Raised This Month: $ Target: $400
 0% 

map


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kooomax
Member
Join Date: Jan 2018
Old 06-26-2023 , 19:53   map
Reply With Quote #1

hello
I wanted to edit the mapmenu plugin i want to add this menu to the winning map

Do you want to change it right now?

Yes, change it now!
Change it just nextmap...
Don't change it!

PHP Code:
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
//     https://alliedmods.net/amxmodx-license

//
// Maps Menu Plugin
//

#include <amxmodx>
#include <amxmisc>

new Array:g_mapName;
new 
g_mapNums
new g_menuPosition[MAX_PLAYERS 1]

new 
g_voteCount[5]

new 
g_voteSelected[MAX_PLAYERS 1][4]
new 
g_voteSelectedNum[MAX_PLAYERS 1]

new 
g_coloredMenus

new g_choosed

public plugin_init()
{
    
register_plugin("Maps Menu"AMXX_VERSION_STR"AMXX Dev Team")
    
register_dictionary("mapsmenu.txt")
    
register_dictionary("common.txt")
    
register_clcmd("amx_mapmenu""cmdMapsMenu"ADMIN_MAP"- displays changelevel menu")
    
register_clcmd("amx_votemapmenu""cmdVoteMapMenu"ADMIN_VOTE"- displays votemap menu")

    
register_menucmd(register_menuid("Changelevel Menu"), 1023"actionMapsMenu")
    
register_menucmd(register_menuid("Which map do you want?"), 527"voteCount")
    
register_menucmd(register_menuid("Change map to"), 527"voteCount")
    
register_menucmd(register_menuid("Votemap Menu"), 1023"actionVoteMapMenu")
    
register_menucmd(register_menuid("The winner: "), 3"actionResult")

    
g_mapName=ArrayCreate(32);
    
    new 
maps_ini_file[64];
    
get_configsdir(maps_ini_filecharsmax(maps_ini_file));
    
format(maps_ini_filecharsmax(maps_ini_file), "%s/maps.ini"maps_ini_file);

    if (!
file_exists(maps_ini_file))
        
get_cvar_string("mapcyclefile"maps_ini_filecharsmax(maps_ini_file));
        
    if (!
file_exists(maps_ini_file))
        
format(maps_ini_filecharsmax(maps_ini_file), "mapcycle.txt")
    
    
load_settings(maps_ini_file)

    
g_coloredMenus colored_menus()
}

public 
autoRefuse()
{
    
log_amx("Vote: %L""en""RESULT_REF")
    
client_print(0print_chat"%L"LANG_PLAYER"RESULT_REF")
}

public 
actionResult(idkey)
{
    
remove_task(4545454)
    
    switch (
key)
    {
        case 
0:
        {
            new 
_modName[10]
            
get_modname(_modNamecharsmax(_modName))
            
            if (!
equal(_modName"zp"))
            {
                
message_begin(MSG_ALLSVC_INTERMISSION)
                
message_end()
            }

            new 
tempMap[32];
            
ArrayGetString(g_mapNameg_choosedtempMapcharsmax(tempMap));
            
            
set_task(2.0"delayedChange"0tempMapstrlen(tempMap) + 1)
            
log_amx("Vote: %L""en""RESULT_ACC")
            
client_print(0print_chat"%L"LANG_PLAYER"RESULT_ACC")
        }
        case 
1autoRefuse()
    }
    
    return 
PLUGIN_HANDLED
}

