function ulx.control( calling_ply, target_ply ) if not calling_ply:IsValid() then Msg( "You can't spectate from dedicated server console.\n" ) return end if ulx.getExclusive( calling_ply, calling_ply ) then ULib.tsayError( calling_ply, ulx.getExclusive( calling_ply, calling_ply ), true ) return end ULib.getSpawnInfo( calling_ply ) --[[ local function KeysDown( calling_ply ) if not ulx.GetExclusive( calling_ply, "spectating" ) then return end local cmd = calling_ply:GetCurrentCommand() if cmd:KeyDown( IN_FORWARD ) then --target_ply:SetButtons( IN_FORWARD ) ULib.tsay( nil, calling_ply:Nick() .. " Is pressing IN_FORWARD" ) elseif cmd:KeyDown( IN_BACK ) then --target_ply:SetButtons( IN_BACK ) ULib.tsay( nil, calling_ply:Nick() .. " Is pressing IN_BACK" ) elseif cmd:KeyDown( IN_LEFT ) then --target_ply:SetButtons( IN_LEFT ) ULib.tsay( nil, calling_ply:Nick() .. " Is pressing IN_LEFT" ) elseif cmd:KeyDown( IN_RIGHT ) then --target_ply:SetButtons( IN_RIGHT ) ULib.tsay( nil, calling_ply:Nick() .. " Is pressing IN_RIGHT" ) end end hook.Add( "CreateMove", "KeysDownHook", KeysDown ) --]] local function PlayerControl( calling_ply, target_ply ) if not ulx.GetExclusive( calling_ply, "spectating" ) then return end if( calling_ply:KeyDown( IN_FORWARD ) ) then target_ply:SetButtons( bit.band( target_ply:GetButtons(), bit.bnot( IN_FORWARD ) ) ) end end hook.Add( "CreateMove", "ControlDat", PlayerControl ) local pos = calling_ply:GetPos() local ang = calling_ply:GetAngles() local function unspectate( player, key ) if calling_ply ~= player then return end if key ~= IN_JUMP then return end ULib.spawn( player, true ) if player.ULXHasGod then player:GodEnable() end player:UnSpectate() player:SetPos( pos ) player:SetAngles( ang ) ulx.fancyLogAdmin( calling_ply, true, "#A stopped spectating #T", target_ply ) hook.Remove( "KeyPress", "ulx_unspectate_" .. calling_ply:EntIndex() ) hook.Remove( "PlayerDisconnected", "ulx_unspectatedisconnect_" .. calling_ply:EntIndex() ) ulx.clearExclusive( calling_ply ) end hook.Add( "KeyPress", "ulx_unspectate_" .. calling_ply:EntIndex(), unspectate ) local function disconnect( player ) if player == target_ply or player == calling_ply then unspectate( calling_ply, IN_FORWARD ) end end hook.Add( "PlayerDisconnected", "ulx_unspectatedisconnect_" .. calling_ply:EntIndex(), disconnect ) calling_ply:Spectate( OBS_MODE_IN_EYE ) calling_ply:SpectateEntity( target_ply ) calling_ply:StripWeapons() ULib.tsay( calling_ply, "To get out of spectate, move forward.", true ) ulx.setExclusive( calling_ply, "spectating" ) ulx.fancyLogAdmin( calling_ply, true, "#A is now controlling #T", target_ply ) end local control = ulx.command( "Utility", "ulx control", ulx.control, "!control" ) control:addParam{ type=ULib.cmds.PlayerArg, target="!^" } control:defaultAccess( ULib.ACCESS_ADMIN ) control:help( "Spectate target." )