Raised This Month: $ Target: $400
 0% 

[help] votemaps


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-14-2014 , 16:46   Re: [help] votemaps
Reply With Quote #9

Try this:

PHP Code:
#include <amxmodx>

#define TASKID 1337
#define MAX_MAPS 32

new g_iMapCount;
new 
g_sMaps[MAX_MAPS][32];
new 
g_iMapVotes[MAX_MAPS];
new 
g_iMenuMap;

new 
g_pRounds;
new 
g_pRandom;
new 
g_pMapCycle;

new 
g_iRounds;


public 
plugin_init()
{
    
register_plugin("Vote Map",AMXX_VERSION_STR,"SmileY");
    
    
g_pRounds     register_cvar("amxx_votemap_rounds","3");
    
g_pRandom     register_cvar("amxx_votemap_random","1");
    
g_pMapCycle     get_cvar_pointer("mapcyclefile");
    
    
register_event("SendAudio","ev_SendAudio","a","2=%!MRAD_terwin","2=%!MRAD_ctwin");
}

public 
plugin_cfg()
{
    new 
sPatch[40];
    
get_localinfo("amxx_configsdir",sPatch,charsmax(sPatch));

    
format(sPatch,charsmax(sPatch),"%s/custom_maps.ini",sPatch);

    if(!
LoadMaps(sPatch))
    {
        
get_pcvar_string(g_pMapCycle,sPatch,charsmax(sPatch));
        
        
LoadMaps(sPatch);
    }
}

public 
LoadMaps(const sPatch[])
{
    if(
file_exists(sPatch))
    {
        new 
iFile fopen(sPatch,"rb");
        
        new 
sMap[32],iNum[10];
        
        new 
sCurrent[32];
        
get_mapname(sCurrent,charsmax(sCurrent));
        
        
g_iMenuMap menu_create("Vote Map:","MenuHandle",1);
        
menu_setprop(g_iMenuMap,MPROP_EXIT,MEXIT_NEVER);
        
        while(!
feof(iFile) && (g_iMapCount MAX_MAPS))
        {
            
fgets(iFile,sMap,charsmax(sMap));
            
trim(sMap);
            
            if(
sMap[0] != ';' && is_map_valid(sMap) && !equali(sMap,sCurrent))
            {
                
copy(g_sMaps[g_iMapCount],charsmax(g_sMaps[]),sMap);
                    
                
num_to_str(g_iMapCount,iNum,charsmax(iNum));
                
menu_additem(g_iMenuMap,g_sMaps[g_iMapCount],iNum);
            
                
g_iMapCount++;
            }
        }
        
        
fclose(iFile);
        
        return 
g_iMapCount;
    }
    
    return 
0;
}

public 
ev_SendAudio()
{
    new 
iRounds get_pcvar_num(g_pRounds);
    
    if(
iRounds && !task_exists(TASKID))
    {
        
g_iRounds++;
        
        if(
g_iRounds >= iRounds)
        {
            
StartVoteMap();
        }
        else
        {
            new 
iLack = (iRounds g_iRounds);
            
            if(
iLack 1)
            {
                
client_print_color
                
(
                    
0,
                    
print_team_red,
                    
"^4[AMXX] ^3%i ^1Rounds remaining to start the ^3Vote Map.",
                    
iLack
                
);
            }
            else
            {
                
client_print_color
                
(
                    
0,
                    
print_team_red,
                    
"^4[AMXX] ^3WARNING: LAST ROUND TO VOTE FOR NEW MAP!"
                
);
            }
        }
    }
    
/* else server_print("[AMXX] Vote Map Disabled."); */
}

public 
StartVoteMap()
{
    
arrayset(g_iMapVotes,0,sizeof(g_iMapVotes));
    
    new 
iPlayers[32],iNum;
    
get_players(iPlayers,iNum,"ch");
    
    for(new 
i;iNum;i++)
    {
        
menu_display(iPlayers[i],g_iMenuMap);
    }
    
    
set_task(15.0,"VoteMapEnd",TASKID);
    
    
client_print_color(0,print_team_blue,"^4[AMXX] ^3Starting Vote to Next Map...");
}

public 
MenuHandle(id,iMenu,iKey)
{
    if(
iKey != MENU_EXIT)
    {
        new 
sInfo[3],sKey[32],iAccess,iBack;
        
menu_item_getinfo(iMenu,iKey,iAccess,sInfo,charsmax(sInfo),sKey,charsmax(sKey),iBack);
        
        
g_iMapVotes[str_to_num(sInfo)]++;
        
        new 
sName[32];
        
get_user_name(id,sName,charsmax(sName));
        
        
client_print_color(0,print_team_grey,"^4[AMXX] ^3%s ^1choosed ^3%s",sName,sKey);
    }
    
    return 
PLUGIN_HANDLED;
}

public 
VoteMapEnd()
{
    
show_menu(0,0,"^n",1);
    new 
iWinner,iWinnerVotes,iVotes;

    for(new 
i;g_iMapCount;i++)
    {
        
iVotes g_iMapVotes[i];
    
        if(
iVotes >= iWinnerVotes)
        {
            
iWinner i;
            
iWinnerVotes iVotes;
        }
        else if(
iVotes == iWinnerVotes)
        {
            if(
random_num(0,1))
            {
                
iWinner i;
                
iWinnerVotes iVotes;
            }
        }
    }
    
    if(
g_iMapVotes[iWinner])
    {
        
client_print_color
        
(
            
0,
            
print_team_blue,
            
"^4[AMXX] ^1Changing Map to ^3%s...",
            
g_sMaps[iWinner]
        );
    }
    else
    {
        if(
get_pcvar_num(g_pRandom))
        {
            while(!
is_map_valid(g_sMaps[iWinner]))
            {
                
iWinner random(g_iMapCount);
            }
            
            
client_print_color
            
(
                
0,
                
print_team_grey,
                
"^4[AMXX] ^3%s ^1Has been choosen: No one voted for a valid map.",
                
g_sMaps[iWinner]
            );
        }
        else
        {
            
set_task(5.0,"StartVoteMap",TASKID);
            
            
client_print_color
            
(
                
0,
                
print_team_grey,
                
"^4[AMXX] ^3Restarting Vote Map: No one voted for a valid map."
            
);
        }
    }
    
    
set_task(5.0,"ChangeMap",TASKID,g_sMaps[iWinner],sizeof(g_sMaps[]));
}

public 
ChangeMap(const sMap[])
{
    
server_cmd("changelevel ^"%s^"",sMap);

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 04-14-2014 at 16:48. Reason: show_menu(0,0,"^n",1);
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode