AFK Kicker :)

I got bored thinking of ideas , so i made this. Even if there is a bigger, better , faster one out there, this one is highly customizable and what not. Place it in Lua/Autorun/Server/BRAAWW-call-this-file-what-you-want.lua


/*---------------------

		AFK KICKER BY MEISNO
		( or ningaglio on FP )
		
--------------------------*/


//--------------- SETINGS --------------------
// Time Befor kick

local Timing = { }
Timing["Hours"] = 0
Timing["Minutes"] = 5
Timing["Secondes"] = 0
local Kick_Message = "AFK for " .. Timing["Hours"] .. " Hours , " .. Timing["Minutes"] .. " Minutes and " .. Timing["Secondes"] .. " Secondes"

// -----DO NOT EDIT BELOW THIS LINE ---------


local Hours = Timing["Hours"] * 60 * 60
local Minutes = Timing["Minutes"] * 60
local Secondes = Timing["Secondes"]
local total = Hours + Minutes + Secondes

local function _KICK( ply )
    if ValidEntity(ply) and ply:IsPlayer() then
        ply:Kick( Kick_Message )
    end
end

hook.Add( "PlayerInitialSpawn", "AFKKICKER", function( ply )
	timer.Create( ply:Nick() .. "_AFK",  total , 1 , _KICK , ply )
end)

hook.Add( "KeyPress", "AFKRESET", function( ply )
	timer.Adjust( ply:Nick() .. "_AFK",  total , 1 , _KICK , ply )
end)

concommand.Add("Lobby_remove_AFK", function( ply )
	if ply:IsAdmin() then
		timer.Remove( ply:Nick() .. "_AFK" )
	end
end)


Features highly customizable stickytape and an admin commands

You need to check for mouse movement as well, not just key presses.

You need to check for errors before releasing.

and this.

And you dont need to use tostring on a number to … them in a string

UPDATE :



/*---------------------

		AFK KICKER BY MEISNO
		( or ningaglio on FP )
		
--------------------------*/


//--------------- SETINGS --------------------
// Time Befor kick

local Timing = { }
Timing["Hours"] = 0
Timing["Minutes"] = 5
Timing["Secondes"] = 0
local Kick_Message = "AFK for " .. Timing["Hours"] .. " Hours , " .. Timing["Minutes"] .. " Minutes and " .. Timing["Secondes"] .. " Secondes"

// -----DO NOT EDIT BELOW THIS LINE ---------


local Hours = Timing["Hours"] * 60 * 60
local Minutes = Timing["Minutes"] * 60
local Secondes = Timing["Secondes"]
local total = Hours + Minutes + Secondes

local function _KICK( ply )
    if ValidEntity(ply) and ply:IsPlayer() then
        ply:Kick( Kick_Message )
    end
end

hook.Add( "PlayerInitialSpawn", "AFKKICKER", function( ply )
	timer.Create( ply:Nick() .. "_AFK",  total , 1 , _KICK , ply )
end)

hook.Add( "KeyPress", "AFKRESET", function( ply )
	timer.Adjust( ply:Nick() .. "_AFK",  total , 1 , _KICK , ply )
end)

concommand.Add("Lobby_remove_AFK", function( ply )
	if ply:IsAdmin() then
		timer.Remove( ply:Nick() .. "_AFK" )
	end
end)


Why post it again? Just update the OP.

You can define a table’s members in its definition:

[lua]
local Timing =
{
Hours = 0,
Minutes = 5,
Seconds = 0
};
[/lua]

The _KICK function needs to validate the player. And the timer does not need to repeat.

Err … Nevec , How to explain?

The Player is already validated cause it joins and its validated in the engine, And the time DOES NOT repeat , Why did you think it did?

When a player leaves you will start getting errors as the player object will be null. You need to validate the player in the _KICK function as Nevec said.

[editline]05:07PM[/editline]

[lua]local function _KICK( ply )
if ValidEntity(ply) and ply:IsPlayer() then
ply:Kick( Kick_Message )
end
end[/lua]

Oh :S Sorry for being rude then :S

[editline]06:13PM[/editline]

Couldn’t i fix this by hooking into the PlayerDisconnected Hook?

You should also remove the timer if the player object is invalid.

You could hook PlayerDisconnected as well.

Can i go off thread for a sec? How do you become a Gold Member ( out of intrest :3 ) ?

You need 2000 posts and you have to have been a member for at least 2 years.

You’d be better off using a think hook than timers. Then you only need one for all players.

Its pretty genuine how you utilized the timer library. I probably would have ended up writing my own thing. Nice work.