Unique23 Posted February 4, 2014 Share Posted February 4, 2014 Hello Everyone, I am trying to make a barrier system for the team. Here is the code, local barrier = {} function createBarrier ( thePlayer ) if ( getTeamName(getPlayerTeam(thePlayer)) == "Unique" ) then local nX, nY, nZ = getElementPosition(thePlayer) local nX2, nY2 = 0, 0 local nZ2 = getPedRotation(thePlayer) local barrier = createObject(3578, nX, nY, nZ - 0.2, 0, 0, nZ2) setElementPosition(thePlayer, nX, nY, nZ + 1) end end addCommandHandler ("b", createBarrier) There is no problem about creating a barrier.It works fine.But the problem I have is, when I do /r , I want object to remove itself. function removeBarrier ( thePlayer ) if isElement(barrier) then destroyElement(barrier) barrier = nil end end addCommandHandler ("r", removeBarrier,thePlayer) addEventHandler("onPlayerQuit", root, removeBarrier) This didn't work. Plus: When I spam /r , script puts a lot of yellow barriers but I want script to remove last barrier when I want to put new one. Link to comment
DNL291 Posted February 4, 2014 Share Posted February 4, 2014 Try this: local barrier = {} function createBarrier ( thePlayer ) if ( getTeamName(getPlayerTeam(thePlayer)) == "Unique" ) then local nX, nY, nZ = getElementPosition(thePlayer) local nX2, nY2, nZ2 = getElementRotation(thePlayer) barrier[thePlayer] = createObject(3578, nX, nY, nZ - 0.2, 0, 0, nZ2) setElementPosition(thePlayer, nX, nY, nZ + 1) end end addCommandHandler ("b", createBarrier) function removeBarrier ( thePlayer ) if isElement(barrier[thePlayer]) then destroyElement(barrier[thePlayer]) barrier[thePlayer] = nil end end addCommandHandler ("r", removeBarrier) addEventHandler("onPlayerQuit", root, function () if isElement(barrier[source]) then destroyElement(barrier[source]) barrier[source] = nil end end) Link to comment
Unique23 Posted February 4, 2014 Author Share Posted February 4, 2014 local barrier = {} function createBarrier ( thePlayer ) if ( getTeamName(getPlayerTeam(thePlayer)) == "Unique" ) then local nX, nY, nZ = getElementPosition(thePlayer) local nX2, nY2 = 0, 0 local nZ2 = getPedRotation(thePlayer) local barrier[thePlayer] = createObject(3578, nX, nY, nZ - 0.2, 0, 0, nZ2) setElementPosition(thePlayer, nX, nY, nZ + 1) end end addCommandHandler ("b", createBarrier) function removeBarrier ( thePlayer ) if isElement(barrier[thePlayer]) then destroyElement(barrier[thePlayer]) barrier[thePlayer] = nil end end addCommandHandler ("r", removeBarrier,thePlayer) addEventHandler("onPlayerQuit", root, function () if isElement(barrier[source]) then destroyElement(barrier[source]) barrier[source] = nil end end) It didn't work and gave an error at line 8: unexpected symbol near [ But I removed [thePlayer] at that line it worked then tried to do /r , didn't work. And as i said i don't want spam like this screnshot: http://i.imgur.com/T7axIsd.jpg Link to comment
DNL291 Posted February 4, 2014 Share Posted February 4, 2014 Copy my code again, I fixed few errors. Link to comment
Unique23 Posted February 4, 2014 Author Share Posted February 4, 2014 Thank you , it worked but I can still spam Link to comment
TAPL Posted February 4, 2014 Share Posted February 4, 2014 local barrier = {} function createBarrier(thePlayer) local team = getPlayerTeam(thePlayer) if (team and getTeamName(team) == "Unique") and not isElement(barrier[thePlayer]) then local nX, nY, nZ = getElementPosition(thePlayer) local nX2, nY2 = 0, 0 local nZ2 = getPedRotation(thePlayer) barrier[thePlayer] = createObject(3578, nX, nY, nZ - 0.2, 0, 0, nZ2) setElementPosition(thePlayer, nX, nY, nZ + 1) end end addCommandHandler("b", createBarrier) function removeBarrier(thePlayer) if isElement(barrier[thePlayer]) then destroyElement(barrier[thePlayer]) barrier[thePlayer] = nil end end addCommandHandler("r", removeBarrier) addEventHandler("onPlayerQuit", root, function() if isElement(barrier[source]) then destroyElement(barrier[source]) barrier[source] = nil end end) Link to comment
Unique23 Posted February 4, 2014 Author Share Posted February 4, 2014 im still able to abuse barriers Link to comment
TAPL Posted February 4, 2014 Share Posted February 4, 2014 I test the code and everything work fine. 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