Advertisement
suhrabmujeeb

ToggleAble AFK

Oct 2nd, 2011
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.65 KB | None | 0 0
  1. /*
  2. Toggleable AFK system by suhrab_mujeeb
  3. Special thanks to FireCat for testing and helping
  4. You can remove the credits
  5. */
  6.  
  7.  
  8.  
  9.  
  10.  
  11. // Includes
  12. #include <a_samp>
  13. #include <zcmd>
  14.  
  15. // Defines, Colors.
  16. #define COLOR_BLUE 0x0000FFFF
  17. #define COLOR_RED 0xFF0000FF
  18. #define COLOR_GREEN 0x008040FF
  19. #define Version "1.0b"
  20.  
  21. // Variables, Bools.
  22. new
  23.     bool: IsAvailable,
  24.         IsPlayerAFK[MAX_PLAYERS],
  25.             IsPlayerBRB[MAX_PLAYERS],
  26.                 Text3D: AFKPlayer[MAX_PLAYERS],
  27.                     Text3D: BRBPlayer[MAX_PLAYERS];
  28.  
  29. // Functions
  30. forward SendClientMessageToAllOthers(playerid,color,string[]);
  31. public SendClientMessageToAllOthers(playerid,color,string[])
  32. {
  33.     for(new j=0; j<MAX_PLAYERS; j++)
  34.     {
  35.         if(IsPlayerConnected(j) && j != playerid)
  36.         {
  37.             SendClientMessage(j,color,string);
  38.         }
  39.     }
  40. }
  41.  
  42. // Rest of the code
  43.  
  44. public OnFilterScriptInit()
  45. {
  46.     print(" ");
  47.     print("      _____________________________");
  48.     print("             |                             |");
  49.     print("     |_ Toggleable AFK/BRB System _|");
  50.     print("     |_ Author: suhrab_mujeeb     _|");
  51.     printf("        |_  Release: %s        _|", Version);
  52.     print("     |_____________________________|");
  53.     print(" ");
  54.     print(" ");
  55.     IsAvailable = true;
  56.     return 1;
  57. }
  58.  
  59. public OnPlayerConnect(playerid)
  60. {
  61.     IsPlayerAFK[playerid] = 0;
  62.     IsPlayerBRB[playerid] = 0;
  63.     return 1;
  64. }
  65.  
  66. public OnPlayerDisconnect(playerid, reason)
  67. {
  68.     IsPlayerAFK[playerid] = 0;
  69.     IsPlayerBRB[playerid] = 0;
  70.     return 1;
  71. }
  72.  
  73. public OnPlayerText(playerid, text[])
  74. {
  75.     if(IsPlayerAFK[playerid] == 1)
  76.     {
  77.         return SendClientMessage(playerid, COLOR_RED, "How are you supposed to chat if you are Away from the keyboard?");
  78.     }
  79.     else return 1;
  80. }
  81.  
  82. // Commands
  83.  
  84. CMD:afk(playerid, params[])
  85. {
  86.     if(IsAvailable == true)
  87.     {
  88.         if((IsPlayerAFK[playerid] == 0) && (IsPlayerBRB[playerid] == 0))
  89.         {
  90.             new string[128],
  91.                 pName[MAX_PLAYER_NAME];
  92.             TogglePlayerControllable(playerid, 0);
  93.             GetPlayerName(playerid, pName, sizeof(pName));
  94.             format(string, sizeof(string), "%s[%d] is now away from keyboard (/afk)", pName, playerid);
  95.             SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  96.             SendClientMessage(playerid, COLOR_BLUE, "You're now set as AFK");
  97.             AFKPlayer[playerid] = Create3DTextLabel("Away from keyboard", 0xFFFFFFFF, 0.0, 0.0, 2.0, 40, 0, 0);
  98.             Attach3DTextLabelToPlayer(AFKPlayer[playerid], playerid, 0.0, 0.0, 0.4);
  99.             IsPlayerAFK[playerid] = 1;
  100.         }
  101.         else if((IsPlayerAFK[playerid] == 1) || (IsPlayerBRB[playerid] == 1))
  102.         {
  103.             SendClientMessage(playerid, COLOR_RED, "You are already AFK/BRB");
  104.         }
  105.     }
  106.     else if(IsAvailable == false)
  107.     {
  108.         return SendClientMessage(playerid, COLOR_RED, "The AFK/BRB system is turned off by an Admin");
  109.     }
  110.     return 1;
  111. }
  112.  
  113. CMD:brb(playerid, params[])
  114. {
  115.     if(IsAvailable == true)
  116.     {
  117.         if((IsPlayerAFK[playerid] == 0) && (IsPlayerBRB[playerid] == 0))
  118.         {
  119.             new string[128],
  120.                 pName[MAX_PLAYER_NAME];
  121.             TogglePlayerControllable(playerid, 0);
  122.             GetPlayerName(playerid, pName, sizeof(pName));
  123.             format(string, sizeof(string), "%s[%d] is will be right back (/brb)", pName, playerid);
  124.             SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  125.             SendClientMessage(playerid, COLOR_BLUE, "You're now set as BRB");
  126.             BRBPlayer[playerid] = Create3DTextLabel("Be right back", 0xFFFFFFFF, 0.0, 0.0, 2.0, 40, 0, 0);
  127.             Attach3DTextLabelToPlayer(BRBPlayer[playerid], playerid, 0.0, 0.0, 0.4);
  128.             IsPlayerBRB[playerid] = 1;
  129.         }
  130.         else if((IsPlayerAFK[playerid] == 1) || (IsPlayerBRB[playerid] == 1))
  131.         {
  132.             SendClientMessage(playerid, COLOR_RED, "You are already AFK/BRB");
  133.         }
  134.     }
  135.     else if(IsAvailable == false)
  136.     {
  137.         return SendClientMessage(playerid, COLOR_RED, "The AFK/BRB system is turned off by an Admin");
  138.     }
  139.     return 1;
  140. }
  141.  
  142. CMD:back(playerid, params[])
  143. {
  144.     if(IsPlayerAFK[playerid] == 1)
  145.     {
  146.         new string[128],
  147.                 pName[MAX_PLAYER_NAME];
  148.         IsPlayerAFK[playerid] = 0;
  149.         SendClientMessage(playerid, COLOR_BLUE, "You are now back");
  150.         TogglePlayerControllable(playerid, 1);
  151.         Delete3DTextLabel(AFKPlayer[playerid]);
  152.         GetPlayerName(playerid, pName, sizeof(pName));
  153.         format(string, sizeof(string), "%s[%d] is now back from AFK (/back)", pName, playerid);
  154.         SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  155.     }
  156.     if(IsPlayerBRB[playerid] == 1)
  157.     {
  158.         new string[128],
  159.                 pName[MAX_PLAYER_NAME];
  160.         IsPlayerBRB[playerid] = 0;
  161.         SendClientMessage(playerid, COLOR_BLUE, "You are now back");
  162.         TogglePlayerControllable(playerid, 1);
  163.         GetPlayerName(playerid, pName, sizeof(pName));
  164.         format(string, sizeof(string), "%s[%d] is now back from BRB (/back)", pName, playerid);
  165.         Delete3DTextLabel(BRBPlayer[playerid]);
  166.         SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  167.     }
  168.     else if((IsPlayerAFK[playerid] == 0) && (IsPlayerBRB[playerid] ==0))
  169.     {
  170.         SendClientMessage(playerid, COLOR_RED, "You are neither AFK nor BRB");
  171.     }
  172.     return 1;
  173. }
  174.  
  175. CMD:togglesystem(playerid, params[])
  176. {
  177.     if(IsPlayerAdmin(playerid))
  178.     {
  179.         if(IsAvailable == true)
  180.         {
  181.             IsAvailable = false;
  182.             SendClientMessage(playerid, COLOR_RED, "AFK/BRB set as un-usable");
  183.         }
  184.         else if(IsAvailable == false)
  185.         {
  186.             IsAvailable = true;
  187.             SendClientMessage(playerid, COLOR_GREEN, "AFK/BRB set as usable");
  188.         }
  189.     }
  190.     else
  191.     {
  192.         return 0;
  193.     }
  194.     return 1;
  195. }
  196.  
  197. CMD:afklist(playerid,params[])
  198. {
  199.         new count = 0,
  200.                 string[128],
  201.                     pName[MAX_PLAYER_NAME];
  202.         SendClientMessage(playerid, COLOR_GREEN, " ");
  203.         SendClientMessage(playerid, COLOR_GREEN, "___________ |- AFK Players -| ___________");
  204.         SendClientMessage(playerid, COLOR_GREEN, " ");
  205.         for(new i = 0; i < MAX_PLAYERS; i++)
  206.         {
  207.             if (IsPlayerConnected(i))
  208.             {
  209.                 if(IsPlayerAFK[i] == 1)
  210.                 {
  211.                     GetPlayerName(i, pName,sizeof(pName));
  212.                     format(string, sizeof(string), "Player: {99EE22}%s, {992233}ID: {99DDDD}%d", pName, i);
  213.                     SendClientMessage(playerid, COLOR_BLUE, string);
  214.                     count++;
  215.                 }
  216.             }
  217.         }
  218.         if (count == 0)
  219.         {
  220.             SendClientMessage(playerid, COLOR_RED, "Who are you looking for? No one AFK here");
  221.             SendClientMessage(playerid, COLOR_GREEN, " _______________________________________");
  222.         }
  223.         return 1;
  224. }
  225.  
  226. CMD:brblist(playerid,params[])
  227. {
  228.         new count = 0,
  229.                 string[128],
  230.                     pName[MAX_PLAYER_NAME];
  231.         SendClientMessage(playerid, COLOR_GREEN, " ");
  232.         SendClientMessage(playerid, COLOR_GREEN, "___________ |- BRB Players -| ___________");
  233.         SendClientMessage(playerid, COLOR_GREEN, " ");
  234.         for(new i = 0; i < MAX_PLAYERS; i++)
  235.         {
  236.             if (IsPlayerConnected(i))
  237.             {
  238.                 if(IsPlayerBRB[i] == 1)
  239.                 {
  240.                     GetPlayerName(i, pName,sizeof(pName));
  241.                     format(string, sizeof(string), "Player: {99EE22}%s, {992233}ID: {99DDDD}%d", pName, i);
  242.                     SendClientMessage(playerid, COLOR_BLUE, string);
  243.                     count++;
  244.                 }
  245.             }
  246.         }
  247.         if (count == 0)
  248.         {
  249.             SendClientMessage(playerid, COLOR_RED, "Who are you looking for? No one BRB here");
  250.             SendClientMessage(playerid, COLOR_GREEN, " _______________________________________");
  251.         }
  252.         return 1;
  253. }
  254.  
  255. CMD:afkcmds(playerid, params[])
  256. {
  257.     SendClientMessage(playerid, COLOR_BLUE, "__________ |- Toggleable AFK/BRB commands -| __________");
  258.     SendClientMessage(playerid, COLOR_BLUE, "Basic:    /afk | /brb | /back");
  259.     SendClientMessage(playerid, COLOR_BLUE, "Lists:    /afklist | /brblist");
  260.     if(IsPlayerAdmin(playerid))
  261.     {
  262.         SendClientMessage(playerid, COLOR_RED, "           /togglesystem (rcon cmd)");
  263.     }
  264.     return 1;
  265. }
  266.  
  267. CMD:brbcmds(playerid, params[])
  268. {
  269.     return cmd_afkcmds(playerid, params);
  270. }
  271.  
  272. CMD:brbcmd(playerid, params[])
  273. {
  274.     return cmd_afkcmds(playerid, params);
  275. }
  276.  
  277. CMD:afkcmd(playerid, params[])
  278. {
  279.     return cmd_afkcmds(playerid, params);
  280. }
  281.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement