Raised This Month: $ Target: $400
 0% 

Custom Vote


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 04-20-2012 , 04:51   Custom Vote
Reply With Quote #1

Hi..

So what am trying to do is make a simple map vote , ill show my code first and then start explaining the problem

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Test"
#define VERSION "1.0"
#define AUTHOR "Epic"

new g_Map1[33], g_Map2[33];
new 
g_Vote1[33], g_Vote2[33];
new 
bool:g_VoteStarted;
new 
g_maxplayersg_msgSayText;
static const 
Team[] = "^x03"
static const Green[] = "^x04"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""VoteMap")
    
g_maxplayers get_maxplayers()
    
g_msgSayText get_user_msgid("SayText")

}

public 
VoteMap(id)
{
    
g_VoteStarted true
    
new menuitem1[64], menuitem2[64];
    new 
menu menu_create("Choose 2 Maps:""VoteMap_Handler")
    if(
g_Map1[id])
    {
        
format(menuitem1charsmax(menuitem1), "%s"g_Map1)
        
menu_additem(menumenuitem1"1"0)
    }
    else
    {
        
menu_additem(menu"Select Map1""1"0)
    }
    if(
g_Map2[id])
    {
        
format(menuitem2charsmax(menuitem2), "%s"g_Map2)
        
menu_additem(menumenuitem2"2"0)
    }
    else
    {
        
menu_additem(menu"Select Map2""2"0)
    }
    if(
g_Map1[id] && g_Map2[id])
    {
        
menu_addblank(menu3)
        
menu_additem(menu"Start Vote""4"0)
    }
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
VoteMap_Handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        
g_Map1[id] = 0
        g_Map2
[id] = 0
        g_VoteStarted 
false
        
return PLUGIN_HANDLED;
        
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1:
        {
            
ShowMenu1(id)
        }
        case 
2:
        {
            
ShowMenu2(id)
        }
        case 
4:
        {
            for(new 
1<= g_maxplayersi++)
            {
                if(
is_user_connected(i))
                {
                    new 
szName[33]
                    
g_Vote1[id] = 0
                    g_Vote2
[id] = 0
                    StartVote
(i)
                    
get_user_name(idszNamecharsmax(szName))
                    
ChatColor(i"%s[AMXX] %s[%s] %shas Started a vote"GreenTeamszNameGreen)
                    
set_task(10.0"EndVote");
                    return 
PLUGIN_CONTINUE
                
}
            }
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE
}

public 
ShowMenu1(id)
{
    new 
menu menu_create("Choose first Map:""Menu1_Handler")
    
    
menu_additem(menu"de_dust2""1"0);
    
menu_additem(menu"de_dust""2"0);
    
menu_additem(menu"de_inferno""3"0);
    
menu_additem(menu"de_nuke32""4"0)
    
menu_additem(menu"awp_aztecwave""5"0);
    
menu_additem(menu"de_aztec""6"0);
    
menu_additem(menu"de_train32""7"0);
    
menu_additem(menu"35hp_2""8"0)
    
menu_additem(menu"awp_india""9"0);
    
menu_additem(menu"cs_italy32""10"0);
    
menu_additem(menu"scoutzknivez""11"0);
    
menu_additem(menu"cs_militia""12"0)
    
menu_additem(menu"scoutmap""13"0)
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
Menu1_Handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
VoteMap(id)
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1format(g_Map1charsmax(g_Map1), "%s"" de_dust2")
        case 
2format(g_Map1charsmax(g_Map1), "%s"" de_dust")
        case 
3format(g_Map1charsmax(g_Map1), "%s"" de_inferno")
        case 
4format(g_Map1charsmax(g_Map1), "%s"" de_nuke32")
        case 
5format(g_Map1charsmax(g_Map1), "%s"" awp_aztecwave")
        case 
6format(g_Map1charsmax(g_Map1), "%s"" de_aztec")
        case 
7format(g_Map1charsmax(g_Map1), "%s"" de_train32")
        case 
8format(g_Map1charsmax(g_Map1), "%s"" 35hp_2")
        case 
9format(g_Map1charsmax(g_Map1), "%s"" awp_india")
        case 
10format(g_Map1charsmax(g_Map1), "%s"" cs_italy32")
        case 
11format(g_Map1charsmax(g_Map1), "%s"" scoutzknivez")
        case 
12format(g_Map1charsmax(g_Map1), "%s"" cs_militia")
        case 
13format(g_Map1charsmax(g_Map1), "%s"" scoutmap")
    }
    
VoteMap(id)
}

