Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define AFKTime 60 //How many seconds it takes to go AFK
- #define AFKWorld 1 //if you don't understand virtual worlds, don't touch this
- #define AFKColor 0x000000FF
- new AFK[MAX_PLAYERS];
- new Float:AFKPos[MAX_PLAYERS][3];
- new Esc[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- SetTimer("AFKCheck",1000,true);
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- AFK[playerid] = 0;
- Esc[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- BackFromAFK(playerid);
- Esc[playerid] = 0;
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- BackFromAFK(playerid);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- BackFromAFK(playerid);
- return 0;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- Esc[playerid] = 0;
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- Esc[playerid] = 0;
- return 1;
- }
- forward AFKCheck();
- public AFKCheck()
- {
- new Float:Pos[3];
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- Esc[i] += 1;
- GetPlayerPos(i,Pos[0],Pos[1],Pos[2]);
- if(Esc[i] >= 30)
- {
- AFK[i] += 120;
- AFKMode(i);
- }
- if(Pos[0] != AFKPos[i][0] || Pos[1] != AFKPos[i][1] || Pos[2] != AFKPos[i][2])
- {
- BackFromAFK(i);
- }
- else
- {
- AFK[i] += 1;
- AFKMode(i);
- }
- GetPlayerPos(i,AFKPos[i][0],AFKPos[i][1],AFKPos[i][2]);
- }
- return 1;
- }
- stock BackFromAFK(playerid)
- {
- if(AFK[playerid] >= AFKTime)
- {
- SetPlayerColor(playerid,GetPVarInt(playerid,"OldCol"));
- SetPlayerVirtualWorld(playerid,GetPVarInt(playerid,"OldVW"));
- }
- AFK[playerid] = 0;
- return 1;
- }
- stock AFKMode(playerid)
- {
- if(AFK[playerid] >= AFKTime)
- {
- SetPVarInt(playerid,"OldCol",GetPlayerColor(playerid));
- SetPVarInt(playerid,"OldVW",GetPlayerVirtualWorld(playerid));
- SetPlayerColor(playerid,AFKColor);
- SetPlayerVirtualWorld(playerid,AFKWorld);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement