Raised This Month: $51 Target: $400
 12% 

Smart Mapchooser [small vs big maps]


Post New Thread Reply   
 
Thread Tools Display Modes
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 03-22-2015 , 13:54   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #11

The file exists, it has 8 maps in it.

At the voting time, the maps from that file are read but some of them are duplicated, example:

Choose the next map:

1.de_dust2
2.de_dust2
3.de_nuke
4.de_train
5.de_train
__________________
We all live under the same sky but we have different horizons.
bLacK-bLooD is offline
GhostMan
Senior Member
Join Date: Jun 2012
Old 03-22-2015 , 15:48   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #12

I'd love to get the same function with Galileo plugin.
__________________
Hi.
GhostMan is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 03-23-2015 , 09:53   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #13

I still don't know why this happens.

This is the full code:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>

#define SELECTMAPS  5

#define charsof(%1) (sizeof(%1)-1)

new Array:g_mapName;
new 
g_mapNums;

new 
g_nextName[SELECTMAPS]
new 
g_voteCount[SELECTMAPS 2]
new 
g_mapVoteNum
new g_teamScore[2]
new 
g_lastMap[32]

new 
g_coloredMenus
new bool:g_selected false

public plugin_init()
{
    
register_plugin("Nextmap Chooser"AMXX_VERSION_STR"AMXX Dev Team")
    
register_dictionary("mapchooser.txt")
    
register_dictionary("common.txt")
    
    
g_mapName=ArrayCreate(32);
    
    new 
MenuName[64]
    
    
format(MenuName63"%L""en""CHOOSE_NEXTM")
    
register_menucmd(register_menuid(MenuName), (-1^(-1<<(SELECTMAPS+2))), "countVote")
    
register_cvar("amx_extendmap_max""90")
    
register_cvar("amx_extendmap_step""15")

    if (
cstrike_running())
        
register_event("TeamScore""team_score""a")

    
get_localinfo("lastMap"g_lastMap31)
    
set_localinfo("lastMap""")

    
set_task(15.0"voteNextmap"987456""0"b")

    
g_coloredMenus colored_menus()
    
    
}

public 
checkVotes()
{
    new 
0
    
    
for (new 0g_mapVoteNum; ++a)
        if (
g_voteCount[b] < g_voteCount[a])
            
a

    
    
if (g_voteCount[SELECTMAPS] > g_voteCount[b]
        && 
g_voteCount[SELECTMAPS] > g_voteCount[SELECTMAPS+1])
    {
        new 
mapname[32]
        
        
get_mapname(mapname31)
        new 
Float:steptime get_cvar_float("amx_extendmap_step")
        
set_cvar_float("mp_timelimit"get_cvar_float("mp_timelimit") + steptime)
        
ColorChat(0GREEN"[XMAS]^x01 Votarea s-a incheiat. Harta va fi prelungita cu^x04 %.0f^x01 minute."steptime)
        
log_amx("Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes"mapnamesteptime)
        
        return
    }
    
    new 
smap[32]
    if (
g_voteCount[b] && g_voteCount[SELECTMAPS 1] <= g_voteCount[b])
    {
        
ArrayGetString(g_mapNameg_nextName[b], smapcharsof(smap));
        
set_cvar_string("amx_nextmap"smap);
    }

    
    
get_cvar_string("amx_nextmap"smap31)
    
ColorChat(0GREEN"[XMAS]^x01 Votarea s-a incheiat. Urmatoarea harta va fi^x04 %s^x01."smap)
    
log_amx("Vote: Voting for the nextmap finished. The nextmap will be %s"smap)
}

