Jump to content

[Question] Player Collisions


kieran

Recommended Posts

Hey, so another broken script I made...  Wow, a lot gone wrong today :/  anyway....  Tried making a sort of script for players spawning so if say 10 players spawn at once they won't all be stuck in each other, here's the simple stuff I tried. 

function Ghost()
	setTimer(setElementCollisionsEnabled, 20000, 1, source, false)
	setTimer(setElementCollisionsEnabled, 1000, 1, source, true)
end
addEventHandler("onPlayerSpawn", getRootElement(), Ghost)

Basically it freezes him -_- is the problem maybe I have it server and not client side?

90o8i0.jpg

Link to comment

:/ it freezes him then lets him run.....  I am trying to set a peds collisions, is that maybe the problem...?

function Ghost()
	setElementCollisionsEnabled(source, false)
	setTimer(setElementCollisionsEnabled, 20000, 1, source, true)
end
addEventHandler("onClientPlayerSpawn", getRootElement(), Ghost)

Changed your false and trues, basically he is frozen 20 secs, then he moves.

 

Edit

Okay, so this works for vehicles, but how can I get players? just a simple getElementPosition?

addEventHandler("onClientVehicleEnter", getRootElement(),
function ()
	local v = getPedOccupiedVehicle(localPlayer) -- Get her's Vehicle ID
	for index,vehicle in ipairs(getElementsByType("vehicle")) do --LOOP through all Vehicles
		setElementCollidableWith(vehicle, v, false) -- Set the Collison off with the Other vehicles.
	end
end
)

 

Edited by kieran
Link to comment

Try this:

addEvent("enableSpawnProtection", true)
addEventHandler("enableSpawnProtection", root, 
function (bool)
	for _,v in pairs( getElementsByType("player") ) do
		setElementCollidableWith(v, source, not bool)
	end
	setTimer(
		function()
			for _,v in pairs( getElementsByType("player") ) do
				setElementCollidableWith(v, localPlayer, bool)
			end
		end, 10000, 1
	)
end)

 

addEventHandler( "onPlayerSpawn", root,
	function ()
		triggerClientEvent(source, "enableSpawnProtection", source, true)
	end
)

 

  • Like 1
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...