Advertisement
Guest User

Game Style Vote

a guest
Jun 28th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.32 KB | None | 0 0
  1. #include <amxmodx>
  2.  
  3. #define VERSION "0.1"
  4.  
  5. enum{
  6.     NORMAL,
  7.     BOOST,
  8.     TASK_VOTE = 1337
  9. };
  10.  
  11. new g_iVotes[2 * BOOST] = 0;
  12. new bool:g_bVotedAlready[33] = false;
  13. new pCvarGameStyleCommand, pCvarVoteDelay, pCvarVoteTime;
  14. new g_iVoteTimer;
  15.  
  16. public plugin_init() {
  17.     register_plugin("Game Style Vote", VERSION, "diablix")
  18.    
  19.     register_menucmd(register_menuid("VoteMenu"), 1023, "handleVoteMenu");
  20.    
  21.     pCvarGameStyleCommand   = register_cvar("vote_command", "hns_semiclip");
  22.     pCvarVoteDelay          = register_cvar("vote_delay", "120");
  23.     pCvarVoteTime           = register_cvar("vote_time", "30");
  24.    
  25.     g_iVoteTimer = get_pcvar_num(pCvarVoteTime);
  26. }
  27.  
  28. public plugin_cfg()
  29.     set_task(float(get_pcvar_num(pCvarVoteDelay)), "taskBegin");
  30.  
  31. public taskBegin()
  32.     set_task(1.0, "taskVote", TASK_VOTE, _, _, "a", get_pcvar_num(pCvarVoteTime));
  33.    
  34. public taskVote(){
  35.     g_iVoteTimer --;
  36.    
  37.     set_hudmessage(85, 255, 85, 0.0, 0.18, 0, 1.2, 1.2, 0.1, 0.1, 4);
  38.     show_hudmessage(0, "%d seconds left to begin the vote!", g_iVoteTimer);
  39.    
  40.     new iPlayers[32], iNum;
  41.     get_players(iPlayers, iNum);
  42.    
  43.     for(new i ; i < iNum ; i ++){
  44.         showVoteMenu(iPlayers[i]);
  45.     }
  46.     if(g_iVoteTimer == 1){
  47.         g_iVoteTimer = 0;
  48.         remove_task(TASK_VOTE);
  49.        
  50.         set_hudmessage(85, 255, 85, 0.0, 0.18, 0, 6.2, 6.2, 1.1, 1.1, 4);
  51.         show_hudmessage(0, "Game Style changed to %s !", g_iVotes[BOOST] >= g_iVotes[NORMAL] ? "boost" : "normal");
  52.        
  53.         new s_pCvarString[32];
  54.         get_pcvar_string(pCvarGameStyleCommand, s_pCvarString, sizeof s_pCvarString - 1);
  55.        
  56.         set_cvar_num(s_pCvarString, g_iVotes[BOOST] >= g_iVotes[NORMAL] ? 0 : 1);
  57.     }  
  58. }
  59.    
  60. public showVoteMenu(id){
  61.     new szMenuBody[256], iLen, bit_Keys;
  62.     iLen = formatex(szMenuBody, sizeof szMenuBody -1, "[HNS]\y Pick Game Style^n\y %d\w seconds left", g_iVoteTimer);
  63.     iLen += formatex(szMenuBody[iLen], sizeof szMenuBody -1, "^n^n\r1. \wBoost\r  |\w Votes :\y %d", g_iVotes[BOOST]);
  64.     iLen += formatex(szMenuBody[iLen], sizeof szMenuBody -1, "^n\r2. \wNormal\r |\w Votes :\y %d", g_iVotes[NORMAL]);
  65.    
  66.     bit_Keys = (1<<0)|(1<<1);
  67.    
  68.     show_menu(id, bit_Keys, szMenuBody, -1, "VoteMenu");
  69.    
  70.     return 1;
  71. }
  72.  
  73. public handleVoteMenu(id, iKey){
  74.     if(!g_bVotedAlready[id]){
  75.         g_iVotes[iKey] ++;
  76.         client_print(id, 3, "You voted for %s game style.", iKey == BOOST ? "boost" : "normal");
  77.         g_bVotedAlready[id] = !g_bVotedAlready[id];
  78.     }
  79.    
  80.     return 1;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement