Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ ### AFK Detection v2 ###]]--
- --[[ ### for Phasor v2 by H® Shaft ###]]--
- -- Original by Nugget: Re-write of Nuggets AFK 1.01, credits to him.
- -- Corrected some logical errors, and updated the bit offsets and action key descriptions.
- -- Added kick_afk_admin and hide admin features
- -- Players kicked by this script are logged in Phasor's game log: "H® Shaft was kicked for being AFK."
- -- Edited to be persistent, and to play nice with other scripts and to work efficiently as originally intended.
- -- V2: Added check to determine if player is in a moving/non-moving vehicle
- -- edit --
- afk_time = 30 --| Time in seconds before a player is considered to be AFK (amount of time before warning time clock starts).
- afk_warn_time = 180 --| Time in seconds before a player is warned that they will be kicked for being AFK (use nil to disable).
- afk_kick_time = 200 --| Time in seconds before a player should be kicked for being AFK (use nil to disable).
- kick_afk_admin = false --| If true, any admin who is afk can be kicked. If false, admin will be hidden instead of kicked.
- -- don't edit --
- afk = {}
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(processId, game, persistent)
- for i=0,15 do
- if getplayer(i) then
- afk[i] = {}
- afk[i].orientation = {}
- afk[i].response = true
- afk[i].time = 0
- afk[i].boolean = false
- afk[i].hidden = false
- afk[i].timerid = registertimer(1000, "AFKTimer", i)
- end
- end
- checkactions = registertimer(500, "CheckActions")
- end
- function OnServerChat(player, type, message)
- local response = nil
- if player and type < 4 then
- afk[player].time = -1
- afk[player].boolean = false
- response = true
- end
- return response
- end
- function OnPlayerJoin(player)
- if getplayer(player) then
- afk[player] = {}
- afk[player].orientation = {}
- afk[player].response = true
- afk[player].time = 0
- afk[player].boolean = false
- afk[player].hidden = false
- afk[player].timerid = registertimer(1000, "AFKTimer", player)
- end
- end
- function OnPlayerLeave(player)
- if getplayer(player) then
- if afk[player].timerid then
- removetimer(afk[player].timerid)
- afk[player].timerid = nil
- end
- afk[player] = nil
- end
- end
- function OnWeaponReload(player, weapId)
- if getplayer(player) then
- afk[player].time = -1
- afk[player].boolean = false
- end
- return nil
- end
- function OnObjectCreationAttempt(mapId, parentId, player)
- if player then
- local tagname, tagtype = gettaginfo(mapId)
- if tagtype == "proj" then
- if afk[player] then
- afk[player].time = -1
- afk[player].boolean = false
- end
- end
- end
- return nil
- end
- function OnVehicleEntry(player, vehiId, seat, mapId, voluntary)
- if getplayer(player) then
- afk[player].time = -1
- afk[player].boolean = false
- end
- return nil
- end
- function OnVehicleEject(player, voluntary)
- if getplayer(player) then
- afk[player].time = -1
- afk[player].boolean = false
- end
- return nil
- end
- function CheckActions(id, count)
- for i = 0,15 do
- if getplayer(i) then
- local m_objectId = getplayerobjectid(i)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- local melee_key = readbit(m_object + 0x208, 7)
- local action_key = readbit(m_object + 0x208, 6)
- local flashlight_key = readbit(m_object + 0x208, 4)
- local jump_key = readbit(m_object + 0x208, 1)
- local crouch_key = readbit(m_object + 0x208, 0)
- local left_mouse = readbit(m_object + 0x209, 3)
- local right_mouse = readbit(m_object + 0x209, 4)
- local shooting = readbyte(m_object + 0x2A5)
- if melee_key or action_key or flashlight_key or jump_key or crouch_key or left_mouse or right_mouse or (shooting == 1) then
- if afk[i].hidden == true then
- afk[i].hidden = false
- end
- afk[i].time = -1
- afk[i].boolean = false
- end
- end
- end
- end
- end
- return true
- end
- function isafk(player)
- if player then
- if afk[player] then
- return afk[player].boolean
- end
- end
- end
- if afk_warn_time then
- afk_warn_message = "**WARNING** You will be kicked in " .. afk_kick_time - afk_warn_time .. " seconds for being AFK!"
- end
- if afk_kick_time then
- afk_kick_message = " is being kicked for inactivity (AFK)."
- end
- function AFKTimer(id, count, player)
- if getplayer(player) and afk[player] then
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- local x_aim = readfloat(m_object + 0x230)
- local y_aim = readfloat(m_object + 0x234)
- local z_aim = readfloat(m_object + 0x238)
- local walking = readbyte(m_object + 0x4D2)
- local bool = true
- if x_aim == (afk[player].orientation.x or x_aim) and y_aim == (afk[player].orientation.y or y_aim) and z_aim == (afk[player].orientation.z or z_aim) then
- bool = false
- elseif (walking == 0 and isinvehicle(player)) then
- bool = false
- end
- afk[player].orientation.x = x_aim
- afk[player].orientation.y = y_aim
- afk[player].orientation.z = z_aim
- afk[player].response = bool
- if isinvehicle(player) then
- local m_vehicle = getobject(getplayervehicleid(player))
- if m_vehicle then
- if readfloat(m_vehicle + 0x68) == 0 and readfloat(m_vehicle + 0x6c) == 0 then
- bool = false
- elseif readfloat(m_vehicle + 0x68) > 0 or readfloat(m_vehicle + 0x6c) > 0 then
- bool = true
- afk[player].time = afk[player].time - 1
- if afk[player].hidden == true then
- afk[player].hidden = false
- end
- end
- end
- end
- if afk[player].response == false then
- afk[player].time = afk[player].time + 1
- else
- afk[player].time = 0
- end
- if afk[player].hidden == true then
- applycamo(player, 2)
- end
- if afk[player].time == 0 then
- afk[player].boolean = false
- afk[player].hidden = false
- elseif afk[player].time == afk_time then
- afk[player].boolean = true
- elseif afk[player].time == afk_warn_time then
- privatesay(player, afk_warn_message, false)
- elseif afk[player].time == afk_kick_time then
- if kick_afk_admin and isadmin(player) then
- afk[player].timerid = registertimer(2000, "kickplayer", player)
- elseif not kick_afk_admin and isadmin(player) then
- afk[player].hidden = true
- privatesay(player, "**ADMIN** You are being hidden while you are AFK.", false)
- hideadmin(player)
- elseif not kick_afk_admin and not isadmin(player) then
- say(getname(player) .. afk_kick_message, false)
- afk[player].timerid = registertimer(2000, "kickplayer", player)
- end
- end
- else
- afk[player].orientation.x = nil
- afk[player].orientation.y = nil
- afk[player].orientation.z = nil
- end
- end
- end
- return true
- end
- function getplayervehicleid(player)
- return readdword(getobject(getplayerobjectid(player)) + 0x11C)
- end
- function kickplayer(id, count, player)
- if count == 1 then
- if getplayer(player) then
- if kick_afk_admin and isadmin(player) then
- log_msg(1, getname(player) .. " was kicked for being AFK.")
- svcmd("sv_kick " .. resolveplayer(player))
- elseif not kick_afk_admin and isadmin(player) then
- privatesay(player, "**ADMIN** You are being hidden while you are AFK.", false)
- hideadmin(player)
- elseif not kick_afk_admin and not isadmin(player) then
- log_msg(1, getname(player) .. " was kicked for being AFK.")
- svcmd("sv_kick " .. resolveplayer(player))
- end
- end
- end
- return false
- end
- function hideadmin(player)
- for i = 0,15 do
- local m_player = getplayer(i)
- if m_player then
- local m_objectId = getplayerobjectid(i)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- writefloat(m_player + 0x100, readfloat(m_player + 0x100) - 1000)
- afk[i].hidden = true
- end
- end
- end
- end
- end
- function OnDamageLookup(receiving, causing, tagid)
- local response = nil
- local tagname, tagtype = gettaginfo(tagid)
- if receiving then
- local r_player = objectidtoplayer(receiving)
- if r_player and (afk[r_player].hidden == true) then
- response = false
- end
- end
- return response
- end
- function OnGameEnd(stage)
- if stage == 1 then
- if checkactions then
- removetimer(checkactions)
- checkactions = nil
- end
- for i=0,15 do
- if getplayer(i) then
- if afk[i].timerid then
- removetimer(afk[i].timerid)
- afk[i].timerid = nil
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement