It works good for first time then when i reconnect and go afk it kicks me in few seconds
Код:
forward AFKCheck(playerid);
public AFKCheck(playerid)
{
new pName[24],string[100];
for(new i = 0; i < MAX_PLAYERS; i ++)
if(IsPlayerConnected(i))
{
if(AFKTime[i] > MAX_AFK && AFK[i] == 1)
{
AFK[i] = 0;
AFKTime[i] = 0;
GetPlayerName(i,pName,sizeof pName);
format(string,sizeof(string),"%s has been kicked from server for being AFK for too long.",pName);
SendClientMessageToAll(0xFFCCCC,string);
SetTimerEx("DelayedKick", 1000, false, "i", i);
}
}
return 1;
}
forward AFKTimer(playerid);
public AFKTimer(playerid)
{
AFKTime[playerid]++;
return 1;
}
Код:
forward OnPlayerPause(playerid);
public OnPlayerPause(playerid)
{
new string[154],pName[24];
new Float:x,Float:y,Float:z;
GetPlayerName(playerid,pName,sizeof pName);
GetPlayerPos(playerid,x,y,z);
format(string,sizeof(string),"{9999FF}[AFK] {FF6600}%s is now Away From Keyboard.",pName);
SendClientMessageToAll(COLOR_WHITE,string);
SendClientMessage(playerid,0xFF9900,"You are now on AFK mode.");
AFK[playerid] = 1;
AFKLabel = Create3DTextLabel("AFK",0xFF3333, x, y, z, 20.0, 0, 0);
Attach3DTextLabelToPlayer(AFKLabel,playerid, 0.0, 0.0, 0.7);
format(string,sizeof(string),"AFK [%i] seconds",AFKTime[playerid]);
Update3DTextLabelText(AFKLabel, 0xFF3333, string);
AFKTimerUpdate = SetTimer("AFKTimer",1000,true);
return 1;
}
forward OnPlayerResume(playerid,time);
public OnPlayerResume(playerid,time)
{
new string[100],pName[24];
GetPlayerName(playerid,pName,sizeof pName);
format(string,sizeof(string),"{6633FF}[AFK] {66FF99}%s is now back.",pName);
SendClientMessageToAll(COLOR_WHITE,string);
format(string,sizeof(string),"You were AFK for %i seconds.",time);
SendClientMessage(playerid,0xFF9900,string);
AFK[playerid] = 0;
Delete3DTextLabel(AFKLabel);
KillTimer(AFKTimerUpdate);
AFKTime[playerid] = 0;
return 1;
}
CMD:setmaxafk(playerid,params[])
{
new string[128],pName[24],OldAFK,newlimit;
if(PInfo[playerid][Level] < 4)
return SendClientMessage(playerid,STEALTH_BLUE,"You need to be level 4 to use this command.");
CMDMessageToAdmins(playerid,"SETMAXAFK");
GetPlayerName(playerid,pName,sizeof pName);
OldAFK = MAX_AFK;
if(sscanf(params,"i",newlimit))
return SendClientMessage(playerid,COLOR_RED,"USAGE: /setmaxafk [Time]");
MAX_AFK = newlimit;
format(string,sizeof(string),"Administrator %s has changed max afk time from %i to %i seconds.",pName,OldAFK,newlimit);
SendClientMessageToAll(0x0099CCFF,string);
return 1;
}