21.11.2016, 09:17
PHP код:
new IdleAfkTime[MAX_PLAYERS];
new Float:pLastpos[MAX_PLAYERS][2];
new afktimer[MAX_PLAYERS];
new playername[MAX_PLAYER_NAME];
public OnPlayerConnect(playerid)
{
IdleAfkTime[playerid] = 300;//Afk after 5 minutes
afktimer[playerid] = SetTimerEx("IdleAfk", 1000, 1, "i", playerid);
return 1;
}
forward IdleAfk(playerid);
public IdleAfk(playerid)
{
new Float:x, Float:y, Float:z, stringsdata[20];
if (IsPlayerConnected(playerid))
{
GetPlayerPos(playerid, x, y, z);
if ((x == pLastpos[playerid][0] && y == pLastpos[playerid][1]) || ((x != pLastpos[playerid][0] || y != pLastpos[playerid][1]) && GetPlayerState(playerid) != PLAYER_STATE_PASSENGER))
{
IdleAfkTime[playerid] --;
if (IdleAfkTime[playerid] == 0)
{
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
format(stringsdata,sizeof(stringsdata), "* %s is AFK.", playername);
SendClientMessageToAll(COLOR_YELLOW, stringsdata);
TogglePlayerControllable(playerid, 0);
}
}
}
}
CMD:back(playerid, params[])
{
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
format(stringsdata,sizeof(stringsdata), "* %s is Back.", playername);
SendClientMessageToAll(COLOR_YELLOW, stringsdata);
TogglePlayerControllable(playerid, 1);
return ;
}