Biesmen

Countdown Include 1.0

May 10th, 2011
1,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. //============================================================//
  2. //* CountDownForPlayer & CountDownForAll
  3. //* Version: 1.0
  4. //============================================================//
  5. //* Created by:
  6. //* Biesmen
  7. //============================================================//
  8. //* Foreach Include by:
  9. //* Y_Less
  10. //============================================================//
  11.  
  12. #include <a_samp>
  13. #include <Foreach>
  14.  
  15. #undef MAX_PLAYERS
  16. #define MAX_PLAYERS 500 // Change 500 to your server's slots.
  17.  
  18. enum CountStuff
  19. {
  20. cdc[2],
  21. cdem[30],
  22. cds,
  23. CDUsed,
  24. };
  25. new CD[MAX_PLAYERS][CountStuff];
  26.  
  27. new CDTimer[MAX_PLAYERS];
  28. new CDTimerA;
  29.  
  30.  
  31. forward CountD();
  32. forward CountDP(playerid);
  33.  
  34. stock AvailableColors(TColor[])
  35. {
  36. if(strcmp(TColor,"r", true) == 0) return 1;
  37. if(strcmp(TColor,"g", true) == 0) return 1;
  38. if(strcmp(TColor,"b", true) == 0) return 1;
  39. if(strcmp(TColor,"w", true) == 0) return 1;
  40. if(strcmp(TColor,"y", true) == 0) return 1;
  41. if(strcmp(TColor,"p", true) == 0) return 1;
  42. if(strcmp(TColor,"l", true) == 0) return 1;
  43. if(strcmp(TColor,"h", true) == 0) return 1;
  44. else return 0;
  45. }
  46.  
  47. stock CountDownForAll(Color[2], EndMessage[30], Seconds)
  48. {
  49. foreach(Player, i)
  50. {
  51. if(CD[i][CDUsed] == 1) return print("CountDown ERROR: There's a player still having the Countdown messages!");
  52. if(strlen(Color) > 1 || !AvailableColors(Color)) return print("CountDown ERROR: Invalid color used!");
  53. if(strlen(EndMessage) > 30) return print("CountDown ERROR: End Message is too long!");
  54. if(Seconds < 0 ) return print("CountDown ERROR: Negative amount of seconds.");
  55. CD[i][cdc] = Color;
  56. CD[i][cdem] = EndMessage;
  57. CD[i][cds] = Seconds;
  58. CDTimerA = SetTimer("CountD", 1000, true);
  59. CD[i][CDUsed] = 1;
  60. }
  61. return 1;
  62. }
  63.  
  64. stock CountDownForPlayer(playerid, Color[2], EndMessage[30], Seconds)
  65. {
  66. if(CD[playerid][CDUsed] == 1) return print("CountDown ERROR: The function is already being used for this player!");
  67. if(strlen(Color) > 1 || !AvailableColors(Color)) return print("CountDown ERROR: Invalid color used!");
  68. if(strlen(EndMessage) > 30) return print("CountDown ERROR: End Message is too long!");
  69. if(Seconds < 0 ) return print("CountDown ERROR: Negative amount of seconds.");
  70. CD[playerid][cdc]= Color;
  71. CD[playerid][cdem] = EndMessage;
  72. CD[playerid][cds] = Seconds;
  73. CDTimer[playerid] = SetTimerEx("CountDP", 1000, true, "i", playerid);
  74. CD[playerid][CDUsed] = 1;
  75. return 1;
  76. }
  77.  
  78. public CountD()
  79. {
  80. foreach(Player, i)
  81. {
  82. new string[35];
  83. if(CD[i][cds] != 0)
  84. {
  85. format(string, sizeof(string), "~%s~%d", CD[i][cdc], CD[i][cds]);
  86. GameTextForPlayer(i,string, 1000, 4);
  87. CD[i][cds]--;
  88. }
  89. else
  90. {
  91. format(string, sizeof(string), "~%s~%s", CD[i][cdc], CD[i][cdem]);
  92. GameTextForPlayer(i, string, 2000, 4);
  93. KillTimer(CDTimerA);
  94. CD[i][CDUsed] = 0;
  95. }
  96. }
  97. return 1;
  98. }
  99.  
  100. public CountDP(playerid)
  101. {
  102. new string[35];
  103. if(CD[playerid][cds] != 0)
  104. {
  105. format(string, sizeof(string), "~%s~%d", CD[playerid][cdc], CD[playerid][cds]);
  106. GameTextForPlayer(playerid,string, 1000, 4);
  107. CD[playerid][cds]--;
  108. }
  109. else
  110. {
  111. format(string, sizeof(string), "~%s~%s", CD[playerid][cdc], CD[playerid][cdem]);
  112. GameTextForPlayer(playerid, string, 2000, 4);
  113. KillTimer(CDTimer[playerid]);
  114. CD[playerid][CDUsed] = 0;
  115. }
  116. return 1;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment