Jump to content

[NEW] [HELP] How to disable player's collision?


hrtht

Recommended Posts

  • Moderators

https://wiki.multitheftauto.com/wiki/SetElementCollisionsEnabled

Note: Vehicles that are collisionless and have a driver will cause bugs.
 
Note: Enabling a players collisions when they're inside a vehicle will cause bugs.
 
Note: Disabling a peds collisions will cause some problems, such as it being unable to move or wrong rotation after creation.

 

But I think setElementCollidableWith what you want.
Check the example on wiki.

Edited by Patrick
Link to comment
function ghostmode_on()
	local playerVehicle = getPedOccupiedVehicle(localPlayer) -- Get the players vehicle
	if(playerVehicle) then -- Check the return value.
		for i,v in pairs(getElementsByType("vehicle")) do --LOOP through all vehicles
			setElementCollidableWith(v, playerVehicle, false) -- Set the collison off with the other vehicles.
		end
		outputChatBox("You are now a Ghost")
	end
end
addCommandHandler("ghostmode", ghostmode_on) -- Add the /ghostmode Command.

 

What I need to change to get it working with players? I'm new help me man

Link to comment
  • Moderators
3 minutes ago, hrtht said:

What I need to change to get it working with players? I'm new help me man
function ghostmode_on()
	for i,v in pairs(getElementsByType("player")) do --LOOP through all players
		setElementCollidableWith(v, localPlayer, false) -- Set the collison off with the other vehicles.
	end
	outputChatBox("You are now a Ghost")
end
addCommandHandler("ghostmode", ghostmode_on) -- Add the /ghostmode Command.

Replace vehicle elements with players.

Link to comment
3 hours ago, Patrick said:

function ghostmode_on()
	for i,v in pairs(getElementsByType("player")) do --LOOP through all players
		setElementCollidableWith(v, localPlayer, false) -- Set the collison off with the other vehicles.
	end
	outputChatBox("You are now a Ghost")
end
addCommandHandler("ghostmode", ghostmode_on) -- Add the /ghostmode Command.

Replace vehicle elements with players.

How to add a output for saying that you're no longer Ghost?

Link to comment
  • Moderators
8 minutes ago, hrtht said:

How to add a output for saying that you're no longer Ghost?

I'm happy to help but you also have to learn.
Some Lua tutorial for you:
https://forum.multitheftauto.com/topic/121619-Lua-for-absolute-beginners
https://forum.multitheftauto.com/topic/64228-the-ultimate-Lua-tutorial/
https://forum.multitheftauto.com/topic/95654-tut-debugging/
https://forum.multitheftauto.com/topic/114541-tut-events/

 

local status = false

function ghostmode_toggle()
    status = not status -- toggle status
  
    if status then
        for i,v in pairs(getElementsByType("player")) do --LOOP through all players
            setElementCollidableWith(v, localPlayer, false) -- Set the collison off with the other players.
        end
        outputChatBox("You are now a Ghost")
    
    else
        for i,v in pairs(getElementsByType("player")) do --LOOP through all players
            setElementCollidableWith(v, localPlayer, true) -- Set the collison on with the other players.
        end
        outputChatBox("You aren't a Ghost")
    end
end
addCommandHandler("ghostmode", ghostmode_toggle) -- Add the /ghostmode Command.

 

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