problem on kick afk after 30min
#1

hi this script on my game mode dosent kick players after 30min afk
see this picthre:
this player is AFK and not sleeping
Code:
Код:
public TwoMinutesTimer()
{
	if(kickafk == 1)
	{
		new name[30],string[128];
		foreach(new i : Player)
		{
			if(IsPlayerConnected(i))
			{
				if(IsBot[i] == 0)
				{
					if(PlayerInfo[i][pSleeping] == 0)
					{
						if(IsPlayerAFK[i] >= 1680)
						{
							SS(i, COLOR_LIGHTRED, "If you don't move you will be kicked in 2 minutes.", "If you don't move you will be kicked in 2 minutes.");
						}
						if(IsPlayerAFK[i] >= 1800)
						{
							SS(i, COLOR_WHITE, "Shoma az server kick shodid zira bish az 30daghighe dar server afk bodid.", "You were kicked for being AFK (away from keyboard) for more than 30 minutes.");
							SS(i, COLOR_WHITE, "baraye inke AFK nashid bayad bekhabid berid dar khaneh va /sleep bezanid.", "To leave your character AFK for longer than 30 minutes, use /sleep in a house.");
							SendClientMessage(i, COLOR_GENANNOUNCE, "You have been kicked for being AFK.");
							GetPlayerName(i, name, sizeof(name));
							format(string, sizeof(string),"%s was kicked by AdmBot for being AFK for more than 30 minutes.",name);
							SendClientMessageToAll(COLOR_LIGHTRED, string);
							new var100[300];
							mysql_format(SQL, var100, sizeof(var100), "INSERT INTO kicklogs (`playerid`,`giverid`,`playername`,`givername`,`reason`) VALUES ('%d','3','%s','AdmBot','AFK for more than 30 minutes')", PlayerInfo[i][pSQLID],PlayerInfo[i][pNormalName]);
							mysql_tquery(SQL,var100,"","");
							KickEx(i);
						}
					}
				}
			}
		}
	}
Reply
#2

Show code where you set the player has afk and start the counting before the twominutestimer is called
Reply
#3

Delete twominutestimer and do my guide and it will work 100% for you:

Define this right under your includes:
Код:
#define IsPlayerAFKFor30Mins(%1) GetTickCount() > (lastupdate[%1]+60*1000*30) // 30 = 30 Minutes
new lastupdate[MAX_PLAYERS];
Add this at OnPlayerUpdate:
Код:
lastupdate[playerid] = GetTickCount();
Now use your new function 'IsPlayerAFKFor30Mins' or whatever you will call it in a global timer
example:

Код:
SetTimer("CheckAFKPlayers",5000,1);
forward CheckAFKPlayers();
public CheckAFKPlayers() foreach(Player,i) if(IsPlayerAFKFor30Mins(i)) Kick(i);
Explaination: if a player pressed ESC Button and 30 minutes has passed, that player will get kicked right away.

I hope it helped you or even learned you something new
Reply
#4

Then add it to your gamemode, like that:

Код:
public OnPlayerUpdate(playerid)
{
	lastupdate[playerid] = GetTickCount();
	return 1;
}
Reply
#5

Inside OnGameModeInIt()
Код:
SetTimer("CheckAFKPlayers",5000,1);
Outside the functions
Код:
forward CheckAFKPlayers();
public CheckAFKPlayers() foreach(Player,i) if(IsPlayerAFKFor30Mins(i)) Kick(i);
Reply
#6

Put that with your other public functions. If you dont know where to put, put it right before OnGameModeInit
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)