Advertisement
Guest User

Vote Slap&Cash System By Randomdude.

a guest
Apr 20th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. /*============================================================================
  2. | |
  3. | RandomDude's VoteSlap System! |
  4. | |
  5. ==============================================================================*/
  6. #define FILTERSCRIPT
  7. #include <a_samp>
  8.  
  9. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  10. #define GREY 0xAFAFAFAA
  11. #define GREEN 0x33AA33AA
  12. #define YELLOW 0xFFFF00AA
  13. #define WHITE 0xFFFFFFAA
  14. #define LIGHTBLUE 0x33CCFFAA
  15. #define ORANGE 0xFF9900AA
  16. new Votes = 0;
  17. new Voted[MAX_PLAYERS];
  18. new VoteActive;
  19. new thingy;
  20. new VPlayers;
  21. new SlapName[24];
  22. new PlayerName[24];
  23. forward CountDownTimer(playerid);
  24. new Count;
  25. new Timer;
  26. new Text:TCountDown;
  27. new Text:Voteslap;
  28. new Text:Votecash;
  29. #if defined FILTERSCRIPT
  30.  
  31. public OnFilterScriptInit()
  32. {
  33. print("\n--------------------------------------");
  34. print("FilterScript Made By RandomDude.");
  35. print("--------------------------------------\n");
  36. return 1;
  37. }
  38.  
  39. public OnFilterScriptExit()
  40. {
  41. return 1;
  42. }
  43. #endif
  44.  
  45. public OnPlayerConnect(playerid)
  46. {
  47. Voted[playerid] = 0;
  48. return 1;
  49. }
  50. public CountDownTimer(playerid)
  51. {
  52. new string[3];
  53. Count--;
  54. TextDrawDestroy(TCountDown);
  55. format(string,sizeof(string),"%d",Count);
  56. TCountDown = TextDrawCreate(300.0,300.0,string);
  57.  
  58. TextDrawTextSize(TCountDown,0.7,3.0);
  59. TextDrawShowForAll(TCountDown);
  60.  
  61. if(Count == 0)
  62. {
  63. KillTimer(Timer);
  64. KillTimer(thingy);
  65. TextDrawDestroy(TCountDown);
  66. TextDrawDestroy(Voteslap);
  67. Voted[playerid] = 0;
  68. }
  69. return 1;
  70. }
  71.  
  72. public OnPlayerCommandText(playerid, cmdtext[])
  73. {
  74. dcmd(voteslap,8,cmdtext);
  75. dcmd(votes,4,cmdtext);
  76. dcmd(stopvote,8,cmdtext);
  77. dcmd(votecash,8,cmdtext);
  78. dcmd(votec,5,cmdtext);
  79. return 0;
  80. }
  81. dcmd_stopvote(playerid,params[])
  82. {
  83. #pragma unused params
  84. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,LIGHTBLUE,"You are not an admin!");
  85. TextDrawDestroy(TCountDown);
  86. TextDrawDestroy(Voteslap);
  87. TextDrawDestroy(Votecash);
  88. KillTimer(Timer);
  89. KillTimer(thingy);
  90. SendClientMessageToAll(0xFF0000FF,"An admin has stopped the vote process.");
  91. return 1;
  92. }
  93. dcmd_voteslap(playerid,params[])
  94. {
  95. new id,n[24],on[24],str2[128],string[3];
  96. new tmp[256], tmp2[256], Index,str[128];
  97. VPlayers = GetPlayersOnServer()/2+1;
  98. if(GetPlayersOnServer() <= 2)
  99. return SendClientMessage(playerid,GREY,"The minimum players required for this command to work are 3.");
  100. tmp = strtok(params,Index), tmp2 = strtok(params,Index),id = strval(tmp);
  101. if(IsPlayerAdmin(id)) return SendClientMessage(playerid,0xFF0000FF,"You cannot try to voteslap an admin! -_-");
  102. if(VoteActive == 1) return SendClientMessage(playerid,0xFF0000FF,"There is already a Vote for something in proccess, please wait until it has finished.");
  103. GetPlayerName(playerid,n,24),GetPlayerName(id,on,24);
  104. Voted[playerid] = 1;
  105. SlapName = on;
  106. PlayerName = n;
  107. if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /voteslap [ID] [Reason]");
  108. if(!IsPlayerConnected(id))return SendClientMessage(playerid,GREY,"You have entered an incorrect ID.");
  109. Votes = 1;
  110. VoteActive = 1;
  111. format(str2,sizeof(str2),"~r~Voteslap on ~w~%s. ~r~%d/%d",PlayerName,Votes,VPlayers);
  112. Voteslap = TextDrawCreate(50.0,300.0,str2);
  113. TextDrawLetterSize(Voteslap,0.5,2.5);
  114. TextDrawShowForAll(Voteslap);
  115. thingy = SetTimer("VoteFail",21000,false);
  116. Timer = SetTimerEx("CountDownTimer",1000,true,"i",playerid);
  117. format(str,sizeof(str),"%s has started a voteslap on %s. Reason: %s. To vote - /votes",n,on,params[2]);
  118. SendClientMessageToAll(0xFF0000FF,str);
  119. format(string,sizeof(string),"%d",Count);
  120. TCountDown = TextDrawCreate(300.0,300.0,string);
  121. Count = 21;
  122. return 1;
  123. }
  124. dcmd_votes(playerid,params[])
  125. {
  126. #pragma unused params
  127. new str[128],name[24],str2[128];
  128. GetPlayerName(playerid,name,24);
  129. if(VoteActive == 0) return SendClientMessage(playerid,GREY,"There is no active vote slap on right now.");
  130. if(Voted[playerid] == 1) return SendClientMessage(playerid,LIGHTBLUE,"You have already voted!");
  131. KillTimer(thingy);
  132. thingy = SetTimer("VoteFail",21000,false);
  133. Votes++;
  134. Voted[playerid] = 1;
  135. format(str,sizeof(str),"%s has voted. %d/%d",name,Votes,VPlayers);
  136. SendClientMessageToAll(0xFF0000FF,str);
  137. TextDrawDestroy(Voteslap);
  138. format(str2,sizeof(str),"~r~Voteslap on ~w~%s. ~r~%d/%d",Votes,VPlayers);
  139. TextDrawCreate(50.0,300,str2);
  140. TextDrawLetterSize(Voteslap,0.5,2.5);
  141. TextDrawShowForAll(Voteslap);
  142. KillTimer(Timer);
  143. Timer = SetTimer("CountDownTimer",1000,true);
  144. Count = 21;
  145. if(Votes == VPlayers)
  146. {
  147. format(str,sizeof(str),"%s has been slapped. %d/%d votes.",Votes,Votes);
  148. SendClientMessageToAll(0xFF0000FF,str);
  149. TextDrawDestroy(Voteslap);
  150. KillTimer(thingy);
  151. VoteActive = 0;
  152. new Float:PPos[3];
  153. GetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]);
  154. SetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]+4);
  155. return 1;
  156. }
  157. return 1;
  158. }
  159. //NEW VOTE SYSTEM to take away money from player
  160. dcmd_votecash(playerid,params[])
  161. {
  162. new id,n[24],on[24],str2[128],string[3];
  163. new tmp[256], tmp2[256], Index,str[128];
  164. VPlayers = GetPlayersOnServer()/2+1;
  165. if(GetPlayersOnServer() <= 2)
  166. return SendClientMessage(playerid,GREY,"The minimum players required for this command to work are 3.");
  167. tmp = strtok(params,Index), tmp2 = strtok(params,Index),id = strval(tmp);
  168. if(IsPlayerAdmin(id)) return SendClientMessage(playerid,0xFF0000FF,"You cannot try to Votecash an admin! -_-");
  169. if(VoteActive == 1) return SendClientMessage(playerid,0xFF0000FF,"There is already a Vote for something in proccess, please wait until it has finished.");
  170. GetPlayerName(playerid,n,24),GetPlayerName(id,on,24);
  171. Voted[playerid] = 1;
  172. SlapName = on;
  173. PlayerName = n;
  174. if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /Votecash [ID] [Reason]");
  175. if(!IsPlayerConnected(id))return SendClientMessage(playerid,GREY,"You have entered an incorrect ID.");
  176. Votes = 1;
  177. VoteActive = 1;
  178. format(str2,sizeof(str2),"~r~Votecash on ~w~%s. ~r~%d/%d",PlayerName,Votes,VPlayers);
  179. Votecash = TextDrawCreate(50.0,300.0,str2);
  180. TextDrawLetterSize(Votecash,0.5,2.5);
  181. TextDrawShowForAll(Votecash);
  182. thingy = SetTimer("VoteFail",21000,false);
  183. Timer = SetTimerEx("CountDownTimer",1000,true,"i",playerid);
  184. format(str,sizeof(str),"%s has started a Votecash on %s. Reason: %s. To vote - /votec",n,on,params[2]);
  185. SendClientMessageToAll(0xFF0000FF,str);
  186. format(string,sizeof(string),"%d",Count);
  187. TCountDown = TextDrawCreate(300.0,300.0,string);
  188. Count = 21;
  189. return 1;
  190. }
  191. dcmd_votec(playerid,params[])
  192. {
  193. #pragma unused params
  194. new str[128],name[24],str2[128];
  195. GetPlayerName(playerid,name,24);
  196. if(VoteActive == 0) return SendClientMessage(playerid,GREY,"There is no active vote cash on right now.");
  197. if(Voted[playerid] == 1) return SendClientMessage(playerid,LIGHTBLUE,"You have already voted!");
  198. KillTimer(thingy);
  199. thingy = SetTimer("VoteFail",21000,false);
  200. Votes++;
  201. Voted[playerid] = 1;
  202. format(str,sizeof(str),"%s has voted. %d/%d",name,Votes,VPlayers);
  203. SendClientMessageToAll(0xFF0000FF,str);
  204. TextDrawDestroy(Votecash);
  205. format(str2,sizeof(str),"~r~Votecash on ~w~%s. ~r~%d/%d",Votes,VPlayers);
  206. TextDrawCreate(50.0,300,str2);
  207. TextDrawLetterSize(Votecash,0.5,2.5);
  208. TextDrawShowForAll(Votecash);
  209. KillTimer(Timer);
  210. Timer = SetTimer("CountDownTimer",1000,true);
  211. Count = 21;
  212. if(Votes == VPlayers)
  213. {
  214. format(str,sizeof(str),"%s has lost some cash :D. %d/%d votes.",Votes,Votes);
  215. SendClientMessageToAll(0xFF0000FF,str);
  216. TextDrawDestroy(Votecash);
  217. KillTimer(thingy);
  218. VoteActive = 0;
  219. GivePlayerMoney(playerid,-10000);
  220. return 1;
  221. }
  222. return 1;
  223. }
  224. forward VoteFail(playerid);
  225. public VoteFail(playerid)
  226. {
  227. Votes = 0;
  228. VoteActive = 0;
  229. Voted[playerid] = 0;
  230. SendClientMessageToAll(LIGHTBLUE,"There were not enough votes for an action to be taken.! :)");
  231. TextDrawDestroy(Voteslap);
  232. TextDrawDestroy(Votecash);
  233. return 1;
  234. }
  235.  
  236. GetPlayersOnServer()
  237. {
  238. new count;
  239. for(new x=0; x< MAX_PLAYERS; x++)
  240. {
  241. if(IsPlayerConnected(x))
  242. {
  243. count++;
  244. }
  245. }
  246. return count;
  247. }
  248. strtok(const string[], &index)
  249. {
  250. new length = strlen(string);
  251. while ((index < length) && (string[index] <= ' '))
  252. {
  253. index++;
  254. }
  255. new offset = index;
  256. new result[20];
  257. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  258. {
  259. result[index - offset] = string[index];
  260. index++;
  261. }
  262. result[index - offset] = EOS;
  263. return result;
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement