local CATEGORY_NAME = "Admin Suite"
-- Local function playerSend is taken from ULX source code, ulyssesmod.net, and is licensed under the MIT license. A copy can be found here, https://github.com/TeamUlysses/ulx4/blob/master/LICENSE.
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 + 90 ), -- Right
math.NormalizeAngle( yawForward - 90 ), -- Left
yawForward,
}
local t = {}
t.start = to:GetPos() + Vector( 0, 0, 32 ) -- 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
from.ulx_prevpos = from:GetPos()
from.ulx_prevang = from:EyeAngles()
return to:GetPos() + Angle( 0, directions[ 1 ], 0 ):Forward() * 47
else
return false
end
end
t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47
tr = util.TraceEntity( t, from )
end
from.ulx_prevpos = from:GetPos()
from.ulx_prevang = from:EyeAngles()
return tr.HitPos
end
function ulx.jump( ply )
if not ply:IsAlive() then
ply:ChatPrint( "You're dead!" )
end
if not ply:IsValid() then
Msg( "The land of the console can not be moved.\n" )
end
if ply:IsInVehicle() then
ply:ExitVehicle()
end
-- Create ragdoll (Extracted from the TTT gamemode)
local rag = ents.Create( "prop_ragdoll" )
rag:SetPos( ply:GetPos() )
rag:SetModel( ply:GetModel() )
rag:SetAngles( ply:GetAngles() )
rag:SetColor( ply:GetColor() )
rag:Spawn()
rag:Activate()
rag:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER )
rag:SetKeyValue( "targetname", "cleanser_dissolve" )
for i=0, rag:GetPhysicsObjectCount() - 1 do
local bone = rag:GetPhysicsObjectNum( i )
if IsValid( bone ) then
local bp, ba = ply:GetBonePosition( rag:TranslatePhysBoneToBone(i ) )
if bp and ba then bone:SetPos( bp ) bone:SetAngles( ba ) end
end
end
-- Dissolve ragdoll
local dissolver = ents.Create( "env_entity_dissolver" )
dissolver:Spawn()
dissolver:Activate()
dissolver:SetKeyValue( "target", "cleanser_dissolve" )
dissolver:SetKeyValue( "magnitude", 100 )
dissolver:SetKeyValue( "dissolvetype", 0 )
dissolver:Fire( "Dissolve" )
timer.Simple( 0.1, function() dissolver:Remove() end )
ply:SetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) )
local newpos = playerSend( ply, ply:GetMoveType() == MOVETYPE_NOCLIP )
if not newpos then
ULib.tsayError( ply, "Can't find a place to put you!", true )
return
end
ply:ChatPrint( "You have dissolved and have jumped to your crosshair!" )
end
local jump = ulx.command( CATEGORY_NAME, "ulx jump", ulx.jump, { "!jump", "!launch" } )
jump:defaultAccess( ULib.ACCESS_SUPERADMIN )
jump:help( "Jump to where you are looking, and leave a dissolving body in the background." )