public 
ShowMenu2(id)
{
    new 
menu menu_create("Choose a Map:""Menu2_Handler")
    
menu_additem(menu"de_dust2""1"0);
    
menu_additem(menu"de_dust""2"0);
    
menu_additem(menu"de_inferno""3"0);
    
menu_additem(menu"de_nuke32""4"0)
    
menu_additem(menu"awp_aztecwave""5"0);
    
menu_additem(menu"de_aztec""6"0);
    
menu_additem(menu"de_train32""7"0);
    
menu_additem(menu"35hp_2""8"0)
    
menu_additem(menu"awp_india""9"0);
    
menu_additem(menu"cs_italy32""10"0);
    
menu_additem(menu"scoutzknivez""11"0);
    
menu_additem(menu"cs_militia""12"0)
    
menu_additem(menu"scoutmap""13"0)
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
Menu2_Handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
VoteMap(id)
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        
        case 
1format(g_Map2charsmax(g_Map2), "%s"" de_dust2")
        case 
2format(g_Map2charsmax(g_Map2), "%s"" de_dust")
        case 
3format(g_Map2charsmax(g_Map2), "%s"" de_inferno")
        case 
4format(g_Map2charsmax(g_Map2), "%s"" de_nuke32")
        case 
5format(g_Map2charsmax(g_Map2), "%s"" awp_aztecwave")
        case 
6format(g_Map2charsmax(g_Map2), "%s"" de_aztec")
        case 
7format(g_Map2charsmax(g_Map2), "%s"" de_train32")
        case 
8format(g_Map2charsmax(g_Map2), "%s"" 35hp_2")
        case 
9format(g_Map2charsmax(g_Map2), "%s"" awp_india")
        case 
10format(g_Map2charsmax(g_Map2), "%s"" cs_italy32")
        case 
11format(g_Map2charsmax(g_Map2), "%s"" scoutzknivez")
        case 
12format(g_Map2charsmax(g_Map2), "%s"" cs_militia")
        case 
13format(g_Map2charsmax(g_Map2), "%s"" scoutmap")
    }
    
VoteMap(id)
}

public 
StartVote(id)
{
    new 
menuitem1[64], menuitem2[64];
    new 
menu menu_create("Which map do you want?""Vote_Handler")
    
    
format(menuitem1charsmax(menuitem1), "%s"g_Map1[id])
    
format(menuitem2charsmax(menuitem2), "%s"g_Map2[id])
    
    
menu_additem(menumenuitem1"1"0);
    
menu_additem(menumenuitem2"2"0);
    
menu_addblank(menu3)
    
menu_additem(menu"None""4"0)
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
Vote_Handler(idmenuitem)
{
    if( 
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    new 
data[6], iName[64], szName[33];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1
        {
            if(
g_VoteStarted)
            {
                
g_Vote1[id] = g_Vote1[id] + 1
                get_user_name
(idszNamecharsmax(szName))
                
ChatColor(0"%s[AMXX] %s[%s] %shas chosen %s[%s]"GreenTeamszNameGreenTeamg_Map1[id])
            }
            else
            {
                
ChatColor(id"%s[AMXX] Voting time is already over"Green)
            }
        }
        case 
2:
        {
            if(
g_VoteStarted)
            {
                
g_Vote2[id] = g_Vote2[id] + 1
                get_user_name
(idszNamecharsmax(szName))
                
ChatColor(0"%s[AMXX] %s[%s] %shas chosen %s[%s]"GreenTeamszNameGreenTeamg_Map2[id])
            }
            else
            {
                
ChatColor(id"%s[AMXX] Voting time is already over"Green)
            }
        }
        case 
4menu_destroy(id)
    }
    return 
PLUGIN_CONTINUE
}

public 
EndVote(id)
{
    if(
g_Vote1[id] > g_Vote2[id])
    {
        
ChatColor(id"%s[AMXX] Map: %s[%s] %sreceived most Votes: %s[%i]"GreenTeamg_Map1[id], GreenTeamg_Vote1[id])
    }
    else if(
g_Vote2[id] > g_Vote1[id])
    {
        
ChatColor(id"%s[AMXX][VIP] Map: %s[%s] %sreceived most Votes: %s[%i]"GreenTeamg_Map2[id], GreenTeamg_Vote2[id])
    }
    else
    {
        
ChatColor(id"%s[AMXX][VIP] The vote tied at %s[%i] %svotes each"GreenTeamg_Vote1[id], Green)
    }
    
g_Vote1[id] = 0
    g_Vote2
[id] = 0
    g_Map1
[id] = 0
    g_Map2
[id] = 0
    g_VoteStarted 
false
}

stock ChatColor(const id, const input[], any:...) 
{
    new 
count 1players[32]
    static 
msg[191]
    
vformat(msg190input3)
    
    
replace_all(msg190"!g""^4")
    
replace_all(msg190"!y""^1")
    
replace_all(msg190"!t""^3")
    
    if (
idplayers[0] = id; else get_players(playerscount"ch")
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLE,g_msgSayText,_players[i])
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }

I know that my code can be easily optimized , i could even use enums ... but i made it like this for the time being ,

Problem : When i try and select a map , most of the time , the map doesnt get added to the main menu , some times it gets added but when i vote it goes all crazy .... , like "de_dust2" becomes "ust2"
Any help would be appreciated

Last edited by EpicMonkey; 04-20-2012 at 04:55.
EpicMonkey is offline
 



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 07:42.


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