16.01.2013, 10:25
Is it possible to auto kick paused players without using onplayerupdate? As onplayerupdate gets executed way too much times in a second.
public OnPlayerSpawn(playerid)
{
SetTimerEx("AFKCheck", 300000, false, "i", playerid);
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
KillTimer(AFKCheck(playerid));
SetTimerEx("AFKCheck", 300000, false, "i", playerid);
return 1;
}
public OnPlayerText(playerid, text[])
{
KillTimer(AFKCheck(playerid));
SetTimerEx("AFKCheck", 300000, false, "i", playerid);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
KillTimer(AFKCheck(playerid));
SetTimerEx("AFKCheck", 300000, false, "i", playerid);
return 1;
}
forward AFKCheck(playerid);
public AFKCheck(playerid)
{
new string[80];
format(string, sizeof(string), "Player %s has been kicked | Reason: Away From Keyboard", playername);
SendClientMessageToAll(0xFF0000FF, string);
Kick(playerid);
return 1;
}
pawn Code:
|
Well you wanted something that wasn't called 3052 or whatever times a second, so there... be happy with it.
|
new PlayerPaused[MAX_PLAYERS], pausetick[MAX_PLAYERS];
pausetick[playerid] = GetTickCount();
SetTimer("PauseCheck", 1000, 1);
forward PauseCheck();
public PauseCheck()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(playerid)) continue;
if(GetTickCount() - pausetick[i] > 1000) // If they haven't updated in 1+ seconds, increase if needed.
{
PlayerPaused[i] = 1;
}
else
{
PlayerPaused[i] = 0;
}
}
return 1;
}