08.07.2015, 00:27
AFK SYSTEM
Version 1.0
KingServerIran
Why you use SetPVarInt & GetPVarInt ?Version 1.0
KingServerIran
bcoz the SetPVarInt & GetPVarInt is very helpful.
now this is a FS so you can use this function in GM too without puting all this FS Codes In GM
EXP: Put this in /kill cmd or other cmd that players cant do while their AFK
[NOTE: you can put anywhere you want: GM and FS]
Код:
if(GetPVarInt(playerid,"AFK") == 1) return SendClientMessage(playerid, -1,"ERROR: You cant use this cmd while your afk");
Compile the pwn file before you use it
The Script
Код:
#include <a_samp>
#define Use3DText true //put 'false' if you dont want 3DText
#define AFKUseChat false //put 'true' if you want AFK Player can use Chat
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" AFK System LOADED By KingServerIran");
print("--------------------------------------\n");
return 1;
}
PlayerName(playerid) {
new Name[24];
GetPlayerName(playerid, Name, 24);
return Name;
}
public OnFilterScriptExit()
{
for(new i=0;i<MAX_PLAYERS;i++) if(IsPlayerConnected(i))
{
SetPVarInt(i,"AFK",0);
TogglePlayerControllable(i,1);
GameTextForPlayer(i,"~b~AFK~g~ Back",2000,1);
}
return 1;
}
public OnPlayerText(playerid, text[])
{
#if AFKUseChat == false
if(GetPVarInt(playerid, "AFK") == 1) return
SendClientMessage(playerid, 0xFF0000AA,"AFK: You need to be back from afk to chat (/afkback)");
#endif
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[128];
if (strcmp("/afk", cmdtext, true, 10) == 0)
{
if(GetPVarInt(playerid,"AFK") != 0)
{
format(string,128,"AFK: %s is now AFK",PlayerName(playerid));
SendClientMessageToAll(0xC0C0C0AA,string);
SendClientMessage(playerid, 0xFF0000,"AFK: Type /afkback to be back!");
TogglePlayerControllable(playerid,0);
SetPVarInt(playerid,"AFK",1);
GameTextForPlayer(playerid,"AFK MODE: ON",2000,1);
}else {
SendClientMessage(playerid, 0xFF0000AA,"ERROR: Your AFK is already ON");
}
return 1;
}
if (strcmp("/afkback", cmdtext, true, 10) == 0)
{
if(GetPVarInt(playerid,"AFK") != 1)
{
format(string,128,"AFK: %s is now Back From AFK",PlayerName(playerid));
SendClientMessageToAll(0xC0C0C0AA,string);
TogglePlayerControllable(playerid,1);
SetPVarInt(playerid,"AFK",0);
GameTextForPlayer(playerid,"AFK MODE: OFF",2000,1);
}else {
SendClientMessage(playerid,0xFF0000AA,"ERROR: Your AFK is already OFF");
}
return 1;
}
if (strcmp("/afks", cmdtext, true, 10) == 0)
{
new Count =0;
for(new i=0;i<MAX_PLAYERS;i++) if(IsPlayerConnected(i) && GetPVarInt(i,"AFK") == 1) Count++;
if(Count <= 0) return SendClientMessage(playerid, 0xFFFFFFAA,"AFK: No AFK Players");
format(string,128,"AFK: There are %d AFK Players",Count);
SendClientMessage(playerid, 0xFFFFFAA,string);
for(new i=0;i<MAX_PLAYERS;i++) if(IsPlayerConnected(i) && GetPVarInt(i,"AFK") == 1) {
format(string,128,"AFK: %s(%d) Stats: AFK",PlayerName(i),i);
SendClientMessage(playerid, 0xFFFFFFAA,string);
}
return 1;
}
return 0;
}
public OnPlayerUpdate(playerid)
{
#if Use3DText == true
if(GetPVarInt(playerid,"AFK") == 1) {
SetPlayerChatBubble(playerid,">>> AFK <<<",0xFFFFFFAA,20.0,1000); // 3D Text
}
#endif
return 1;
}


