WiBox Posted May 12, 2018 Share Posted May 12, 2018 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. Link to comment
WiBox Posted May 13, 2018 Author Share Posted May 13, 2018 is it hard for get fixed? it work but without: if not isElementWithinColShape (object, Z1) then destroyElement(object) end but i need to add them so if someone building inside his zone but he put one outside his specific zone so it get auto destroyed ... Please guys any help? and thanks.. Link to comment
keymetaphore Posted May 13, 2018 Share Posted May 13, 2018 are you visually seeing the colshape in /showcol? if you are, add a debug line at line 28 that outputs something so you can see if it's executed Link to comment
WiBox Posted May 15, 2018 Author Share Posted May 15, 2018 (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 May 15, 2018 by SSKE Link to comment
TEDERIs Posted May 16, 2018 Share Posted May 16, 2018 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. Link to comment
WiBox Posted May 16, 2018 Author Share Posted May 16, 2018 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. Link to comment
TEDERIs Posted May 16, 2018 Share Posted May 16, 2018 (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 May 16, 2018 by TEDERIs Link to comment
WiBox Posted May 16, 2018 Author Share Posted May 16, 2018 Well thanks, i'll check if i can do as you said. Link to comment
TEDERIs Posted May 16, 2018 Share Posted May 16, 2018 (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 May 16, 2018 by TEDERIs Link to comment
WiBox Posted May 22, 2018 Author Share Posted May 22, 2018 Thanks! i appreciate that~ Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now