public 
checkVotes(id)
{
    
id -= 34567
    
new numppl[MAX_PLAYERS], 0
    
    get_players
(pplnum"c")
    if (
num == 0num 1
    g_choosed 
= -1
    
    
for (new 0g_voteSelectedNum[id]; ++i)
        if (
g_voteCount[a] < g_voteCount[i])
            
i

    
new votesNum g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3] + g_voteCount[4]
    new 
iRatio votesNum floatround(get_cvar_float("amx_votemap_ratio") * float(votesNum), floatround_ceil) : 1
    
new iResult g_voteCount[a]

    if (
iResult >= iRatio)
    {
        
g_choosed g_voteSelected[id][a]
        new 
tempMap[32];
        
ArrayGetString(g_mapNameg_choosedtempMapcharsmax(tempMap));
        
client_print(0print_chat"%L %s"LANG_PLAYER"VOTE_SUCCESS"tempMap);
        
log_amx("Vote: %L %s""en""VOTE_SUCCESS"tempMap);
    }
    
    if (
g_choosed != -1)
    {
        if (
is_user_connected(id))
        {
            new 
menuBody[512]
            new 
tempMap[32];
            
ArrayGetString(g_mapNameg_choosedtempMapcharsmax(tempMap));
            new 
len format(menuBodycharsmax(menuBody), g_coloredMenus "\y%L: \w%s^n^n" "%L: %s^n^n"id"THE_WINNER"tempMap)
            
            
len += format(menuBody[len], charsmax(menuBody) - leng_coloredMenus "\y%L^n\w" "%L^n"id"WANT_CONT")
            
format(menuBody[len], charsmax(menuBody) - len"^n1. %L^n2. %L"id"YES"id"NO")

            
show_menu(id0x03menuBody10"The winner: ")
            
set_task(10.0"autoRefuse"4545454)
        } else {
            new 
_modName[10]
            
get_modname(_modNamecharsmax(_modName))
            
            if (!
equal(_modName"zp"))
            {
                
message_begin(MSG_ALLSVC_INTERMISSION)
                
message_end()
            }
            new 
tempMap[32];
            
ArrayGetString(g_mapNameg_choosedtempMapcharsmax(tempMap));
            
set_task(2.0"delayedChange"0tempMapstrlen(tempMap) + 1)
        }
    } else {
        
client_print(0print_chat"%L"LANG_PLAYER"VOTE_FAILED")
        
log_amx("Vote: %L""en""VOTE_FAILED")
    }
    
    
remove_task(34567 id)
}

public 
voteCount(idkey)
{
    if (
key 3)
    {
        
client_print(0print_chat"%L"LANG_PLAYER"VOT_CANC")
        
remove_task(34567 id)
        
set_cvar_float("amx_last_voting"get_gametime())
        
log_amx("Vote: Cancel vote session")
        
        return 
PLUGIN_HANDLED
    
}
    
    if (
get_cvar_float("amx_vote_answers"))
    {
        new 
name[MAX_NAME_LENGTH]
        
        
get_user_name(idnamecharsmax(name))
        
client_print(0print_chat"%L"LANG_PLAYER"X_VOTED_FOR"namekey 1)
    }
    
    ++
g_voteCount[key]
    
    return 
PLUGIN_HANDLED
}

isMapSelected(idpos)
{
    for (new 
0g_voteSelectedNum[id]; ++a)
        if (
g_voteSelected[id][a] == pos)
            return 
1
    
return 0
}

displayVoteMapsMenu(idpos)
{
    if (
pos 0)
        return

    new 
menuBody[512], 0start pos 7

    
if (start >= g_mapNums)
        
start pos g_menuPosition[id] = 0

    
new len format(menuBodycharsmax(menuBody), g_coloredMenus "\y%L\R%d/%d^n\w^n" "%L %d/%d^n^n"id"VOTEMAP_MENU"pos 1, (g_mapNums + ((g_mapNums 7) ? 0)))
    new 
end start 7keys MENU_KEY_0

    
if (end g_mapNums)
        
end g_mapNums

    
new tempMap[32];
    for (new 
startend; ++a)
    {
        
ArrayGetString(g_mapNameatempMapcharsmax(tempMap));
        if (
g_voteSelectedNum[id] == || isMapSelected(idpos b))
        {
            ++
b
            
if (g_coloredMenus)
                
len += format(menuBody[len], charsmax(menuBody) - len"\d%d. %s^n\w"btempMap)
            else
                
len += format(menuBody[len], charsmax(menuBody) - len"#. %s^n"tempMap)
        } else {
            
keys |= (1<<b)
            
len += format(menuBody[len], charsmax(menuBody) - len"%d. %s^n", ++btempMap)
        }
    }

    if (
g_voteSelectedNum[id])
    {
        
keys |= MENU_KEY_8
        len 
+= format(menuBody[len], charsmax(menuBody) - len"^n8. %L^n"id"START_VOT")
    }
    else
        
len += format(menuBody[len], charsmax(menuBody) - leng_coloredMenus "^n\d8. %L^n\w" "^n#. %L^n"id"START_VOT")

    if (
end != g_mapNums)
    {
        
len += format(menuBody[len], charsmax(menuBody) - len"^n9. %L...^n0. %L^n"id"MORE"idpos "BACK" "EXIT")
        
keys |= MENU_KEY_9
    
}
    else
        
len += format(menuBody[len], charsmax(menuBody) - len"^n0. %L^n"idpos "BACK" "EXIT")

    if (
g_voteSelectedNum[id])
        
len += format(menuBody[len], charsmax(menuBody) - leng_coloredMenus "^n\y%L:^n\w" "^n%L:^n"id"SEL_MAPS")
    else
        
len += format(menuBody[len], charsmax(menuBody) - len"^n^n")

    for (new 
04c++)
    {
        if (
g_voteSelectedNum[id])
        {
            
ArrayGetString(g_mapNameg_voteSelected[id][c], tempMapcharsmax(tempMap));
            
len += format(menuBody[len], charsmax(menuBody) - len"%s^n"tempMap)
        }
        else
            
len += format(menuBody[len], charsmax(menuBody) - len"^n")
    }

    new 
menuName[64]
    
format(menuNamecharsmax(menuName), "%L""en""VOTEMAP_MENU")

    
show_menu(idkeysmenuBody, -1menuName)
}

