Advertisement
Guest User

Vote Map On Rounds

a guest
Oct 25th, 2014
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.63 KB | None | 0 0
  1. #include < amxmodx >
  2.  
  3. #define MAX_MAPS 4
  4.  
  5. #define  VOTE_NO 0
  6. #define  VOTE_IN_PROGRESS 1
  7. #define  VOTE_ENDED 2
  8.  
  9. new const Tag[] = "YourTag";
  10. new bool:Voted[ 33 ];
  11. new g_szRoundVotemap, Timer
  12. new g_szKind[MAX_MAPS]
  13. new g_maps[MAX_MAPS][30]
  14. new rounds
  15. new menu
  16. new g_votestatus
  17. new g_nextmap[30]
  18.  
  19. new const Change[][] =
  20. {
  21. "de_dust2",
  22. "de_nuke",
  23. "de_inferno",
  24. "de_train",
  25. "de_dust" //יכולים להוסיף כמה מפות שאתם רוצים
  26.  
  27. }
  28.  
  29. public plugin_init()
  30. {
  31. register_plugin("Simple VoteMap", "1.0", "AMXX")    
  32. register_event( "HLTV", "NewRound", "a", "1=0", "2=0" )
  33. rounds = register_cvar("amx_roundtovote", "35") // מספר הראונדים שיהיה הצבעה
  34.  
  35. register_clcmd("say nextvote", "shownextvote")  
  36. register_clcmd("say /nextvote", "shownextvote")  
  37. set_task(45.0,"Adv_message",.flags="b")
  38.  
  39. g_votestatus = VOTE_NO
  40. }
  41.  
  42. public shownextvote(id)
  43. {
  44. if(g_votestatus == VOTE_NO)
  45. {
  46.     new r = get_pcvar_num(rounds) - g_szRoundVotemap
  47.     if(r > 0)
  48.         ColorChat(id, "There Will be^4 VoteMaps^1 in:^3 %i ^1Rounds", r)
  49.     }
  50.     return PLUGIN_HANDLED
  51. }  
  52.  
  53. public NewRound()
  54. {
  55.     if(g_votestatus == VOTE_IN_PROGRESS)
  56.         return
  57.    
  58.     g_szRoundVotemap++
  59.     new rounds_left = get_pcvar_num(rounds) - g_szRoundVotemap
  60.    
  61.     if(rounds_left > 0)
  62.         ColorChat(0, "There Will be^4 VoteMaps^1 in:^3 %i ^1Rounds", rounds_left)
  63.     else
  64.     {
  65.         if(g_votestatus == VOTE_NO)
  66.         {
  67.             ColorChat(0, "^4 VoteMaps^1 will start now", rounds_left)
  68.             set_task(1.0, "ActionSpecial")
  69.             g_votestatus = VOTE_IN_PROGRESS
  70.         }
  71.        
  72.         if(g_votestatus == VOTE_ENDED)
  73.         {
  74.             message_begin(MSG_ALL, SVC_INTERMISSION)
  75.             message_end()
  76.             set_task(floatmax(get_cvar_float("mp_chattime"), 2.0), "map_change")
  77.             ColorChat(0, "Nextmap will be^4 %s", g_nextmap)
  78.         }
  79.     }
  80. }  
  81.  
  82. public map_change()
  83.     server_cmd("changelevel %s", g_nextmap)
  84.  
  85. public ActionSpecial()
  86. {
  87.     new mapid, currentmap[32]
  88.     new bool:g_choosedmap[sizeof(Change)] = false
  89.    
  90.     get_mapname(currentmap, 31)
  91.     for(mapid = 0; mapid < sizeof(Change); mapid++) //don't add currentmap to vote
  92.         if(equali(Change[mapid], currentmap))
  93.     {
  94.         g_choosedmap[mapid] = true
  95.         break  
  96.     }
  97.    
  98.     for(new i = 0; i < MAX_MAPS; i++)           //select defined amount maps
  99.     {
  100.         g_szKind[i] = 0             //clean votes
  101.        
  102.         do
  103.     {
  104.         while(g_choosedmap[mapid = random_num(0, sizeof(Change)-1)]) {}//if already in vote let's take another  
  105.            
  106.         } while(!is_map_valid(Change[mapid]))   //if not valid map choose another aswell
  107.        
  108.         g_choosedmap[mapid] = true      //choosed for vote, will not be picked again
  109.         format(g_maps[i], 29, "%s", Change[mapid])//added to selected maps for vote
  110.     }
  111.    
  112.     new players[32], num, id
  113.     get_players(players, num)
  114.     for( new i = 0; i < num; i++ ) //show menu
  115.     {
  116.         id = players[i]
  117.         Voted[id] = false;
  118.         ChangeMaps(id)
  119.     }
  120.    
  121.     Timer = 17
  122.    
  123.     client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use bay(s18) mass(e42) cap(s50)^"")  
  124.     set_task( 17.0, "checkvotesd");
  125.     countdown2()
  126. }
  127.  
  128. public ChangeMaps(client)
  129. {
  130.     if(Timer >= 0)
  131.     {
  132.         static szMap[128]
  133.         new st[3]
  134.         formatex(szMap, charsmax(szMap)-1, "\d[\r AMXX \d]^n\w Which Map Do You Want?^n\r// \wStatus: %s^n\r// \wTime to choose: \y%i",Voted[client] ? "\yVoted" : "\rNot Voted", Timer)
  135.         menu = menu_create(szMap, "menu_handler")
  136.        
  137.         for( new k = 0; k < MAX_MAPS; k++ ) // show selected maps + votes
  138.         {
  139.             num_to_str(k+1, st, 2)
  140.             formatex( szMap, charsmax(szMap)-1, "\w%s \w[\r%i \yVotes\w]", g_maps[k] , g_szKind[k])
  141.             menu_additem(menu, szMap, st)
  142.         }
  143.        
  144.         menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
  145.         menu_display(client, menu)
  146.     }
  147.     else    //vote expired
  148.         show_menu(client,0,"^n",1)
  149.     }
  150.    
  151.     public checkvotesd()
  152.     {      
  153.         new Winner = 0;
  154.         for( new i = 1; i < sizeof g_maps; i++ ) // select maps with more votes
  155.         {
  156.             if(g_szKind[Winner] < g_szKind[i])
  157.                 Winner = i
  158.         }
  159.        
  160.         ColorChat(0, "%s ^3Won ^1the vote with ^4%i ^1Votes ^3Next Round Change Map^1.", g_maps[Winner], g_szKind[Winner])
  161.         format(g_nextmap, 29, "%s", g_maps[Winner])   // set winner as nextmap
  162.         g_votestatus = VOTE_ENDED
  163.     }
  164.    
  165.     public menu_handler(client, menu, item)
  166.     {  
  167.         if(Timer >= 0)
  168.         {
  169.             if(!Voted[client] && item != MENU_EXIT) //if didn't vote, count client's vote
  170.             {
  171.                 new data[6], iName[64]
  172.                 new access, callback
  173.                 menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
  174.                 new key = str_to_num(data) - 1
  175.                
  176.                 new szName[32]
  177.                 get_user_name(client, szName, 31)
  178.                
  179.                 ColorChat(0, "^3%s^1 has^4 Voted ^1for^4 %s", szName, g_maps[key])
  180.                 g_szKind[key]++
  181.                
  182.                 Voted[client] = true
  183.             }
  184.             ChangeMaps(client)  //then show again
  185.         }
  186.         else    //vote expired :BB
  187.             show_menu(client,0,"^n",1)
  188.         return PLUGIN_HANDLED
  189.     }  
  190.    
  191.     public countdown2()
  192.     {
  193.         if(Timer >= 0)
  194.         {
  195.             Timer--
  196.             set_task(1.0,"countdown2")
  197.             new players[32], num, id
  198.             get_players(players, num)
  199.             for( new i = 0; i < num; i++ )
  200.             {
  201.                 id = players[i]
  202.                 show_menu(id,0,"^n",1)
  203.                 ChangeMaps(id)
  204.             }
  205.         }
  206.     }  
  207. public Adv_message(){
  208.     ColorChat(0,"Type ^3/nextvote^1 To View The ^4Next Vote Map^1.");
  209.  
  210.    
  211. }  
  212.    
  213.     stock ColorChat(const client, const string[], {Float, Sql, Resul,_}:...)
  214. {
  215.     new msg[ 191 ], players[ 32 ], count = 1;
  216.    
  217.     static len; len = formatex( msg, charsmax(msg), "^4[^3%s^4]^1 ",Tag );
  218.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 );
  219.    
  220.     if( client )  players[ 0 ] = client;
  221.     else    get_players( players,count, "ch" );
  222.    
  223.     for( new i = 0; i < count; i++ )
  224.     {
  225.         if( is_user_connected( players[ i ] ) )
  226.         {
  227.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ),_, players[ i ] );
  228.             write_byte( players[ i ] );
  229.             write_string( msg );
  230.             message_end();
  231.         }
  232.     }
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement