Simple anti-stuck

I’m looking fo anti-stuck script, maybe someone can help me with it?!stuck-command

Or are you talking about a script that never allows you to get stuck in the first place?

Yea, i need code to prevent player from stucking when he spawns

Have a look at THIS

The problem is what I’m using setpos after I spawn player, so this is not what I want. So I need to check if player can be moved to desired position and if not then select closest position where he can be moved

Well, there’s a code in assmod that’s borrowed from Megiddo, it’s in something like
ass_teleporting, if I remember correctly it does something to check that the player is not somewhere out of the map, and if is, then make them go closest spot in map. Anyway, you should probably go have a look in there.

Thanks, i think this is just what i need

[lua] – Code from ULX so thank Megiddo for this. This is so players don’t get stuck in the world when you teleport them
local function playerSend( from, to, force )
if not to:IsInWorld() and not force then return false end – No way we can do this one

	local yawForward = to:EyeAngles().yaw
	local directions = { -- Directions to try
		math.NormalizeAngle( yawForward - 180 ), -- Behind first
		math.NormalizeAngle( yawForward + 180 ), -- Front
		math.NormalizeAngle( yawForward + 90 ), -- Right
		math.NormalizeAngle( yawForward - 90 ), -- Left

	local t = {}
	t.start = to:GetPos() + Vector( 0, 0, 15 ) -- Move them up a bit so they can travel across the ground
	t.filter = { to, from }

	local i = 1
	t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47 -- (33 is player width, this is sqrt( 33^2 * 2 ))
	local tr = util.TraceEntity( t, from )
    while tr.Hit do -- While it's hitting something, check other angles
    	i = i + 1
    	if i > #directions then  -- No place found
			if force then
				return to:GetPos() + Angle( 0, directions[ 1 ], 0 ):Forward() * 47
				return false

		t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47

		tr = util.TraceEntity( t, from )

	return tr.HitPos