Advertisement
2ky

2K-VOTE

2ky
Feb 7th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.96 KB | None | 0 0
  1. #include    < a_samp >      //samp natives -- Kye
  2. #include    < zcmd >        //command processor -- ZeeX
  3. #include    < sscanf2_5 >   //sscanf "unformat" v2.5 -- Y_Less
  4.  
  5. new
  6.  
  7.     bool:player_HasVoted[MAX_PLAYERS]       =   false,
  8.     bool:global_Cooldown                    =   false,
  9.          player_VotingPlayer[MAX_PLAYERS]   =   -1,
  10.          global_PlayerBeingVoted            =   -1,
  11.          global_VoteYes                     =   0,
  12.          global_VoteNo                      =   0
  13. ;
  14.    
  15. #define     DIALOG_TITLE_COLOUR     09C6DB
  16.  
  17. #define     DIALOG_TEXT_COLOUR      A31414
  18.  
  19. #define     DIALOG_TEXT_REASONS     "Use of Cheats\nFlaming\nSpawn Killing"
  20.             /*
  21.                 Edit this string with your available reasons to kick a player.
  22.                 Put \n between reasons.
  23.                 Example: Cheating\nFlaming would display:       Cheating
  24.                                                                 Flaming
  25.                                                                
  26.                 After editing this, go down to OnDialogResponse, and add a new 'case' for it.
  27.             */
  28.  
  29. #define     DIALOG_VOTEKICK         1000
  30.             /*
  31.                 Edit this number to your preferred dialog ID,
  32.                 This is easily editable in order to prevent confrontations (issues) with your gamemode.
  33.             */
  34.            
  35. #define     VOTEKICK_TIME           30
  36.             /*
  37.                 Edit this number to your preferred vote-kick time.
  38.                 This number is in seconds, therefore a 30 here would mean it would take 30 seconds before a vote is made.
  39.             */
  40.            
  41. #define     VOTEKICK_COOLDOWN       5*60000
  42.             /*
  43.                 Edit this number to your preferred vote-kick cooldown time.
  44.                 After someone is voted, this timer will start and prevent other users from votekicking them until it resets the variable.
  45.                 By default, this cooldown is on 5 minutes.
  46.             */
  47.            
  48. public      OnFilterScriptInit() {
  49.  
  50.     print("2K-VOTE has been loaded.");
  51.     for( new gPlayers; gPlayers < MAX_PLAYERS; gPlayers++ )
  52.     {
  53.         if(IsPlayerConnected(gPlayers))
  54.         {
  55.        
  56.             player_HasVoted[gPlayers] = false;
  57.             //The filterscript just got loaded, how would someone vote beforehand?
  58.            
  59.         }
  60.     }
  61.     return true;
  62.    
  63. }
  64.  
  65. public      OnPlayerConnect(playerid) {
  66.  
  67.     player_HasVoted[playerid] = false;
  68.     return true;
  69.    
  70. }
  71.  
  72. CMD:votekick(playerid, params[]) {
  73.  
  74.     new
  75.         p_ID;
  76.    
  77.     if(sscanf(params, "u", p_ID))
  78.         return SendClientMessage(playerid, 0xA31414FF, "< /votekick < Player ID >");
  79.        
  80.     if(player_VotingPlayer[playerid] == INVALID_PLAYER_ID)
  81.         return SendClientMessage(playerid, 0xA31414FF, "< /votekick: Invalid Player ID!");
  82.        
  83.     if(global_Cooldown == true)
  84.         return SendClientMessage(playerid, 0xA31414FF, "< /votekick: Someone has already been votekicked recently!");
  85.    
  86.     player_VotingPlayer[playerid] = p_ID;
  87.     global_PlayerBeingVoted = p_ID;
  88.  
  89.     ShowPlayerDialog(playerid, DIALOG_VOTEKICK, DIALOG_STYLE_LIST, "{09C6DB}2K-VOTE: Select a reason", "{FFFFFF}"DIALOG_TEXT_REASONS"", "Select", "Cancel");
  90.     return true;
  91.    
  92. }
  93.  
  94. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  95. {
  96.  
  97.     switch( dialogid )
  98.     {
  99.    
  100.         case    DIALOG_VOTEKICK:
  101.         {
  102.        
  103.             if( response )
  104.             {
  105.            
  106.                 if( player_VotingPlayer[playerid] != INVALID_PLAYER_ID ) //Checking once again to see if the player is valid.
  107.                 {
  108.                    
  109.                     new
  110.                         c_Name[MAX_PLAYER_NAME],
  111.                         p_Name[MAX_PLAYER_NAME],
  112.                         vStr[128],
  113.                         vStr2[156]
  114.                     ;
  115.                    
  116.                     GetPlayerName(player_VotingPlayer[playerid], c_Name, sizeof(c_Name));
  117.                     GetPlayerName(playerid, p_Name, sizeof(p_Name));
  118.                    
  119.                     switch( listitem )
  120.                     {
  121.                        
  122.                         case 0:
  123.                         {
  124.                            
  125.                             //Use of Cheats
  126.                             format(vStr, sizeof(vStr), "<ATN> %s is being votekicked by %s, Reason: Use of Cheats!", c_Name, p_Name);
  127.                             format(vStr2, sizeof(vStr2), "{FFFFFF}%s has started a votekick against %s.\nREASON: Use of Cheats!\n{6BE012}Would you like to vote to kick this player?", p_Name, c_Name);
  128.                             for ( new gPlayers; gPlayers < MAX_PLAYERS; gPlayers++ )
  129.                             {
  130.                            
  131.                                 if ( gPlayers == player_VotingPlayer[playerid]) return 0;
  132.                                
  133.                                 SendClientMessage(gPlayers, 0xFFFFFFFF, vStr);
  134.                                 ShowPlayerDialog(gPlayers, DIALOG_VOTEKICK+1, DIALOG_STYLE_MSGBOX, "{09C6DB}2K-VOTE: Votekick?", vStr2, "No", "Yes");
  135.                                 SetTimer("VoteKick", VOTEKICK_TIME*1000, false);
  136.                             }
  137.                             global_Cooldown = true;
  138.                        
  139.                         }
  140.                        
  141.                         case 1:
  142.                         {
  143.                            
  144.                             //Flaming
  145.                             format(vStr, sizeof(vStr), "<ATN> %s is being votekicked by %s, Reason: Flaming!", c_Name, p_Name);
  146.                             format(vStr2, sizeof(vStr2), "{FFFFFF}%s has started a votekick against %s.\nREASON: Flaming!\n{6BE012}Would you like to vote to kick this player?", p_Name, c_Name);
  147.                             for ( new gPlayers; gPlayers < MAX_PLAYERS; gPlayers++ )
  148.                             {
  149.                            
  150.                                 if ( gPlayers == player_VotingPlayer[playerid]) return 0;
  151.                                
  152.                                 SendClientMessage(gPlayers, 0xFFFFFFFF, vStr);
  153.                                 ShowPlayerDialog(gPlayers, DIALOG_VOTEKICK+1, DIALOG_STYLE_MSGBOX, "{09C6DB}2K-VOTE: Votekick?", vStr2, "No", "Yes");
  154.                                 SetTimer("VoteKick", VOTEKICK_TIME*1000, false);
  155.                             }
  156.                             global_Cooldown = true;
  157.                        
  158.                         }
  159.                        
  160.                         case 2:
  161.                         {
  162.                        
  163.                             //Spawn-Killing
  164.                             format(vStr, sizeof(vStr), "<ATN> %s is being votekicked by %s, Reason: Spawn Killing!", c_Name, p_Name);
  165.                             format(vStr2, sizeof(vStr2), "{FFFFFF}%s has started a votekick against %s.\nREASON: Spawn Killing!\n{6BE012}Would you like to vote to kick this player?", p_Name, c_Name);
  166.                             for ( new gPlayers; gPlayers < MAX_PLAYERS; gPlayers++ )
  167.                             {
  168.                            
  169.                                 if ( gPlayers == player_VotingPlayer[playerid]) return 0;
  170.                                
  171.                                 SendClientMessage(gPlayers, 0xFFFFFFFF, vStr);
  172.                                 ShowPlayerDialog(gPlayers, DIALOG_VOTEKICK+1, DIALOG_STYLE_MSGBOX, "{09C6DB}2K-VOTE: Votekick?", vStr2, "No", "Yes");
  173.                                 SetTimer("VoteKick", VOTEKICK_TIME*1000, false);
  174.                             }
  175.                             global_Cooldown = true;
  176.                        
  177.                         }
  178.                        
  179.                     }
  180.                
  181.                 }
  182.                
  183.             }
  184.        
  185.         }
  186.        
  187.         case    DIALOG_VOTEKICK+1:
  188.         {
  189.        
  190.             if( response ) //They voted no!
  191.             {
  192.            
  193.                 global_VoteNo++;
  194.                 SendClientMessage(playerid, 0xFFFFFFFF, "< You have voted no on the votekick!");
  195.            
  196.             }
  197.            
  198.             else if( !response )
  199.             {
  200.            
  201.                 global_VoteYes++;
  202.                 SendClientMessage(playerid, 0xFFFFFFFF, "< You have voted yes on the votekick!");
  203.             }
  204.        
  205.         }
  206.    
  207.     }
  208.     return true;
  209.    
  210. }
  211.  
  212. forward     VoteKick();
  213. public      VoteKick()
  214. {
  215.     new
  216.         vStr[128],
  217.         c_Name[MAX_PLAYER_NAME]
  218.     ;
  219.    
  220.     GetPlayerName(global_PlayerBeingVoted, c_Name, sizeof(c_Name));
  221.        
  222.     if(global_VoteNo < global_VoteYes) {
  223.        
  224.         //They have successfully votekicked the user.
  225.         format(vStr, sizeof(vStr), "{09C6DB}<ATN> {FFFFFF}%s has been votekicked.", c_Name);
  226.         SendClientMessageToAll(0xFFFFFFFF, vStr);
  227.         Kick(global_PlayerBeingVoted);
  228.        
  229.     }
  230.     else if(global_VoteYes < global_VoteNo) {
  231.    
  232.         //The Votekick has failed.
  233.         format(vStr, sizeof(vStr), "{09C6DB}<ATN> {FFFFFF}%s has not been votekicked.", c_Name);
  234.         SendClientMessageToAll(0xFFFFFFFF, vStr);
  235.        
  236.     }
  237.     global_VoteNo = 0, global_VoteYes = 0;
  238.     global_PlayerBeingVoted = -1;
  239.     return true;
  240. }
  241.  
  242. public      OnPlayerDisconnect(playerid, reason) {
  243.  
  244.     return true;
  245.    
  246. }
  247.  
  248. public      OnFilterScriptExit() {
  249.  
  250.     print("2K-VOTE has been unloaded.");
  251.     return true;
  252.    
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement