Jump to content

[Help]player collide


Perfect

Recommended Posts

Posted
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

Multi Theft Auto Player since middle of 2011.

Everybody want to act Crazy/Smart/Intelligent/Different/Unique/Innocent and Thats why I am Perfect.

Posted
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 :)

Posted
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

Multi Theft Auto Player since middle of 2011.

Everybody want to act Crazy/Smart/Intelligent/Different/Unique/Innocent and Thats why I am Perfect.

Posted

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) 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

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) 

Developer @ MYVAL

Posted

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 ?

Multi Theft Auto Player since middle of 2011.

Everybody want to act Crazy/Smart/Intelligent/Different/Unique/Innocent and Thats why I am Perfect.

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