RoastChicken, but but but, our old ghost command isn't written for our newer ULib command API.
Sure, it could be converted by us experienced folks, but, the new ones trying to learn ULX and even Lua would be challenged even more.
local function doGhost( ply )
if not ply.ghost then return end
local dTime = FrameTime()
local speed = 500
local upspeed = 200
if ply:KeyDown( IN_FORWARD ) then
ply:SetPos( ply:GetPos() + ply:GetForward() * (speed*dTime) )
elseif ply:KeyDown( IN_BACK ) then
ply:SetPos( ply:GetPos() + ply:GetForward() * (speed*dTime*-1) )
end
if ply:KeyDown( IN_MOVERIGHT ) then
ply:SetPos( ply:GetPos() + ply:GetRight() * (speed*dTime) )
elseif ply:KeyDown( IN_MOVELEFT ) then
ply:SetPos( ply:GetPos() + ply:GetRight() * (speed*dTime*-1) )
end
if ply:KeyDown( IN_JUMP ) then
ply:SetPos( ply:GetPos() + ply:GetUp() * (upspeed*dTime) )
elseif ply:KeyDown( IN_DUCK ) then
ply:SetPos( ply:GetPos() + ply:GetUp() * (upspeed*dTime*-1) )
end
end
function ulx.cc_ghost( ply, command, argv, args )
local targets
if #argv < 1 then
if not ply:IsValid() then
Msg( "You have no physical body to ghost.\n" )
return
end
targets = { ply }
else
local err
targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords
if not targets then
ULib.tsay( ply, err, true )
return
end
end
for _, v in ipairs( targets ) do
if v:InVehicle() then
v:ExitVehicle()
end
if ulx.getExclusive( v, ply ) then
ULib.tsay( ply, ulx.getExclusive( v, ply ), true )
else
v:SetMoveType( MOVETYPE_NONE )
v:SetNotSolid( true )
v:GodEnable()
ULib.invisible( v, true )
v.ghost = true
ulx.setExclusive( v, "ghosted" )
-- This is a self-removing think for ghosts. When there's no more ghosts, it dies.
local function ghostThink()
local remove = true
local players = player.GetAll()
for _, player in ipairs( players ) do
if player.ghost then
doGhost( player )
remove = false
end
end
if remove then
hook.Remove( "Think", "ULXGhostThink" )
end
end
hook.Add( "Think", "ULXGhostThink", ghostThink )
ulx.logUserAct( ply, v, "#A ghosted #T", true )
end
end
end
ulx.concommand( "ghost", ulx.cc_ghost, " - Ghosts you.", ULib.ACCESS_ADMIN, "!ghost", true, ulx.ID_HELP )
function ulx.cc_unghost( ply, command, argv, args )
local targets
if #argv < 1 then
if not ply:IsValid() then
Msg( "You have no physical body to unghost.\n" )
return
end
targets = { ply }
else
local err
targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords
if not targets then
ULib.tsay( ply, err, true )
return
end
end
for _, v in ipairs( targets ) do
if v:InVehicle() then
v:ExitVehicle()
end
v:SetMoveType( MOVETYPE_WALK )
v:SetNotSolid( false )
v:GodDisable()
ULib.invisible( v, false )
v.ghost = nil
ulx.clearExclusive( v )
ulx.logUserAct( ply, v, "#A unghosted #T", true )
end
end
ulx.concommand( "unghost", ulx.cc_unghost, " - Unghosts you.", ULib.ACCESS_ADMIN, "!unghost", true, ulx.ID_HELP )
To those who aren't familiar with current ULib and ULX code API and styles, the above WILL NOT WORK "as is".
I only post it as reference.
Creating new command using ulx.cloak() and ulx.ghost(), as stated previously by someone else in this topic, would be MUCH simpler to do.
(I'm not even sure why Megiddo made this ghost the way he did, but I'm sure at the time it was an awesome reason)