public 
cmdVoteMapMenu(idlevelcid)
{
    if (!
cmd_access(idlevelcid1))
        return 
PLUGIN_HANDLED

    
if (get_cvar_float("amx_last_voting") > get_gametime())
    {
        
client_print(idprint_chat"%L"id"ALREADY_VOT")
        return 
PLUGIN_HANDLED
    
}

    
g_voteSelectedNum[id] = 0

    
if (g_mapNums)
    {
        
displayVoteMapsMenu(idg_menuPosition[id] = 0)
    } else {
        
console_print(id"%L"id"NO_MAPS_MENU")
        
client_print(idprint_chat"%L"id"NO_MAPS_MENU")
    }

    return 
PLUGIN_HANDLED
}

public 
cmdMapsMenu(idlevelcid)
{
    if (!
cmd_access(idlevelcid1))
        return 
PLUGIN_HANDLED

    
if (g_mapNums)
    {
        
displayMapsMenu(idg_menuPosition[id] = 0)
    } else {
        
console_print(id"%L"id"NO_MAPS_MENU")
        
client_print(idprint_chat"%L"id"NO_MAPS_MENU")
    }

    return 
PLUGIN_HANDLED
}

public 
delayedChange(mapname[])
{
    
engine_changelevel(mapname)
}

public 
actionVoteMapMenu(idkey)
{
    new 
tempMap[32];
    switch (
key)
    {
        case 
7:
        {
            new 
Float:voting get_cvar_float("amx_last_voting")
        
            if (
voting get_gametime())
            {
                
client_print(idprint_chat"%L"id"ALREADY_VOT")
                return 
PLUGIN_HANDLED
            
}

            if (
voting && voting get_cvar_float("amx_vote_delay") > get_gametime())
            {
                
client_print(idprint_chat"%L"id"VOT_NOW_ALLOW")
                return 
PLUGIN_HANDLED
            
}

            
g_voteCount = {00000}
            
            new 
Float:vote_time get_cvar_float("amx_vote_time") + 2.0
            set_cvar_float
("amx_last_voting"get_gametime() + vote_time)
            new 
iVoteTime floatround(vote_time)

            
set_task(vote_time"checkVotes"34567 id)

            new 
menuBody[512]
            new 
players[MAX_PLAYERS]
            new 
pnumkeyslen

            get_players
(playerspnum)

            if (
g_voteSelectedNum[id] > 1)
            {
                
len format(menuBodycharsmax(menuBody), g_coloredMenus "\y%L^n\w^n" "%L^n^n"id"WHICH_MAP")
                
                for (new 
0g_voteSelectedNum[id]; ++c)
                {
                    
ArrayGetString(g_mapNameg_voteSelected[id][c], tempMapcharsmax(tempMap));
                    
len += format(menuBody[len], charsmax(menuBody) - len"%d. %s^n"1tempMap)
                    
keys |= (1<<c)
                }
                
                
keys |= (1<<8)
                
len += format(menuBody[len], charsmax(menuBody) - len"^n9. %L^n"id"NONE")
            } else {
                
ArrayGetString(g_mapNameg_voteSelected[id][0], tempMapcharsmax(tempMap));
                
len format(menuBodycharsmax(menuBody), g_coloredMenus "\y%L^n%s?^n\w^n1. %L^n2. %L^n" "%L^n%s?^n^n1. %L^n2. %L^n"id"CHANGE_MAP_TO"tempMapid"YES"id"NO")
                
keys MENU_KEY_1|MENU_KEY_2
            
}

            new 
menuName[64]
            
format(menuNamecharsmax(menuName), "%L""en""WHICH_MAP")

            for (new 
0pnum; ++b)
                if (
players[b] != id)
                    
show_menu(players[b], keysmenuBodyiVoteTimemenuName)

            
format(menuBody[len], charsmax(menuBody), "^n0. %L"id"CANC_VOTE")
            
keys |= MENU_KEY_0
            show_menu
(idkeysmenuBodyiVoteTimemenuName)

            new 
authid[32], name[MAX_NAME_LENGTH]
            
            
get_user_authid(idauthidcharsmax(authid))
            
get_user_name(idnamecharsmax(name))

            
show_activity_key("ADMIN_V_MAP_1""ADMIN_V_MAP_2"name);

            new 
tempMapA[32];
            new 
tempMapB[32];
            new 
tempMapC[32];
            new 
tempMapD[32];
            if (
g_voteSelectedNum[id] > 0)
            {
                
ArrayGetString(g_mapNameg_voteSelected[id][0], tempMapAcharsmax(tempMapA));
            }
            else
            {
                
copy(tempMapAcharsmax(tempMapA), "");
            }
            if (
g_voteSelectedNum[id] > 1)
            {
                
ArrayGetString(g_mapNameg_voteSelected[id][1], tempMapBcharsmax(tempMapB));
            }
            else
            {
                
copy(tempMapBcharsmax(tempMapB), "");
            }
            if (
g_voteSelectedNum[id] > 2)
            {
                
ArrayGetString(g_mapNameg_voteSelected[id][2], tempMapCcharsmax(tempMapC));
            }
            else
            {
                
copy(tempMapCcharsmax(tempMapC), "");
            }
            if (
g_voteSelectedNum[id] > 3)
            {
                
ArrayGetString(g_mapNameg_voteSelected[id][3], tempMapDcharsmax(tempMapD));
            }
            else
            {
                
copy(tempMapDcharsmax(tempMapD), "");
            }
            
            
log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")"
                    
nameget_user_userid(id), authid
                    
tempMapAtempMapBtempMapCtempMapD)
        }
        case 
8displayVoteMapsMenu(id, ++g_menuPosition[id])
        case 
9displayVoteMapsMenu(id, --g_menuPosition[id])
        default:
        {
            
g_voteSelected[id][g_voteSelectedNum[id]++] = g_menuPosition[id] * key
            displayVoteMapsMenu
(idg_menuPosition[id])
        }
    }

    return 
