suhrabmujeeb

ToggleAbleAFK v2b

Nov 26th, 2011
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.53 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.                                 Changlog
  7.    =============================================================================
  8.  
  9.     Version 1.0b
  10.     - Added /afk
  11.     - Added /brb
  12.     - Added /back
  13.     - Added /afklist
  14.     - Added /brblist
  15.     - Added /afkhelp
  16.    
  17.    
  18.     Version 2.0b
  19.     - Added TextDraw
  20.     - AFK/BRB Count
  21.     - Fixed some bugs
  22. */
  23.  
  24.  
  25. // Includes
  26. #include <a_samp>
  27. #include <zcmd>
  28.  
  29. // Defines, Colors.
  30. #define COLOR_BLUE 0x0000FFFF
  31. #define COLOR_RED 0xFF0000FF
  32. #define COLOR_GREEN 0x008040FF
  33. #define Version "2.0b"
  34.  
  35. // Variables, Bools.
  36. new
  37.     bool: IsAvailable;
  38. new
  39.   IsPlayerAFK[MAX_PLAYERS],
  40.   IsPlayerBRB[MAX_PLAYERS],
  41.   AFKPlayers,
  42.   BRBPlayers,
  43.   Text:AFKTD,
  44.   Text:BRBTD,
  45.   Text3D: AFKPlayer[MAX_PLAYERS],
  46.   Text3D: BRBPlayer[MAX_PLAYERS];
  47.  
  48. // Functions
  49. forward SendClientMessageToAllOthers(playerid,color,string[]);
  50. public SendClientMessageToAllOthers(playerid,color,string[])
  51. {
  52.     for(new j=0; j<MAX_PLAYERS; j++)
  53.     {
  54.         if(IsPlayerConnected(j) && j != playerid)
  55.         {
  56.             SendClientMessage(j,color,string);
  57.         }
  58.     }
  59. }
  60.  
  61. // Rest of the code
  62.  
  63. public OnFilterScriptInit()
  64. {
  65.     print(" ");
  66.     print("      _____________________________");
  67.     print("             |                             |");
  68.     print("     |_ Toggleable AFK/BRB System _|");
  69.     print("     |_ Author: suhrab_mujeeb     _|");
  70.     printf("        |_  Release: %s        _|", Version);
  71.     print("     |_____________________________|");
  72.     print(" ");
  73.     print(" ");
  74.     IsAvailable = true;
  75.     AFKPlayers = 0;
  76.     BRBPlayers = 0;
  77.    
  78.     AFKTD = TextDrawCreate(211.000000, 194.000000, "AFK");
  79.     TextDrawBackgroundColor(AFKTD, 255);
  80.     TextDrawFont(AFKTD, 2);
  81.     TextDrawLetterSize(AFKTD, 2.599999, 9.000000);
  82.     TextDrawColor(AFKTD, -16776961);
  83.     TextDrawSetOutline(AFKTD, 1);
  84.     TextDrawSetProportional(AFKTD, 0);
  85.    
  86.     BRBTD = TextDrawCreate(211.000000, 194.000000, "BRB");
  87.     TextDrawBackgroundColor(BRBTD, 255);
  88.     TextDrawFont(BRBTD, 2);
  89.     TextDrawLetterSize(BRBTD, 2.599999, 9.000000);
  90.     TextDrawColor(BRBTD, -16776961);
  91.     TextDrawSetOutline(BRBTD, 1);
  92.     TextDrawSetProportional(BRBTD, 0);
  93.     return 1;
  94. }
  95.  
  96. public OnFilterScriptExit()
  97. {
  98.     TextDrawHideForAll(AFKTD);
  99.     TextDrawDestroy(AFKTD);
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerConnect(playerid)
  104. {
  105.     IsPlayerAFK[playerid] = 0;
  106.     IsPlayerBRB[playerid] = 0;
  107.     TextDrawHideForPlayer(playerid, AFKTD);
  108.     TextDrawHideForPlayer(playerid, BRBTD);
  109.     return 1;
  110. }
  111.  
  112. public OnPlayerDisconnect(playerid, reason)
  113. {
  114.     IsPlayerAFK[playerid] = 0;
  115.     IsPlayerBRB[playerid] = 0;
  116.     if(IsPlayerAFK[playerid] == 1)
  117.     {
  118.         AFKPlayers--;
  119.     }
  120.     if(IsPlayerBRB[playerid] == 1)
  121.     {
  122.         BRBPlayers--;
  123.     }
  124.     return 1;
  125. }
  126.  
  127. public OnPlayerText(playerid, text[])
  128. {
  129.     if(IsPlayerAFK[playerid] == 1)
  130.     {
  131.         SendClientMessage(playerid, COLOR_RED, "How are you supposed to chat if you are Away from the keyboard?");
  132.         return 0;
  133.     }
  134.     return 1;
  135. }
  136.  
  137. // Commands
  138.  
  139. CMD:afk(playerid, params[])
  140. {
  141.     if(IsAvailable == true)
  142.     {
  143.         if((IsPlayerAFK[playerid] == 0) && (IsPlayerBRB[playerid] == 0))
  144.         {
  145.             new string[128],
  146.                 pName[MAX_PLAYER_NAME];
  147.             TogglePlayerControllable(playerid, 0);
  148.             TextDrawShowForPlayer(playerid, AFKTD);
  149.             GetPlayerName(playerid, pName, sizeof(pName));
  150.             format(string, sizeof(string), "%s[%d] is now away from keyboard (/afk)", pName, playerid);
  151.             SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  152.             SendClientMessage(playerid, COLOR_BLUE, "You're now set as AFK");
  153.             AFKPlayer[playerid] = Create3DTextLabel("Away from keyboard", 0xFFFFFFFF, 0.0, 0.0, 2.0, 40, 0, 0);
  154.             Attach3DTextLabelToPlayer(AFKPlayer[playerid], playerid, 0.0, 0.0, 0.4);
  155.             IsPlayerAFK[playerid] = 1;
  156.             AFKPlayers++;
  157.         }
  158.         else if((IsPlayerAFK[playerid] == 1) || (IsPlayerBRB[playerid] == 1))
  159.         {
  160.             SendClientMessage(playerid, COLOR_RED, "You are already AFK/BRB");
  161.         }
  162.     }
  163.     else if(IsAvailable == false)
  164.     {
  165.         return SendClientMessage(playerid, COLOR_RED, "The AFK/BRB system is turned off by an Admin");
  166.     }
  167.     return 1;
  168. }
  169.  
  170. CMD:brb(playerid, params[])
  171. {
  172.     if(IsAvailable == true)
  173.     {
  174.         if((IsPlayerAFK[playerid] == 0) && (IsPlayerBRB[playerid] == 0))
  175.         {
  176.             new string[128],
  177.                 pName[MAX_PLAYER_NAME];
  178.             TogglePlayerControllable(playerid, 0);
  179.             TextDrawShowForPlayer(playerid, BRBTD);
  180.             GetPlayerName(playerid, pName, sizeof(pName));
  181.             format(string, sizeof(string), "%s[%d] will be right back (/brb)", pName, playerid);
  182.             SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  183.             SendClientMessage(playerid, COLOR_BLUE, "You're now set as BRB");
  184.             BRBPlayer[playerid] = Create3DTextLabel("Be right back", 0xFFFFFFFF, 0.0, 0.0, 2.0, 40, 0, 0);
  185.             Attach3DTextLabelToPlayer(BRBPlayer[playerid], playerid, 0.0, 0.0, 0.4);
  186.             IsPlayerBRB[playerid] = 1;
  187.             BRBPlayers++;
  188.         }
  189.         else if((IsPlayerAFK[playerid] == 1) || (IsPlayerBRB[playerid] == 1))
  190.         {
  191.             SendClientMessage(playerid, COLOR_RED, "You are already AFK/BRB");
  192.         }
  193.     }
  194.     else if(IsAvailable == false)
  195.     {
  196.         return SendClientMessage(playerid, COLOR_RED, "The AFK/BRB system is turned off by an Admin");
  197.     }
  198.     return 1;
  199. }
  200.  
  201. CMD:back(playerid, params[])
  202. {
  203.     if((IsPlayerAFK[playerid] == 1) && (IsPlayerBRB[playerid] ==0))
  204.     {
  205.         new string[128],
  206.             pName[MAX_PLAYER_NAME];
  207.         IsPlayerAFK[playerid] = 0;
  208.         TextDrawHideForPlayer(playerid, AFKTD);
  209.         SendClientMessage(playerid, COLOR_BLUE, "You are now back");
  210.         TogglePlayerControllable(playerid, 1);
  211.         Delete3DTextLabel(AFKPlayer[playerid]);
  212.         GetPlayerName(playerid, pName, sizeof(pName));
  213.         format(string, sizeof(string), "%s[%d] is now back from AFK (/back)", pName, playerid);
  214.         SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  215.         AFKPlayers--;
  216.     }
  217.     else if((IsPlayerBRB[playerid] == 1) && (IsPlayerAFK[playerid] == 0))
  218.     {
  219.         new string[128],
  220.             pName[MAX_PLAYER_NAME];
  221.         IsPlayerBRB[playerid] = 0;
  222.         TextDrawHideForPlayer(playerid, BRBTD);
  223.         SendClientMessage(playerid, COLOR_BLUE, "You are now back");
  224.         TogglePlayerControllable(playerid, 1);
  225.         GetPlayerName(playerid, pName, sizeof(pName));
  226.         format(string, sizeof(string), "%s[%d] is now back from BRB (/back)", pName, playerid);
  227.         Delete3DTextLabel(BRBPlayer[playerid]);
  228.         SendClientMessageToAllOthers(playerid, COLOR_BLUE, string);
  229.         BRBPlayers--;
  230.     }
  231.     else
  232.     {
  233.         SendClientMessage(playerid, COLOR_RED, "You are neither AFK nor BRB");
  234.     }
  235.     return 1;
  236. }
  237.  
  238. CMD:togglesystem(playerid, params[])
  239. {
  240.     if(IsPlayerAdmin(playerid))
  241.     {
  242.         if(IsAvailable == true)
  243.         {
  244.             IsAvailable = false;
  245.             SendClientMessage(playerid, COLOR_RED, "AFK/BRB set as un-usable");
  246.         }
  247.         else if(IsAvailable == false)
  248.         {
  249.             IsAvailable = true;
  250.             SendClientMessage(playerid, COLOR_GREEN, "AFK/BRB set as usable");
  251.         }
  252.     }
  253.     else
  254.     {
  255.         return 0;
  256.     }
  257.     return 1;
  258. }
  259.  
  260. CMD:afklist(playerid,params[])
  261. {
  262.         new count = 0,
  263.             string[128],
  264.             str[128],
  265.             pName[MAX_PLAYER_NAME];
  266.         SendClientMessage(playerid, COLOR_GREEN, " ");
  267.         SendClientMessage(playerid, COLOR_GREEN, "___________ |- AFK Players -| ___________");
  268.         SendClientMessage(playerid, COLOR_GREEN, " ");
  269.         for(new i = 0; i < MAX_PLAYERS; i++)
  270.         {
  271.             if (IsPlayerConnected(i))
  272.             {
  273.                 if(IsPlayerAFK[i] == 1)
  274.                 {
  275.                     GetPlayerName(i, pName,sizeof(pName));
  276.                     format(string, sizeof(string), "Player: {99EE22}%s, {992233}ID: {99DDDD}%d", pName, i);
  277.                     SendClientMessage(playerid, COLOR_BLUE, string);
  278.                     count++;
  279.                 }
  280.             }
  281.         }
  282.         if (count == 0)
  283.         {
  284.             SendClientMessage(playerid, COLOR_RED, "Who are you looking for? No one AFK here");
  285.             SendClientMessage(playerid, COLOR_GREEN, " _______________________________________");
  286.         }
  287.         format(str, sizeof(str), "Total AFK players %d", AFKPlayers);
  288.         SendClientMessage(playerid, COLOR_BLUE, str);
  289.         return 1;
  290. }
  291.  
  292. CMD:brblist(playerid,params[])
  293. {
  294.         new BRBCount = 0,
  295.             string[128],
  296.             str[128],
  297.             pName[MAX_PLAYER_NAME];
  298.         SendClientMessage(playerid, COLOR_GREEN, " ");
  299.         SendClientMessage(playerid, COLOR_GREEN, "___________ |- BRB Players -| ___________");
  300.         SendClientMessage(playerid, COLOR_GREEN, " ");
  301.         for(new i = 0; i < MAX_PLAYERS; i++)
  302.         {
  303.             if (IsPlayerConnected(i))
  304.             {
  305.                 if(IsPlayerBRB[i] == 1)
  306.                 {
  307.                     GetPlayerName(i, pName,sizeof(pName));
  308.                     format(string, sizeof(string), "Player: {99EE22}%s, {992233}ID: {99DDDD}%d", pName, i);
  309.                     SendClientMessage(playerid, COLOR_BLUE, string);
  310.                     BRBCount++;
  311.                 }
  312.             }
  313.         }
  314.         if (BRBCount == 0)
  315.         {
  316.             SendClientMessage(playerid, COLOR_RED, "Who are you looking for? No one BRB here");
  317.             SendClientMessage(playerid, COLOR_GREEN, " _______________________________________");
  318.         }
  319.         format(str, sizeof(str), "Total BRB players %d", BRBPlayers);
  320.         SendClientMessage(playerid, COLOR_BLUE, str);
  321.         return 1;
  322. }
  323.  
  324. CMD:afkcmds(playerid, params[])
  325. {
  326.     SendClientMessage(playerid, COLOR_BLUE, "__________ |- Toggleable AFK/BRB commands -| __________");
  327.     SendClientMessage(playerid, COLOR_BLUE, "Basic:    /afk | /brb | /back");
  328.     SendClientMessage(playerid, COLOR_BLUE, "Lists:    /afklist | /brblist");
  329.     if(IsPlayerAdmin(playerid))
  330.     {
  331.         SendClientMessage(playerid, COLOR_RED, "           /togglesystem (rcon cmd)");
  332.     }
  333.     return 1;
  334. }
  335.  
  336. CMD:brbcmds(playerid, params[])
  337. {
  338.     return cmd_afkcmds(playerid, params);
  339. }
  340.  
  341. CMD:brbcmd(playerid, params[])
  342. {
  343.     return cmd_afkcmds(playerid, params);
  344. }
  345.  
  346. CMD:afkcmd(playerid, params[])
  347. {
  348.     return cmd_afkcmds(playerid, params);
  349. }
  350.  
  351. CMD:afkhelp(playerid, params[])
  352. {
  353.     return cmd_afkcmds(playerid, params);
  354. }
  355.  
  356.  
Advertisement
Add Comment
Please, Sign In to add comment