Jump to content

[Help]player collide


Perfect

Recommended Posts

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
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
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 :P

EDIT: If i put " isElementCollidableWith(theElement, withElement)" then script stoped working

Link to comment

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

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

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...