PLUGIN_HANDLED
}

public 
actionMapsMenu(idkey)
{
    switch (
key)
    {
        case 
8displayMapsMenu(id, ++g_menuPosition[id])
        case 
9displayMapsMenu(id, --g_menuPosition[id])
        default:
        {
            new 
g_menuPosition[id] * key
            
new _modName[10]

            
get_modname(_modNamecharsmax(_modName))
            if (!
equal(_modName"zp"))
            {
                
message_begin(MSG_ALLSVC_INTERMISSION)
                
message_end()
            }
            
            new 
authid[32], name[MAX_NAME_LENGTH]
            
            
get_user_authid(idauthidcharsmax(authid))
            
get_user_name(idnamecharsmax(name))

            new 
tempMap[32];
            
ArrayGetString(g_mapNameatempMapcharsmax(tempMap));
            
            
show_activity_key("ADMIN_CHANGEL_1""ADMIN_CHANGEL_2"nametempMap);

            
log_amx("Cmd: ^"%s<%d><%s><>^" changelevel ^"%s^""nameget_user_userid(id), authidtempMap)
            
set_task(2.0"delayedChange"0tempMapstrlen(tempMap) + 1)
            
/* displayMapsMenu(id, g_menuPosition[id]) */
        
}
    }
    
    return 
PLUGIN_HANDLED
}

