Jump to content

[Help]GhostMode


Perfect

Recommended Posts

Hi, I am Trying to Make a Script, which will enable/disable player collision.

I have made a script but i think its too big and it can be compress.

Can you guys please compress it ?

function ghost (playerSource, commandName, switch) 
local switch = true 
local veh = getPedOccupiedVehicle(playerSource) 
if ( switch == true and isPedInVehicle(playerSource) == false ) then 
setElementCollisionsEnabled(playerSource, true) 
outputChatBox("Server: Ghostmod: on", playerSource, 0, 255, 0 ) 
switch = false 
elseif (switch == false and isPedInVehicle(playerSource) == false) then 
setElementCollisionsEnabled(playerSource, false) 
switch = true 
outputChatBox("Server: Ghostmod: off", playerSource, 0, 255, 0 ) 
elseif ( switch == true  isPedInVehicle(playerSource) == true) then 
setElementCollisionsEnabled(veh, true) 
switch = false 
outputChatBox("Server: Ghostmod: on", playerSource, 0, 255, 0 ) 
elseif (switch == false) then 
setElementCollisionsEnabled(veh, false) 
switch = true 
outputChatBox("Server: Ghostmod: off", playerSource, 0, 255, 0 ) 
end 
end 
addCommandHandler("ghost", ghost) 

(by compress i mean make it small, its have too many elseif)

Link to comment
addCommandHandler("ghost", 
function(player) 
    local veh = getPedOccupiedVehicle(player) 
    local stat = getElementCollisionsEnabled(veh or player) 
    setElementCollisionsEnabled(veh or player, not stat) 
    outputChatBox("Server: Ghostmod: "..(stat and "on" or "off"), player, 0, 255, 0 ) 
end) 

Link to comment

Woah, Its have almost 1/3 lines of my code.

Can you Please Explain me this ? :?

   local stat = getElementCollisionsEnabled(veh or player) 
    setElementCollisionsEnabled(veh or player, not stat) 
    outputChatBox("Server: Ghostmod: "..(stat and "on" or "off"), player, 0, 255, 0 ) 

Curious and a bit confused.

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