Jump to content

Need help, Coding problem..


WiBox

Recommended Posts

Posted
local Z1 = createColRectangle(1577, 1723, 60, 140 ) -- LV hospital

function spawnRoadblock(id, x, y, z, rx, ry, rz, dim, int)
        if (not id) then return end
        if (id == 1225 and dim == 0) then
            outputChatBox("Explosive barrels can not be placed in main dimension", client, 255, 0, 0)
            return
        end
        if (id == 978) then
            z = z-1
        end
        local accName = getAccountName(getPlayerAccount(client))
        local object = createObject(tonumber(id), x, y, z, rx, ry, rz)
        setElementDoubleSided(object, true)
        setElementFrozen(object, true)
        setElementData(object, "creator", accName, false)
        roadblocks[object] = {object, getAccountName(getPlayerAccount(client))}
        if (tonumber(dim) ~= 0) then
            setElementDimension(object, dim)
        end
        if (tonumber(int) ~= 0) then
            setElementInterior(object, int)
        end
        if (id ~= 1225) then
            triggerClientEvent(client, "nobreak", client, object)
        end
        if not isElementWithinColShape (object, Z1) then
            destroyElement(object)
        end
end
addEvent("Zone.ZRB.AddRoadblock", true)
addEventHandler("Zone.ZRB.AddRoadblock", root, spawnRoadblock)

Hello, in this script as you see it's about adding a Road Block.. but i got one problem and it's i need to make that if the Object was outside a specific area so it will get auto removed, any help? I appreciate who fix this coding... Thanks.

 

Posted (edited)

Sorry but if you can explain more because i didn't understand or if you can send the code which i need to use, it would be great, thank you.

Edited by SSKE
Posted

As far as i can remember MTA was tricky in collision detection, especially on a new object creation stage. And if that is still here, you may fix the issue by refreshing a colshape manually:

local epsilon = 0.0001
local state = false
local function refreshColShape(colshape)
  	local x, y, z = getElementPosition(colshape)
	if state then
    	setElementPosition(colshape, x - epsilon, y, z)
    else
    	setElementPosition(colshape, x + epsilon, y, z)
    end
  	state = not state
end

Just invoke this after each object creation.

Posted

i'll try it but the only problem that it's a panel, as write the ID and press PLACE, but when i use this code function spawnRoadblock, the problem is that when i place the object in colshape or outside the colshape, it not placing it's like the object isn't detecting the ColShape, because i made a small test and it was true, but i'll try to make a way so it auto refresh every time a object will be added, i appreciate your help thanks.

But if there is another way to refresh the colshape automaticly when a object will be placed, because i'm new at scripting so still trying my luck.. i still got problems with addEventHandler

but anyway thanks.

Posted (edited)

ColShapes work fine with peds and vehicles, but stuck with objects because they are static. And as I know there is no a proper solution. My solution is kind of magic but should works fine. If you want to have a robust solution you may write your own implementation of collision shapes in the Lua.

Edited by TEDERIs
Posted (edited)
2 hours ago, SSKE said:

Well thanks, i'll check if i can do as you said.

I made a pull request with a function which can help you. If it will be accepted, there will be possibility to simply call isInsideColShape to check a point location.

Edited by TEDERIs

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...