displayMapsMenu(idpos)
{
    if (
pos 0)
        return

    new 
menuBody[512]
    new 
tempMap[32]
    new 
start pos 8
    
new 0

    
if (start >= g_mapNums)
        
start pos g_menuPosition[id] = 0

    
new len format(menuBodycharsmax(menuBody), g_coloredMenus "\y%L\R%d/%d^n\w^n" "%L %d/%d^n^n"id"CHANGLE_MENU"pos 1, (g_mapNums + ((g_mapNums 8) ? 0)))
    new 
end start 8
    
new keys MENU_KEY_0

    
if (end g_mapNums)
        
end g_mapNums

    
for (new startend; ++a)
    {
        
keys |= (1<<b)
        
ArrayGetString(g_mapNameatempMapcharsmax(tempMap));
        
len += format(menuBody[len], charsmax(menuBody) - len"%d. %s^n", ++btempMap)
    }

    if (
end != g_mapNums)
    {
        
format(menuBody[len], charsmax(menuBody) - len"^n9. %L...^n0. %L"id"MORE"idpos "BACK" "EXIT")
        
keys |= MENU_KEY_9
    
}
    else
        
format(menuBody[len], charsmax(menuBody) - len"^n0. %L"idpos "BACK" "EXIT")

    new 
menuName[64]
    
format(menuName63"%L""en""CHANGLE_MENU")

    
show_menu(idkeysmenuBody, -1menuName)
}
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;
}

load_settings(filename[])
{
    new 
fp fopen(filename"r");
    
    if (!
fp)
    {
        return 
0;
    }
        

    new 
text[256];
    new 
tempMap[32];
    
    while (
fgets(fptextcharsmax(text)))
    {
        if (
text[0] == ';')
        {
            continue;
        }
        if (
parse(texttempMapcharsmax(tempMap)) < 1)
        {
            continue;
        }
        if (!
ValidMap(tempMap))
        {
            continue;
        }
        
        
ArrayPushString(g_mapNametempMap);
        
g_mapNums++;
    }

    
fclose(fp);

    return 
1;
}

public 
plugin_end()
{
    
ArrayDestroy(g_mapName)

kooomax is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-26-2023 , 23:13   Re: map
Reply With Quote #2

The winning map of what? The maps menu plugin is not related to the map choosing/voting plugin. So, when is this supposed to show up and to whom?
__________________
fysiks is offline
kooomax
Member
Join Date: Jan 2018
Old 06-27-2023 , 00:05   Re: map
Reply With Quote #3

After the voting ends
It will appear to the admin who started the votemap
kooomax is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2023 , 00:19   Re: map
Reply With Quote #4

It already has a menu pop up at the end of the vote to ask you if you would like to accept or reject the result. So, do you mean you want to change the existing menu to add the option to set the chose map as the "next map"? In addition to changing the text of the options?
__________________
fysiks is offline
kooomax
Member
Join Date: Jan 2018
Old 06-27-2023 , 00:25   Re: map
Reply With Quote #5

Yes
As i said at the beginning of the topic after the voting ends
A menu will come to the admin and ask him

If he wants to change the map now
Or wants him to change in the next round
Or ask him not to change
kooomax is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2023 , 00:36   Re: map
Reply With Quote #6

You said "add this menu" which means that you want to add something that wasn't already there. So, I was just trying to make sure we were talking about the same thing before doing the work.

I made the functional changes you asked for. Please download, compile, and test it. Once you know it works, we can update the final text that you want to show up in the menu.

https://github.com/fysiks1/amxmodx/b...s/mapsmenu.sma
__________________
fysiks is offline
kooomax
Member
Join Date: Jan 2018
Old 06-27-2023 , 02:20   Re: map
Reply With Quote #7

There is just one thing that needs to edit
Option number 2, "next map" can you modify it and make it "next round" e.g. if i pressed this choice map will change next round

kooomax is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2023 , 23:21   Re: map
Reply With Quote #8

I updated it (same link as above). Please test to make sure that next round functionality works.
__________________
fysiks is offline
kooomax
Member
Join Date: Jan 2018
Old 06-28-2023 , 04:25   Re: map
Reply With Quote #9

For some reason, the server crashes when moving from the current map to the new map
i tested it 3 times and each time it crashed

Segmentation fault (core dumped)
cat: hlds.51.pid: No such file or directory
email debug.log to [email protected]
Wed Jun 28 11:17:46 EEST 2023: Server restart in 10 seconds

For some reason, the kernel is also not debug after crash

I changed "changelevel" to "amx_map" and it works fine for now

server_cmd("amx_map %s", szMapname);

Last edited by kooomax; 06-28-2023 at 04:33.
kooomax is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2023 , 22:05   Re: map
Reply With Quote #10

I removed server_exec() which I've seen crash my server before so please try it again with the latest version.
__________________
fysiks 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 21:42.


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