Hey guys, i been working on a anti afk script to demote peoples job (no i dont like darkrps antiafk script its retarded)
and basicly it works... but it does it like 90000 times not just once.
heres the code:
[lua]
hook.Add("Tick", "Anti-AFK Tick", function()
local cur_time = CurTime()
for _,ply in pairs(player.GetAll()) do
local angles = ply:EyeAngles()
if ply.LastAngles != angles then
ply.LastAngles = angles
if angles.p != 0 then
SetActivity(ply)
end
end
if afk_mark:GetInt() > 0 then
if ply.LastActivity + afk_mark:GetInt() <= cur_time then
if afk_kick:GetInt() > 0 and ply.LastActivity + afk_mark:GetInt() + afk_kick:GetInt() <= cur_time and (not ply:IsAdmin() or afk_kick_admins:GetBool() or LocalPlayer():Team() == TEAM_CITIZEN ) then
ply:ChatPrint("Because You're AFK your salary will be set to 0 and will only change when you change jobs again!") -- does this command 9000 times
ply:ChangeTeam(TEAM_CITIZEN) -- it does this command like 9000 times
DB.RetrieveSalary(ply, function(amount) ply.OldSalary = amount end) -- 9000
DB.StoreSalary(ply, 0) -- 9000
elseif not tobool(ply.AFK_Time) then
SetAFK(ply, ply.LastActivity)
end
elseif tobool(ply.AFK_Time) then
SetAFK(ply, 0)
end
end
end
end)
end
[/lua]
heres a picture :
ignore the cl_init error (working on a ammo hud :P)
[url]http://dl.dropbox.com/u/22704209/damnyouafk.png[/url]
Yes there is more code.. but i think this is all you need
Your running it in a think hook thats so it checks if the player is afk every frame and calls all your afk stuff if he is, you need to add a check to see if he has already been informed that he is afk.
Mmmm i get it now, mind helping me with this check ? i couldnt think on how to format it out
What don't you understand about it after the player has been found to be afk set a bool value somewhere so you can check if he is already afk then before you set a player to afk check if they already are. If you don't understand how to do that here are some useful links
[url]http://www.lua.org/pil/2.2.html[/url]
[url]http://www.lua.org/pil/4.2.html[/url]
[url]http://www.lua.org/pil/4.3.1.html[/url]
[lua]
hook.Add("Tick", "Anti-AFK Tick", function()
local cur_time = CurTime()
for _,ply in pairs(player.GetAll()) do
local angles = ply:EyeAngles()
if ply.LastAngles != angles then
ply.LastAngles = angles
if angles.p != 0 then
SetActivity(ply)
end
end
end
if afk_mark:GetInt() > 0 then
if ply.LastActivity + afk_mark:GetInt() <= cur_time then
if afk_kick:GetInt() > 0 and ply.LastActivity + afk_mark:GetInt() + afk_kick:GetInt() <= cur_time and (not ply:IsAdmin() or afk_kick_admins:GetBool() or LocalPlayer():Team() == TEAM_CITIZEN ) then
if not hasitchecked then
ply:ChatPrint("Because You're AFK your salary will be set to 0 and will only change when you change jobs again!") -- does this command 9000 times
hasitchecked = true
ply:ChangeTeam(TEAM_CITIZEN) -- it does this command like 9000 times
DB.RetrieveSalary(ply, function(amount) ply.OldSalary = amount end) -- 9000
DB.StoreSalary(ply, 0) -- 9000
elseif not tobool(ply.AFK_Time) then
SetAFK(ply, ply.LastActivity)
end
elseif tobool(ply.AFK_Time) then
SetAFK(ply, 0)
end
end
end
end)
[/lua]
That should work and display only once.
Their was a reason I didn't post the code even thought it would have only taken a few seconds this is because he will learn a lot more doing it by him self also with your code as soon as one person has gone afk no one else will be able to
King, could you a explain a bit more i tried some things but its getting me very frustrated
if !ply.AFK then ply.AFK = true do some afk shit here end
You have failed my test Raymonx1
Ah, Sweet Baby Jesus! thanks Drew works perfect now. (and king for trying to help) all i had to add was
[lua]
if afk_kick:GetInt() > 0 and ply.LastActivity + afk_mark:GetInt() + afk_kick:GetInt() <= cur_time and (not ply:IsAdmin() or afk_kick_admins:GetBool() or LocalPlayer():Team() == TEAM_CITIZEN ) then
if !ply.AFK then ply.AFK = true
ply:ChatPrint("Because You're AFK your salary will be set to 0 and will only change when you change jobs again!")
ply:ChangeTeam(TEAM_CITIZEN, true)
DB.RetrieveSalary(ply, function(amount) ply.OldSalary = amount end)
DB.StoreSalary(ply, 0)
end
[/lua]
I don't believe you wrote the code in the OP since you couldn't do a simple thing like this all you had to do was read the links I posted
Sorry, you need to Log In to post a reply to this thread.