Advertisement
2ky

2K-VOTE

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