All pastes #565469 Raw Edit

Unnamed

public lua v1 · immutable
·published 2007-06-14 00:30 UTC
rendered paste body
function ulx.cc_ragdoll( ply, command, argv, args )	if #argv < 1 then		ULib.tsay( ply, ulx.LOW_ARGS )		return	end	local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords	if not targets then		ULib.tsay( ply, err )		return	end	for _, v in ipairs( targets ) do		if v.ragdoll then -- They're already ragdolled, what do you want?		elseif v.jail then			ULib.tsay( ply, v:Nick() .. " is in jail!" )		else			ulx.logUserAct( ply, v, "#A ragdolled #T" )						if v:InVehicle() then				local vehicle = v:GetParent()				v:ExitVehicle()			end				local ragdoll = ents.Create( "prop_ragdoll" )			ragdoll:SetPos( v:GetPos() )			ragdoll:SetModel( v:GetModel() )			ragdoll:Spawn()			ragdoll:Activate()				v:Spectate( OBS_MODE_CHASE )			v:SpectateEntity( ragdoll )			v:StripWeapons() -- Otherwise they can still use the weapons.				ragdoll:DisallowDeleting( true )			v:DisallowSpawning( true )			v.ragdoll = ragdoll		end	endendulx.concommand( "ragdoll", ulx.cc_ragdoll, "<user(s)> - ragdolls the specified users", ULib.ACCESS_ADMIN, "!ragdoll", _, ulx.ID_PLAYER_HELP )function ulx.cc_unragdoll( ply, command, argv, args )	if #argv < 1 then		ULib.tsay( ply, ulx.LOW_ARGS )		return	end	local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords	if not targets then		ULib.tsay( ply, err )		return	end	for _, v in ipairs( targets ) do		if v.ragdoll then -- Only if they're ragdolled...			ulx.logUserAct( ply, v, "#A unragdolled #T" )			local pos = v.ragdoll:GetPos()			pos.z = pos.z + 10 -- So they don't end up in the ground			v:DisallowSpawning( false )			v.ragdoll:Remove()			v.ragdoll = nil -- Gotta do this before spawn or our hook catches it			v:Spawn() -- Take them out of observer mode, and give them weapons back.			v:SetPos( pos )		end	endendulx.concommand( "unragdoll", ulx.cc_unragdoll, "<user(s)> - unragdolls the specified users", ULib.ACCESS_ADMIN, "!unragdoll", _, ulx.ID_PLAYER_HELP )local function ragdollSpawnCheck( ply )	if ply.ragdoll then		timer.Simple( 0.01, function() -- Doesn't like us using it instantly			ply:Spectate( OBS_MODE_CHASE )			ply:SpectateEntity( ply.ragdoll )			ply:StripWeapons() -- Otherwise they can still use the weapons.		end )	endendhook.Add( "PlayerSpawn", "ULXRagdollSpawnCheck", ragdollSpawnCheck )local function ragdollDisconnectedCheck( ply )	if ply.ragdoll then		ply.ragdoll:Remove()	endendhook.Add( "PlayerDisconnected", "ULXRagdollDisconnectedCheck", ragdollDisconnectedCheck )