Perfect Posted August 24, 2012 Author Share Posted August 24, 2012 You can't use 'else' without an 'if'. like this ? function ghost() local localplayer = getLocalPlayer(source) for index,player in ipairs(getElementsByType("player")) do if setElementCollidableWith(player, localplayer, false) then outputChatBox("Server: Ghostmod: on", source, 0, 255, 0 ) else setElementCollidableWith(player, localplayer, true) outputChatBox("Server: Ghostmode: off", source, 0, 255, 0 ) end end end addCommandHandler("Ghost", ghost) but i got another error WARNING:playerghost/ghost.lua:13: attempt to call global 'addCommandHandler' (a nil value) EDIT: Sorry, its working but how can i make it for vehicles too. i mean i can go thourgh vehicles too Link to comment
albers14 Posted August 24, 2012 Share Posted August 24, 2012 You can't use 'else' without an 'if'. like this ? function ghost() local localplayer = getLocalPlayer(source) for index,player in ipairs(getElementsByType("player")) do if setElementCollidableWith(player, localplayer, false) then outputChatBox("Server: Ghostmod: on", source, 0, 255, 0 ) else setElementCollidableWith(player, localplayer, true) outputChatBox("Server: Ghostmode: off", source, 0, 255, 0 ) end end end addCommandHandler("Ghost", ghost) but i got another error WARNING:playerghost/ghost.lua:13: attempt to call global 'addCommandHandler' (a nil value) EDIT: Sorry, its working but how can i make it for vehicles too. i mean i can go thourgh vehicles too 1. Narh not really, use isElementCollidableWith instead. So if isElementCollidableWith(theElement, withElement) then you code.. 2. Seems like you fixed the one by yourself 3. Right now you can only go through players as you say then use. for index, vehicle in ipairs(getElementsByType("vehicle")) do You should understand it now Link to comment
Perfect Posted August 24, 2012 Author Share Posted August 24, 2012 You can't use 'else' without an 'if'. like this ? function ghost() local localplayer = getLocalPlayer(source) for index,player in ipairs(getElementsByType("player")) do if setElementCollidableWith(player, localplayer, false) then outputChatBox("Server: Ghostmod: on", source, 0, 255, 0 ) else setElementCollidableWith(player, localplayer, true) outputChatBox("Server: Ghostmode: off", source, 0, 255, 0 ) end end end addCommandHandler("Ghost", ghost) but i got another error WARNING:playerghost/ghost.lua:13: attempt to call global 'addCommandHandler' (a nil value) EDIT: Sorry, its working but how can i make it for vehicles too. i mean i can go thourgh vehicles too 1. Narh not really, use isElementCollidableWith instead. So if isElementCollidableWith(theElement, withElement) then you code.. 2. Seems like you fixed the one by yourself 3. Right now you can only go through players as you say then use. for index, vehicle in ipairs(getElementsByType("vehicle")) do You should understand it now I know i just need to put there vehicle but where can i add that in my script EDIT: If i put " isElementCollidableWith(theElement, withElement)" then script stoped working Link to comment
GTX Posted August 24, 2012 Share Posted August 24, 2012 Try this. function ghost() for index,vehicle in ipairs(getElementsByType("vehicle")) do if isElementCollidableWith(vehicle, getPedOccupiedVehicle(localplayer)) == false then outputChatBox("Server: Ghostmod: on", source, 0, 255, 0 ) setElementCollidableWith(vehicle, getPedOccupiedVehicle(localplayer), true) else setElementCollidableWith(vehicle, getPedOccupiedVehicle(localplayer), false) outputChatBox("Server: Ghostmode: off", source, 0, 255, 0 ) end end end addCommandHandler("Ghost", ghost) Link to comment
Alexs Posted August 24, 2012 Share Posted August 24, 2012 Use: setElementCollisionsEnabled function ghost (playerSource, commandName, switch) if ( switch == "on" ) then setElementCollisionsEnabled(playerSource, false) outputChatBox("Server: Ghostmod: on", playerSource, 0, 255, 0 ) elseif ( switch == off) then setElementCollisionsEnabled(playerSource, false) outputChatBox("Server: Ghostmod: on", playerSource, 0, 255, 0 ) end end addCommandHandler("ghost", ghost) and if you want to turn off the collisions for all, try this: function ghost (playerSource, commandName, switch) local players = getElementsByType("player") for i, plays in pairs (players) do if ( switch == "on" ) then setElementCollisionsEnabled(plays, false) outputChatBox("Server: Ghostmod: on", plays, 0, 255, 0 ) elseif ( switch == "off" ) then setElementCollisionsEnabled(plays, true) outputChatBox("Server: Ghostmod: off", plays, 0, 255, 0 ) end end end addCommandHandler("ghost", ghost) Link to comment
Perfect Posted August 24, 2012 Author Share Posted August 24, 2012 I want for both vehicles and players. if i type /ghostmode then vehicles and players go through from me. how can i do that with single command ? 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