Raised This Month: $ Target: $400
 0% 

Voting menu won't display.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 07-20-2011 , 09:57   Voting menu won't display.
Reply With Quote #1

Hey guys.
I made a PUG mode and a part of my PUG mode is the map voting, for some wierd reason when it reaches to this part of code (Public StartVote()) (and im sure it reaches to this part of code cuz i did before that it will print something if it reaches there.) it does nothing, and it doesn't display the menu it should display. Anybody finds bugs in this?

PHP Code:
/* Global Variables that are found in this code */

new gVoteMenu;
new 
gVotes[5];
new 
maps_ini_file[64]
new 
mapscounter
new mapsavailable[30][20]
new 
mapschosen[4][20]
new 
donemaps
new didgetmap

/* Global Variables .... */
public StartVote()
{
        if (
didgetmap == 0)
        {
                 
set_task(0.1"getmaps")
        }
    new 
rnd
    
    
while (donemaps != 4)
    {
        
rnd random(mapscounter)
        
        
copy(mapschosen[donemaps++], 19mapsavailable[rnd])
        
        
mapsavailable[rnd] = mapsavailable[--mapscounter]
    }        
    
    
gVoteMenu menu_create("\rChange map?""votemap");
    
    
    
menu_additem(gVoteMenumapschosen[0], "0"0)
    
menu_additem(gVoteMenumapschosen[1], "1"0)
    
menu_additem(gVoteMenumapschosen[2], "2"0)
    
menu_additem(gVoteMenumapschosen[3], "3"0)
    
menu_additem(gVoteMenu"\nExtend current map""4"0)
    
    new 
players[32], pnumtempid;
    
    
get_players(playerspnum"ch");

    for( new 
ii<pnumi++ )
    {
        
tempid players[i];
        
client_print(tempidprint_chat"%s Please vote for the map you'd like to play in."PREFIX)
        
menu_display(tempidgVoteMenu);
    }

    
set_task(10.0"EndVote"); 
    return 
PLUGIN_HANDLED;

 
 
public 
votemap(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
voteid str_to_num(data);
    
    
gVotes[voteid]++;
    return 
PLUGIN_HANDLED;
}

public 
getmaps()
{
    
get_configsdir(maps_ini_file63);
    
format(maps_ini_file63"%s/maps.ini"maps_ini_file);
    
    new 
mapsfile fopen(maps_ini_file"r")
    new 
linefortest[50]
    new 
maptoadd[25]
    
    while (!
feof(mapsfile))
    {
        
fgets(mapsfilelinefortest24)
        
mapscounter++
    }
    
    for (new 
zz<mapscounter z++)
    {
        
fgets(mapsfilemaptoadd24)
        
copy(mapsavailable[z], 24maptoadd)
    }
    
    
didgetmap++
    
set_task(0.1"StartVote")

Diegorkable is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-20-2011 , 10:06   Re: Voting menu won't display.
Reply With Quote #2

PHP Code:
public StartVote()
{
    if (
didgetmap == 0)
    {
        
getmaps()
    }
    new 
rnd
    
    
while (donemaps != && mapscounter 0)
    {
        
rnd random(mapscounter)
        
        
copy(mapschosen[donemaps++], 19mapsavailable[rnd])
        
        
mapsavailable[rnd] = mapsavailable[--mapscounter]
    }        
    
    
gVoteMenu menu_create("\rChange map?""votemap");
    
    new 
num[11]
    for(new 
0donemapsi++)
    {
        
num_to_str(inum10)
        
menu_additem(gVoteMenumapschosen[i], num0)
    }
    
menu_additem(gVoteMenu"\nExtend current map""4"0)
    
    new 
players[32], pnumtempid;
    
    
get_players(playerspnum"ch");
    
    for( new 
ii<pnumi++ )
    {
        
tempid players[i];
        
client_print(tempidprint_chat"%s Please vote for the map you'd like to play in."PREFIX)
        
menu_display(tempidgVoteMenu);
    }
    
    
set_task(10.0"EndVote"); 
    return 
PLUGIN_HANDLED;
}

public 
getmaps()
{
    
get_configsdir(maps_ini_file63);
    
format(maps_ini_file63"%s/maps.ini"maps_ini_file);
    
    new 
mapsfile fopen(maps_ini_file"r")
    new 
linefortest[50]
    
    while (
mapscounter sizeof(mapsavailable) && !feof(mapsfile))
    {
        
fgets(mapsfilelinefortest49)
        
trim(linefortest)
        
        if (
is_map_valid(linefortest))
        {
            
copy(mapsavailable[mapscounter++], 24linefortest)
        }
    }
    
    
fclose(mapsfile)
    
    
didgetmap++

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-20-2011 , 10:28   Re: Voting menu won't display.
Reply With Quote #3

1. Recursive task loop from getmaps() and StartVote()
2. Changed getmaps() to be direct call to have maps ready for vote
3. Chooses 4 maps while maps are available to be chosen
4. Only add items to the menu that exist
5. Stop loop if maps list is completely filled
6. First loop reads to end of file, second loop would give no results to add to maps list
7. Remove new line character at end of line
8. Only add map if it exists
9. Close file after using it
PHP Code:
public StartVote()
{
    if (
didgetmap == 0)
    {
        
// #1, #2
        
getmaps()
    }
    new 
rnd
    
    
// #3
    
while (donemaps != && mapscounter 0)
    {
        
rnd random(mapscounter)
        
        
copy(mapschosen[donemaps++], 19mapsavailable[rnd])
        
        
mapsavailable[rnd] = mapsavailable[--mapscounter]
    }        
    
    
gVoteMenu menu_create("\rChange map?""votemap");
    
    
// #4
    
new num[11]
    for(new 
0donemapsi++)
    {
        
num_to_str(inum10)
        
menu_additem(gVoteMenumapschosen[i], num0)
    }
    
menu_additem(gVoteMenu"\nExtend current map""4"0)
    
    new 
players[32], pnumtempid;
    
    
get_players(playerspnum"ch");
    
    for( new 
ii<pnumi++ )
    {
        
tempid players[i];
        
client_print(tempidprint_chat"%s Please vote for the map you'd like to play in."PREFIX)
        
menu_display(tempidgVoteMenu);
    }
    
    
set_task(10.0"EndVote"); 
    return 
PLUGIN_HANDLED;
}

public 
getmaps()
{
    
get_configsdir(maps_ini_file63);
    
format(maps_ini_file63"%s/maps.ini"maps_ini_file);
    
    new 
mapsfile fopen(maps_ini_file"r")
    new 
linefortest[50]
    
    
// #5, #6
    
while (mapscounter sizeof(mapsavailable) && !feof(mapsfile))
    {
        
fgets(mapsfilelinefortest49)
        
trim(linefortest// #7
        
        // #8
        
if (is_map_valid(linefortest))
        {
            
copy(mapsavailable[mapscounter++], 24linefortest)
        }
    }
    
    
// #9
    
fclose(mapsfile)
    
    
didgetmap++
    
// #1

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 07-20-2011 , 10:17   Re: Voting menu won't display.
Reply With Quote #4

Thanks, I'll test it now. Can you tell me what you fixed and why did it not work with my code?
Diegorkable is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 07-20-2011 , 10:32   Re: Voting menu won't display.
Reply With Quote #5

Now I have another question.
Your fix works good, but after map vote is done, the server crashes.... I'll send you the public where it goes after ending the vote, tell me why is that..

PHP Code:
/* Global Variable in this code */
new changemapto
/* Global... */

public EndVote()
{
    new 
0;
    new 
0;
    
    while ((
!= 5) && (!= 5))
    {
        if (
gVotes[x] >= gVotes[c])
        {
    
            if ((
== 4) && (== 4))
            {
                
client_print(0print_chat"%s The current map will be extended for this match. Match will start in 10 seconds."PREFIX)
                
set_task(10.0"StartMatch"
                continue;
            }
                    
            else if ((
== 0) && (== 4))
            {
                
client_print(0print_chat"%s The map will be changed within 10 seconds. The map that was chosen is: %s."PREFIXmapschosen[0])
                
changemapto 0
                set_task
(10.0"ChangeMap")
                continue;
            }
                
            else if ((
== 1) && (== 4))
            {
                
client_print(0print_chat"%s The map will be changed within 10 seconds. The map that was chosen is: %s."PREFIXmapschosen[1])
                
changemapto 1
                set_task
(10.0"ChangeMap")
                continue;
            }
                
            else if ((
== 2) && (== 4))
            {
                
client_print(0print_chat"%s The map will be changed within 10 seconds. The map that was chosen is: %s."PREFIXmapschosen[2])
                
changemapto 2
                set_task
(10.0"ChangeMap")
                continue;
            }
                
            else if ((
== 3) && (== 4))
            {
                
client_print(0print_chat"%s The map will be changed within 10 seconds. The map that was chosen is: %s."PREFIXmapschosen[3])
                
changemapto 3
                set_task
(10.0"ChangeMap")
                continue;
            }
            
c++
        }
        
        else
        {
            
x++
            
0
        
}
    }        
}

public 
ChangeMap()
{
    new 
maptochangeto[25]
    
    
copy(maptochangeto24mapschosen[changemapto])
    
server_cmd("changelevel %s"maptochangeto)


Last edited by Diegorkable; 07-20-2011 at 10:39.
Diegorkable is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-20-2011 , 11:33   Re: Voting menu won't display.
Reply With Quote #6

That's an ugly loop.

PHP Code:
public EndVote()
{
    new 
best 0;
    for(new 
1sizeof(gVotes); i++)
    {
        if(
gVotes[i] > gVotes[best])
            
best i;
    }
    
    if(
best == 4)
    {
        
client_print(0print_chat"%s The current map will be extended for this match. Match will start in 10 seconds."PREFIX);
        
set_task(10.0"StartMatch");
    }
    else
    {
        
client_print(0print_chat"%s The map will be changed within 10 seconds. The map that was chosen is: %s."PREFIXmapschosen[best]);
        
changemapto best;
        
set_task(10.0"ChangeMap");
    }

Anyway, those "continue" statements are causing an infinite loop (server crash) and should be "break".
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 07-20-2011 , 11:57   Re: Voting menu won't display.
Reply With Quote #7

Thanks that works too, thanks alot Exolent

Now I have one more question. I used an .ini file that the pug will read from to spot if its after map vote or not, so after plugin_precache it wont do "type .rdy" again even if it was already and its after vote map, so it'll spot that if there's a specific written character I set, it'll start teams vote. The problem is, The teams vote doesnt work (teams vote = how the teams will be organized), I checked console and it says "Vote how you would like the teams to be organized" and then just says "Teams will be kept as they are", like it decides by itself the first option, and it doesnt even display the menu...

Here is the code:

PHP Code:
public TeamsVote()
 {        
    
    
rVoteMenu menu_create("\rHow do you want the teams organized?""votemap");
    
    
    
menu_additem(rVoteMenu"Keep current teams as they are.""0"0)
    
menu_additem(rVoteMenu"Random captains picking their team.""1"0)
    
menu_additem(rVoteMenu"Random teams.""2"0)
    ;
    
    new 
players[32], pnumtempid;
    
    
get_players(playerspnum"ch");

    for( new 
ii<pnumi++ )
    {
        
tempid players[i];
        
client_print(tempidprint_chat"%s Please pick the way you'd like the teams to be organized."PREFIX)
        
menu_display(tempidrVoteMenu0);
    }

    
set_task(10.0"EndTeamsVote");
    return 
PLUGIN_HANDLED;
 }
 
 
public 
voteteams(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
voteid str_to_num(data);
    
    
rVotes[voteid]++;
    return 
PLUGIN_HANDLED;
}
    
public 
EndTeamsVote()
{
    for(new 
xx<3x++)
    {
        for (new 
cc<c++)
        {
            if (
gVotes[x] >= gVotes[c])
            {
                if ((
== 2) && (== 2))
                {
                    
client_print(0print_chat"%s The teams will be kept as they are, match will now start."PREFIX)
                    
set_task(3.0"StartMatch")
                }
                
                else if ((
== 0) && (== 2))
                {
                    
client_print(0print_chat"%s Random Captains will be chosen in 10 seconds."PREFIX)
                    
set_task(10.0"RandomCpt")
                }
                
                else if ((
== 1) && (== 2))
                {
                    
client_print(0print_chat"%s Random teams will be set in 10 seconds."PREFIX)
                    
set_task(10.0"RandomTeams")
                }
                
            }
        }
    }

Diegorkable is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-20-2011 , 12:13   Re: Voting menu won't display.
Reply With Quote #8

PHP Code:
rVotes[voteid]++;
// ...
if (gVotes[x] >= gVotes[c]) 
Notice anything? Also, change that loop to the method I showed in my last post.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-20-2011 , 12:28   Re: Voting menu won't display.
Reply With Quote #9

Your other problem is here:

PHP Code:
rVoteMenu menu_create("\rHow do you want the teams organized?""votemap");

//..

public voteteams(idmenuitem
What doesn't match?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 07-20-2011 , 12:15   Re: Voting menu won't display.
Reply With Quote #10

Yeah I know the EndTeamsVote public looks ugly, but it doesnt even display a menu of how would you like the teams to be organized and just gives the answer as "teams will be kept as they are, why?
Diegorkable is offline
Reply



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 00:51.


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