Guest User

Vote Slap System By RandomDude.

a guest
Apr 19th, 2013
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. #if defined FILTERSCRIPT
  29.  
  30. public OnFilterScriptInit()
  31. {
  32.     print("\n--------------------------------------");
  33.     print("FilterScript Made By RandomDude.");
  34.     print("--------------------------------------\n");
  35.     return 1;
  36. }
  37.  
  38. public OnFilterScriptExit()
  39. {
  40.     return 1;
  41. }
  42. #endif
  43.  
  44. public OnPlayerConnect(playerid)
  45. {
  46.     Voted[playerid] = 0;
  47.     return 1;
  48. }
  49. public CountDownTimer(playerid)
  50. {
  51.     new string[3];
  52.     Count--;
  53.     TextDrawDestroy(TCountDown);
  54.     format(string,sizeof(string),"%d",Count);
  55.     TCountDown = TextDrawCreate(300.0,300.0,string);
  56.  
  57.     TextDrawTextSize(TCountDown,0.7,3.0);
  58.     TextDrawShowForAll(TCountDown);
  59.    
  60.     if(Count == 0)
  61.     {
  62.         KillTimer(Timer);
  63.         KillTimer(thingy);
  64.         TextDrawDestroy(TCountDown);
  65.         TextDrawDestroy(Voteslap);
  66.         Voted[playerid] = 0;
  67.     }
  68.     return 1;
  69. }
  70.  
  71. public OnPlayerCommandText(playerid, cmdtext[])
  72. {
  73.     dcmd(voteslap,8,cmdtext);
  74.     dcmd(vote,4,cmdtext);
  75.     dcmd(stopvote,8,cmdtext);
  76.     return 0;
  77. }
  78. dcmd_stopvote(playerid,params[])
  79. {
  80.     #pragma unused params
  81.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,LIGHTBLUE,"You are not an admin!");
  82.     TextDrawDestroy(TCountDown);
  83.     TextDrawDestroy(Voteslap);
  84.     KillTimer(Timer);
  85.     KillTimer(thingy);
  86.     SendClientMessageToAll(0xFF0000FF,"An admin has stopped the vote slap.");
  87.     return 1;
  88. }
  89. dcmd_voteslap(playerid,params[])
  90. {
  91.     new id,n[24],on[24],str2[128],string[3];
  92.     new tmp[256], tmp2[256], Index,str[128];
  93.     VPlayers = GetPlayersOnServer()/2+1;
  94.     if(GetPlayersOnServer() <= 2)
  95.         return SendClientMessage(playerid,GREY,"The minimum players required for this command to work are 3.");
  96.     tmp = strtok(params,Index), tmp2 = strtok(params,Index),id = strval(tmp);
  97.     if(IsPlayerAdmin(id)) return SendClientMessage(playerid,0xFF0000FF,"You cannot try to voteslap an admin! -_-");
  98.     if(VoteActive == 1) return SendClientMessage(playerid,0xFF0000FF,"There is already a voteslap in proccess, please wait until it has finished.");
  99.     GetPlayerName(playerid,n,24),GetPlayerName(id,on,24);
  100.     Voted[playerid] = 1;
  101.     SlapName = on;
  102.     PlayerName = n;
  103.     if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /voteslap [ID] [Reason]");
  104.     if(!IsPlayerConnected(id))return SendClientMessage(playerid,GREY,"You have entered an incorrect ID.");
  105.     Votes = 1;
  106.     VoteActive = 1;
  107.     format(str2,sizeof(str2),"~r~Voteslap on ~w~%s. ~r~%d/%d",PlayerName,Votes,VPlayers);
  108.     Voteslap = TextDrawCreate(50.0,300.0,str2);
  109.     TextDrawLetterSize(Voteslap,0.5,2.5);
  110.     TextDrawShowForAll(Voteslap);
  111.     thingy = SetTimer("VoteFail",21000,false);
  112.     Timer = SetTimerEx("CountDownTimer",1000,true,"i",playerid);
  113.     format(str,sizeof(str),"%s has started a voteslap on %s. Reason: %s. To vote /vote",n,on,params[2]);
  114.     SendClientMessageToAll(0xFF0000FF,str);
  115.     format(string,sizeof(string),"%d",Count);
  116.     TCountDown = TextDrawCreate(300.0,300.0,string);
  117.     Count = 21;
  118.     return 1;
  119. }
  120. dcmd_vote(playerid,params[])
  121. {
  122.     #pragma unused params
  123.     new str[128],name[24],str2[128];
  124.     GetPlayerName(playerid,name,24);
  125.     if(VoteActive == 0) return SendClientMessage(playerid,GREY,"There is no active vote slap on right now.");
  126.     if(Voted[playerid] == 1) return SendClientMessage(playerid,LIGHTBLUE,"You have already voted!");
  127.     KillTimer(thingy);
  128.     thingy = SetTimer("VoteFail",21000,false);
  129.     Votes++;
  130.     Voted[playerid] = 1;
  131.     format(str,sizeof(str),"%s has voted. %d/%d",name,Votes,VPlayers);
  132.     SendClientMessageToAll(0xFF0000FF,str);
  133.     TextDrawDestroy(Voteslap);
  134.     format(str2,sizeof(str),"~r~Voteslap on ~w~%s. ~r~%d/%d",Votes,VPlayers);
  135.     TextDrawCreate(50.0,300,str2);
  136.     TextDrawLetterSize(Voteslap,0.5,2.5);
  137.     TextDrawShowForAll(Voteslap);
  138.     KillTimer(Timer);
  139.     Timer = SetTimer("CountDownTimer",1000,true);
  140.     Count = 21;
  141.     if(Votes == VPlayers)
  142.     {
  143.         format(str,sizeof(str),"%s has been slapped. %d/%d votes.",Votes,Votes);
  144.         SendClientMessageToAll(0xFF0000FF,str);
  145.         TextDrawDestroy(Voteslap);
  146.         KillTimer(thingy);
  147.         VoteActive = 0;
  148.         new Float:PPos[3];
  149.         GetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]);
  150.         SetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]+4);
  151.         return 1;
  152.     }
  153.     return 1;
  154. }
  155.    
  156. forward VoteFail(playerid);
  157. public VoteFail(playerid)
  158. {
  159.     Votes = 0;
  160.     VoteActive = 0;
  161.     Voted[playerid] = 0;
  162.     SendClientMessageToAll(LIGHTBLUE,"There were not enough votes for the voteslap! :)");
  163.     TextDrawDestroy(Voteslap);
  164.     return 1;
  165. }
  166.  
  167. GetPlayersOnServer()
  168. {
  169.     new count;
  170.     for(new x=0; x< MAX_PLAYERS; x++)
  171.     {
  172.         if(IsPlayerConnected(x))
  173.         {
  174.             count++;
  175.         }
  176.     }
  177.     return count;
  178. }
  179. strtok(const string[], &index)
  180. {
  181.     new length = strlen(string);
  182.     while ((index < length) && (string[index] <= ' '))
  183.     {
  184.         index++;
  185.     }
  186.     new offset = index;
  187.     new result[20];
  188.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  189.     {
  190.         result[index - offset] = string[index];
  191.         index++;
  192.     }
  193.     result[index - offset] = EOS;
  194.     return result;
  195. }
RAW Paste Data