public 
countVote(idkey)
{
    if (
get_cvar_float("amx_vote_answers"))
    {
        new 
name[32]
        
get_user_name(idname31)
        
        if (
key == SELECTMAPS)
            
ColorChat(0GREEN"%s^x01 a ales prelungirea hartii"name)
        else if (
key SELECTMAPS)
        {
            new 
map[32];
            
ArrayGetString(g_mapNameg_nextName[key], mapcharsof(map));
            
ColorChat(0GREEN"%s^x01 a ales^x04 %s"namemap);
        }
    }
    ++
g_voteCount[key]
    
    return 
PLUGIN_HANDLED
}

bool:isInMenu(id)
{
    for (new 
0g_mapVoteNum; ++a)
        if (
id == g_nextName[a])
            return 
true
    
return false
}

public 
voteNextmap()
{
    new 
winlimit get_cvar_num("mp_winlimit")
    new 
maxrounds get_cvar_num("mp_maxrounds")

    new 
players;
    
players get_playersnum( );

    new 
maps_ini_file[64]

    
get_configsdir(maps_ini_file63);

    if ( 
players 10 )
    {
        
format(maps_ini_file63"%s/maps_small.ini"maps_ini_file);
        
log_amx("Loaded the small ini file.");
    }
    else
    {
        
format(maps_ini_file63"%s/maps_big.ini"maps_ini_file);
        
log_amx("Loaded the big ini file.");
    }
    
    if (!
file_exists(maps_ini_file))
        
get_cvar_string("mapcyclefile"maps_ini_file63)
        
log_amx("Loaded the standard mapcycle.txt");
    if (
loadSettings(maps_ini_file))
    {
        new 
timeleft get_timeleft()
        
        if (
timeleft || timeleft 299)
        {
            
g_selected false
            
return
        }

        if (
g_selected)
            return

        
g_selected true
        
        
new menu[512], amkeys = (1<<SELECTMAPS 1)

        new 
pos format(menu511g_coloredMenus "\r%L:\w^n^n" "%L:^n^n"LANG_SERVER"CHOOSE_NEXTM")
        new 
dmax = (g_mapNums SELECTMAPS) ? SELECTMAPS g_mapNums
        
        
for (g_mapVoteNum 0g_mapVoteNum dmax; ++g_mapVoteNum)
        {
            
random_num(0g_mapNums 1)
            
            while (
isInMenu(a))
                if (++
>= g_mapNums0
            
            g_nextName
[g_mapVoteNum] = a
            pos 
+= format(menu[pos], 511"\r%d. \w%a^n"g_mapVoteNum 1ArrayGetStringHandle(g_mapNamea));
            
mkeys |= (1<<g_mapVoteNum)
            
g_voteCount[g_mapVoteNum] = 0
        
}
        
        
menu[pos++] = '^n'
        
g_voteCount[SELECTMAPS] = 0
        g_voteCount
[SELECTMAPS 1] = 0
        
        
new mapname[32]
        
get_mapname(mapname31)

        if ((
winlimit maxrounds) == && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max")))
        {
            
pos += format(menu[pos], 511"\r%d. \w%L^n"SELECTMAPS 1LANG_SERVER"EXTED_MAP"mapname)
            
mkeys |= (1<<SELECTMAPS)
        }

        
format(menu[pos], 511"\r%d. \w%L"SELECTMAPS+2LANG_SERVER"NONE")
        new 
MenuName[64]
        
        
format(MenuName63"%L""en""CHOOSE_NEXTM")
        
show_menu(0mkeysmenu15MenuName)
        
set_task(15.0"checkVotes")
        
client_cmd(0"spk Gman/Gman_Choose2")
        
log_amx("Vote: Voting for the nextmap started")
    }
}
stock bool:ValidMap(mapname[])
{
    if ( 
is_map_valid(mapname) )
    {
        return 
true;
    }
    
// If the is_map_valid check failed, check the end of the string
    
new len strlen(mapname) - 4;
    
    
// The mapname was too short to possibly house the .bsp extension
    
if (len 0)
    {
        return 
false;
    }
    if ( 
equali(mapname[len], ".bsp") )
    {
        
// If the ending was .bsp, then cut it off.
        // the string is byref'ed, so this copies back to the loaded text.
        
mapname[len] = '^0';
        
        
// recheck
        
if ( is_map_valid(mapname) )
        {
            return 
true;
        }
    }
    
    return 
false;
}

loadSettings(filename[])
{
    if (!
file_exists(filename))
        return 
0

    
new szText[32]
    new 
currentMap[32]
    
    new 
buff[256];
    
    
get_mapname(currentMap31)

    new 
fp=fopen(filename,"r");
    
    while (!
feof(fp))
    {
        
buff[0]='^0';
        
szText[0]='^0';
        
        
fgets(fpbuffcharsof(buff));
        
        
parse(buffszTextcharsof(szText));
        
        
        if (
szText[0] != ';' &&
            
ValidMap(szText) &&
            !
equali(szTextg_lastMap) &&
            !
equali(szTextcurrentMap))
        {
            
ArrayPushString(g_mapNameszText);
            ++
g_mapNums;
        }
        
    }
    
    
fclose(fp);

    return 
g_mapNums
}

public 
team_score()
{
    new 
team[2]
    
    
read_data(1team1)
    
g_teamScore[(team[0]=='C') ? 1] = read_data(2)
}

public 
plugin_end()
{
    new 
current_map[32]

    
get_mapname(current_map31)
    
set_localinfo("lastMap"current_map)

Edit: Everything happens in voteNextmap() function.
__________________
We all live under the same sky but we have different horizons.

Last edited by bLacK-bLooD; 03-23-2015 at 10:06.
bLacK-bLooD is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-23-2015 , 12:20   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #14

Let's take it step by step, since you are a bit confused.

About:
Quote:
For some reason the log_amx outputs both "Loaded the small ini file." and "Loaded the standard mapcycle.txt", as if the maps_small.ini does not exist and as a backup it loads the standard mapcycle.txt
PHP Code:
if (!file_exists(maps_ini_file))
        
get_cvar_string("mapcyclefile"maps_ini_file63)
        
log_amx("Loaded the standard mapcycle.txt"); 
Only the first instruction is inside the if check, log_amx is outside it. You can aboid "{ }" only when you have a singe instruction inside if check, but here you have too.

PHP Code:
if (!file_exists(maps_ini_file))
{
    
get_cvar_string("mapcyclefile"maps_ini_file63)
    
log_amx("Loaded the standard mapcycle.txt");

I've not changed important things, just added "{ }" and maybe something more, I don't remember, but now it choose the right file for the ammount of players.
PHP Code:
public voteNextmap()
{
    new 
winlimit get_cvar_num("mp_winlimit")
    new 
maxrounds get_cvar_num("mp_maxrounds")

    new 
players;
    
players get_playersnum( );

    new 
maps_ini_file[64]

    
get_configsdir(maps_ini_file63);
    
server_print("Found: %s"maps_ini_file)
    if ( 
players 10 )
    {
        
format(maps_ini_file63"%s/maps_small.ini"maps_ini_file);
        
log_amx("Loaded the small ini file: %s"maps_ini_file);
    }
    else
    {
        
format(maps_ini_file63"%s/maps_big.ini"maps_ini_file);
        
log_amx("Loaded the big ini file: %s"maps_ini_file);
    }

    if (!
file_exists(maps_ini_file))
    {
        
get_cvar_string("mapcyclefile"maps_ini_file63)
        
log_amx("Loaded the standard mapcycle.txt");
    }
    if (
loadSettings(maps_ini_file))
    {
        new 
timeleft get_timeleft()
        
        if (
timeleft || timeleft 299)
        {
            
g_selected false
            
return
        }

        if (
g_selected)
        return

        
g_selected true
        
        
new menu[512], amkeys = (1<<SELECTMAPS 1)

        new 
pos format(menu511g_coloredMenus "\r%L:\w^n^n" "%L:^n^n"LANG_SERVER"CHOOSE_NEXTM")
        new 
dmax = (g_mapNums SELECTMAPS) ? SELECTMAPS g_mapNums
        
        
for (g_mapVoteNum 0g_mapVoteNum dmax; ++g_mapVoteNum)
        {
            
random_num(0g_mapNums 1)
            
            while (
isInMenu(a))
            if (++
>= g_mapNums0
            
            g_nextName
[g_mapVoteNum] = a
            pos 
+= format(menu[pos], 511"\r%d. \w%a^n"g_mapVoteNum 1ArrayGetStringHandle(g_mapNamea));
            
mkeys |= (1<<g_mapVoteNum)
            
g_voteCount[g_mapVoteNum] = 0
        
}
        
        
menu[pos++] = '^n'
        
g_voteCount[SELECTMAPS] = 0
        g_voteCount
[SELECTMAPS 1] = 0
        
        
new mapname[32]
        
get_mapname(mapname31)

        if ((
winlimit maxrounds) == && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max")))
        {
            
pos += format(menu[pos], 511"\r%d. \w%L^n"SELECTMAPS 1LANG_SERVER"EXTED_MAP"mapname)
            
mkeys |= (1<<SELECTMAPS)
        }

        
format(menu[pos], 511"\r%d. \w%L"SELECTMAPS+2LANG_SERVER"NONE")
        new 
MenuName[64]
        
        
format(MenuName63"%L""en""CHOOSE_NEXTM")
        
show_menu(0mkeysmenu15MenuName)
        
set_task(15.0"checkVotes")
        
client_cmd(0"spk Gman/Gman_Choose2")
        
log_amx("Vote: Voting for the nextmap started")
    }

__________________

Last edited by HamletEagle; 03-23-2015 at 12:20.
HamletEagle is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 03-23-2015 , 13:58   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #15

Oh, okay, that was a stupid mistake.

Everythings works fine now except for the duplicate maps. I still get the same map two times in the vote

Example:

1.de_dust2
2.fy_snow
3.fy_snow
4.de_inferno
5.de_nuke

It doesn't happen necessarily in this order but at every map vote, one or more maps are duplicated.
__________________
We all live under the same sky but we have different horizons.
bLacK-bLooD is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 04-09-2015 , 13:07   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #16

BUMP

Anyone knows why I get duplicate maps at vote time?
__________________
We all live under the same sky but we have different horizons.
bLacK-bLooD is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-09-2015 , 13:26   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #17

Start debuging your code and you will find. Output every step where string-arrays get filled with a value, any loop that you make.
__________________
HamletEagle is offline
bLacK-bLooD
AlliedModders Donor
Join Date: Jun 2008
Old 04-18-2015 , 03:55   Re: Smart Mapchooser [small vs big maps]
Reply With Quote #18

I'm back with answers, sort of. I figured out the problem is in the loadSettings() function since it's the only place where the array gets pushed.

PHP Code:
loadSettings(filename[])
{
    if (!
file_exists(filename))
        return 
0

    
new szText[32]
    new 
currentMap[32]
    
    new 
buff[256];
    
    
get_mapname(currentMap31)

    new 
fp=fopen(filename,"r");
    
    while (!
feof(fp))
    {
        
buff[0]='^0';
        
szText[0]='^0';
        
        
fgets(fpbuffcharsof(buff));
        
        
parse(buffszTextcharsof(szText));
        
        
        if (
szText[0] != ';' &&
            
ValidMap(szText) &&
            !
equali(szTextg_lastMap) &&
            !
equali(szTextcurrentMap))
        {
            
ArrayPushString(g_mapNameszText); //the problem I believe is here
            
++g_mapNums;
        }
        
    }
    
    
fclose(fp);

    return 
g_mapNums

However I can't see any problems, or I'm not looking where I am supposed to.

Any help please?
__________________
We all live under the same sky but we have different horizons.
bLacK-bLooD 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 18:20.


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