Files
wnsrc/gamemodes/helix/plugins/willardantiafk/sv_plugin.lua
lifestorm 73479cff9e Upload
2024-08-04 22:55:00 +03:00

85 lines
2.5 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
local PLUGIN = PLUGIN
local INTERVAL = 30
util.AddNetworkString("ixPrintAfkPlayers")
ix.log.AddType("afkStart", function(client)
return Format("%s est maintenant AFK.", client:Name())
end)
ix.log.AddType("afkEnd", function(client, ...)
local arg = {...}
return Format("%s n'est plus AFK. Temps total passé AFK : %s", client:Name(), arg[1])
end)
do
local PLAYER = FindMetaTable("Player")
function PLAYER:CheckAFKTick(interval)
local aimVector = self:GetAimVector()
local posVector = self:GetPos()
if (self.ixLastAimVector == aimVector
and self.ixLastPosition == posVector
and !self.autowalk)
then
return self:AddAFKTime(interval or INTERVAL)
else
self.ixLastAimVector = aimVector
self.ixLastPosition = posVector
if (self:GetNetVar("afkTime", 0) > 0) then
return self:ResetAFKTimer()
end
end
end
function PLAYER:AddAFKTime(time)
local oldValue, oldTime = self:IsAFK(), self:GetNetVar("afkTime", 0)
self:SetNetVar("afkTime", oldTime + time)
if (self:IsAFK() and !oldValue) then
ix.log.Add(self, "afkStart")
return 5
elseif (oldTime + time >= ix.config.Get("afkTime") - 60 and oldTime < ix.config.Get("afkTime") - 60) then
self:Notify("Vous serez considéré comme AFK dans 60 secondes si vous ne bougez pas.")
return 1
end
end
function PLAYER:ResetAFKTimer()
if (self:IsAFK()) then
ix.log.Add(self, "afkEnd", self:GetNetVar("afkTime", 0))
elseif (self:GetNetVar("afkTime", 0) > (ix.config.Get("afkTime") - 60)) then
self:Notify("Timer d'AFK réinitialiser.")
end
self:SetNetVar("afkTime", 0)
return INTERVAL
end
end
function PLUGIN:KickAFK(target, byAdmin)
if (target and target:IsAFK()) then
target:Kick("Vous avez été expulsé pour être AFK")
if (byAdmin) then
ix.util.NotifyLocalized("kickedAdminAFK", nil, byAdmin:Name(), target:Name())
else
ix.util.NotifyLocalized("kickedAFK", nil, target:Name())
end
elseif (byAdmin) then
byAdmin:NotifyLocalized("targetNotAFK", target:Name())
end
end