Advertisement
Phanto90

PVoteKick v1.0

May 20th, 2011
1,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.39 KB | None | 0 0
  1. /*
  2. ================================================================================
  3.                                Phanto's Script
  4. ________________________________________________________________________________
  5. •Script: PVoteKick           •Scripter:  Phanto90
  6. •Type:   FS                  •File size: 6 Kb
  7. •Lines:  261                 •Version:   1.0v
  8. ________________________________________________________________________________
  9.                                * Description *
  10.                              
  11. Have you problems when there are no admin on your server? Hare a simple votekick
  12. system that permits to normal players to start a votekick for a player.
  13.  
  14.  
  15.                      Thanks for choosing Pawnoscripter!
  16.                      http://pawnoscripter.forumfree.it
  17.      
  18.                                                                       Phanto90
  19. ________________________________________________________________________________
  20.  
  21. Do not remove credits.
  22. ================================================================================
  23. */
  24. //===============INCLUDE
  25. #include <a_samp>
  26. //===============COLORI
  27. #define COLOR_ERROR     0xCB544EFF
  28. #define COLOR_OK        0x50C94EFF
  29. //===============DIALOG
  30. #define DIALOG_VOTEKICK 1945
  31. //===============VAR
  32. new bool:IsVoteKickStarted,
  33.     bool:HasPlayerVoted[MAX_PLAYERS];
  34.  
  35. new PlayerToKick=-1,
  36.     Yes,No,
  37.     seconds=60;
  38.    
  39. new string[135],
  40.     name[24],
  41.     name2[24];
  42.  
  43. new Text: Background,
  44.     Text: VoteKickTitle,
  45.     Text: VoteKickName,
  46.     Text: VoteKickVote,
  47.     Text: VoteKickTime;
  48. //============================================================ONFILTERSCRIPTINIT
  49. public OnFilterScriptInit()
  50. {
  51.     Background = TextDrawCreate(493.000000, 230.000000, "Background");
  52.     TextDrawBackgroundColor(Background, 0);
  53.     TextDrawFont(Background, 1);
  54.     TextDrawLetterSize(Background, 0.500000, 6.099999);
  55.     TextDrawColor(Background, 0);
  56.     TextDrawSetOutline(Background, 0);
  57.     TextDrawSetProportional(Background, 1);
  58.     TextDrawSetShadow(Background, 1);
  59.     TextDrawUseBox(Background, 1);
  60.     TextDrawBoxColor(Background, 1010580580);
  61.     TextDrawTextSize(Background, 616.000000, 0.000000);
  62.  
  63.     VoteKickTitle = TextDrawCreate(497.000000, 211.000000, "~>~Votekick~<~");
  64.     TextDrawBackgroundColor(VoteKickTitle, 255);
  65.     TextDrawFont(VoteKickTitle, 0);
  66.     TextDrawLetterSize(VoteKickTitle, 0.660000, 2.599999);
  67.     TextDrawColor(VoteKickTitle, -1);
  68.     TextDrawSetOutline(VoteKickTitle, 1);
  69.     TextDrawSetProportional(VoteKickTitle, 1);
  70.  
  71.     VoteKickVote = TextDrawCreate(555.000000, 254.000000, "~g~~h~Yes~w~: 0  ~r~No~w~: 0");
  72.     TextDrawAlignment(VoteKickVote, 2);
  73.     TextDrawBackgroundColor(VoteKickVote, 255);
  74.     TextDrawFont(VoteKickVote, 2);
  75.     TextDrawLetterSize(VoteKickVote, 0.390000, 2.199999);
  76.     TextDrawColor(VoteKickVote, -1);
  77.     TextDrawSetOutline(VoteKickVote, 1);
  78.     TextDrawSetProportional(VoteKickVote, 1);
  79.  
  80.     VoteKickTime = TextDrawCreate(601.000000, 273.000000, "60");
  81.     TextDrawBackgroundColor(VoteKickTime, 255);
  82.     TextDrawFont(VoteKickTime, 2);
  83.     TextDrawLetterSize(VoteKickTime, 0.250000, 1.500000);
  84.     TextDrawColor(VoteKickTime, -926365441);
  85.     TextDrawSetOutline(VoteKickTime, 1);
  86.     TextDrawSetProportional(VoteKickTime, 1);
  87.  
  88.     VoteKickName = TextDrawCreate(555.000000, 241.000000, "Player_Name");
  89.     TextDrawAlignment(VoteKickName, 2);
  90.     TextDrawBackgroundColor(VoteKickName, 255);
  91.     TextDrawFont(VoteKickName, 1);
  92.     TextDrawLetterSize(VoteKickName, 0.280000, 1.300000);
  93.     TextDrawColor(VoteKickName, -1);
  94.     TextDrawSetOutline(VoteKickName, 1);
  95.     TextDrawSetProportional(VoteKickName, 1);
  96.     return 1;
  97. }
  98. //===============================================================ONPLAYERCONNECT
  99. public OnPlayerConnect(playerid)
  100. {
  101.     if(IsVoteKickStarted == true)
  102.     {
  103.     TextDrawShowForPlayer(playerid, Background); //Prevent bugs in case a player connects while a votekick is started
  104.     TextDrawShowForPlayer(playerid, VoteKickTitle);
  105.     TextDrawShowForPlayer(playerid, VoteKickName);
  106.     TextDrawShowForPlayer(playerid, VoteKickVote);
  107.     TextDrawShowForPlayer(playerid, VoteKickTime);
  108.     return 1;
  109.     }
  110.     return 1;
  111. }
  112. //===========================================================ONPLAYERCOMMANDTEXT
  113. public OnPlayerCommandText(playerid, cmdtext[])
  114. {
  115.     if(!strcmp("/votekick", cmdtext, true))
  116.     {
  117.         if(IsVoteKickStarted == true) return SendClientMessage(playerid, COLOR_ERROR,"[ERROR:] {BBBBBB}A votekick has been already started. Wait until it finish to ask for a new one");
  118.         ShowPlayerDialog(playerid, DIALOG_VOTEKICK, DIALOG_STYLE_INPUT, "{C14124}V{BBBBBB}otekick", "{BBBBBB}Type player's {C14124}ID{BBBBBB} or {C14124}Nick{BBBBBB} you want to votekick.", "VoteKick", "Cancel");
  119.         return 1;
  120.     }
  121.     return 1;
  122. }
  123. //============================================================ONPLAYERDISCONNECT
  124. public OnPlayerDisconnect(playerid)
  125. {
  126.     if(PlayerToKick == playerid)
  127.     {
  128.     GetPlayerName(playerid, name, sizeof(name));
  129.     format(string, sizeof(string), "{C14124}%s{BBBBBB} exited the server, so the votekick has been closed automatically.", name);
  130.     SendClientMessageToAll(COLOR_OK, string);
  131.     Yes=0,No=0,PlayerToKick=-1, seconds=60, IsVoteKickStarted=false;
  132.     TextDrawHideForAll(Background);
  133.     TextDrawHideForAll(VoteKickTitle);
  134.     TextDrawHideForAll(VoteKickName);
  135.     TextDrawHideForAll(VoteKickVote);
  136.     TextDrawSetString(VoteKickVote,"~g~~h~Yes~w~: 0  ~r~No~w~: 0");
  137.     TextDrawHideForAll(VoteKickTime);
  138.     return 1;
  139.     }
  140.     return 1;
  141. }
  142. //==============================================================ONDIALOGRESPONSE
  143. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  144. {
  145.     if(dialogid==DIALOG_VOTEKICK && response)
  146.     {
  147.         if(IsVoteKickStarted == true) return SendClientMessage(playerid, COLOR_ERROR,"[ERROR:] {BBBBBB}A votekick has been already started. Wait until it finish to ask for a new one");
  148.         if(IsNumeric(inputtext)) StartVoteKick(strval(inputtext));
  149.         else
  150.         {
  151.             for(new i = 0; i<MAX_PLAYERS; i++)
  152.                 {
  153.                 GetPlayerName(playerid, name, sizeof(name));
  154.                 if(!strcmp(inputtext, name, true))
  155.                     {
  156.                     StartVoteKick(i);
  157.                     break;
  158.                     }
  159.                 }
  160.         }
  161.         if(PlayerToKick == -1) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR:] {BBBBBB}Player not found.");
  162.         GetPlayerName(playerid, name2, sizeof(name2));
  163.         format(string, sizeof(string), "{C14124}%s{BBBBBB} has started a votekick for {C14124}%s{BBBBBB}. Type {60B149}Yes{BBBBBB} or {B35349}No{BBBBBB} to vote.", name2, name);
  164.         SendClientMessageToAll(COLOR_OK, string);
  165.         return 1;
  166.     }
  167.     return 1;
  168. }
  169. //=================================================================STARTVOTEKICK
  170. stock StartVoteKick(playerid)
  171. {
  172.     if(!IsPlayerConnected(playerid)) return 0;
  173.     PlayerToKick = playerid;
  174.     IsVoteKickStarted = true;
  175.     TextDrawShowForAll(Background);
  176.     TextDrawShowForAll(VoteKickTitle);
  177.     TextDrawShowForAll(VoteKickName);
  178.     GetPlayerName(playerid,name,sizeof(name));
  179.     TextDrawSetString(VoteKickName,name);
  180.     TextDrawShowForAll(VoteKickVote);
  181.     TextDrawShowForAll(VoteKickTime);
  182.     for(new i = 0; i<MAX_PLAYERS; i++)
  183.         HasPlayerVoted[i] = false;
  184.     SetTimer("KickTimer",1000,false);
  185.     return 1;
  186. }
  187. //======================================================================KICKTIME
  188. forward KickTimer();
  189. public  KickTimer()
  190. {
  191.     if(PlayerToKick == -1) return 1;
  192.     if(seconds == 0) return EndVoteKick();
  193.     seconds--;
  194.     format(string,sizeof(string),"%02d",seconds);
  195.     TextDrawHideForAll(VoteKickTime);
  196.     TextDrawSetString(VoteKickTime, string);
  197.     TextDrawShowForAll(VoteKickTime);
  198.     SetTimer("KickTimer",1000,false);
  199.     return 1;
  200. }
  201. //===================================================================ENDVOTEKICK
  202. stock EndVoteKick()
  203. {
  204.     GetPlayerName(PlayerToKick, name, sizeof(name));
  205.     if(Yes>No)
  206.     {
  207.         format(string, sizeof(string), "{C14124}%s {BBBBBB}has been votekicked. [%d Yes | %d No]", name, Yes, No);
  208.         Kick(PlayerToKick);
  209.     }
  210.     else
  211.     {
  212.         format(string, sizeof(string), "{C14124}%s {BBBBBB}has not been kicked. [%d Yes | %d No]", name, Yes, No);
  213.     }
  214.     SendClientMessageToAll(COLOR_OK, string);
  215.     Yes=0,No=0,PlayerToKick=-1, seconds=60, IsVoteKickStarted=false;
  216.     TextDrawHideForAll(Background);
  217.     TextDrawHideForAll(VoteKickTitle);
  218.     TextDrawHideForAll(VoteKickName);
  219.     TextDrawHideForAll(VoteKickVote);
  220.     TextDrawSetString(VoteKickVote,"~g~~h~Yes~w~: 0  ~r~No~w~: 0");
  221.     TextDrawHideForAll(VoteKickTime);
  222.     return 1;
  223. }
  224. //=====================================================================ISNUMERIC
  225. stock IsNumeric(str[])
  226. {
  227.     for(new i=0; i<strlen(str); i++)
  228.     {
  229.         if(str[i]<'0' || str[i]>'9')
  230.         return 0;
  231.     }
  232.     return 1;
  233. }
  234. //==================================================================ONPLAYERTEXT
  235. public OnPlayerText(playerid, text[])
  236. {
  237.     if(!strcmp("Yes", text, true) && strlen(text)==strlen("Yes") && IsVoteKickStarted == true && HasPlayerVoted[playerid] == false)
  238.     {
  239.         Yes++;
  240.         HasPlayerVoted[playerid]= true;
  241.         SendClientMessage(playerid, COLOR_OK, "[VOTE:] {BBBBBB}Thanks for voting!");
  242.         format(string,sizeof(string), "~g~~h~Yes~w~: %d  ~r~No~w~: %d", Yes, No);
  243.         TextDrawHideForAll(VoteKickVote);
  244.         TextDrawSetString(VoteKickVote,string);
  245.         TextDrawShowForAll(VoteKickVote);
  246.         return 0;
  247.     }
  248.     if(!strcmp("No", text, true) && strlen(text)==strlen("No") && IsVoteKickStarted == true && HasPlayerVoted[playerid] == false)
  249.     {
  250.         No++;
  251.         HasPlayerVoted[playerid]= true;
  252.         SendClientMessage(playerid, COLOR_OK, "[VOTE:] {BBBBBB}Thanks for voting!");
  253.         format(string,sizeof(string), "~g~~h~Yes~w~: %d  ~r~No~w~: %d", Yes, No);
  254.         TextDrawHideForAll(VoteKickVote);
  255.         TextDrawSetString(VoteKickVote,string);
  256.         TextDrawShowForAll(VoteKickVote);
  257.         return 0;
  258.     }
  259.     return 1;
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement