Raised This Month: $ Target: $400
 0% 

Mapchooser - NMC+RTV Upgrade (need help)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
XCoder
Member
Join Date: Mar 2006
Location: Worldwide
Old 05-04-2010 , 08:42   Mapchooser - NMC+RTV Upgrade (need help)
Reply With Quote #1

Hello,

After many Hours i complete my work in hardcoded way.
My Problem was that there is noo good Rockthevote + Mapchooser + Special Configuration for the Mapselection.
And the second problem is that the most RTV Plugins want works with my Opposing Force Server!

Now i make this things at own script for my op4 server...
I modified the original "mapchooser.amxx" to this:
PHP Code:
/* AMX Mod X
*   Nextmap Chooser Plugin
*
* Original Version by the AMX Mod X Development Team
* Source originally developed by OLO
* Pimped/Modifyd by XCODER/Dr.StayDry 2010
* Thanks to Sylwester for .ini readout support
*
*
* Re-OPTIMIZED FOR OPPOSING FORCE MOD
* -----------------------------------
* + RockTheVote Feature (that rly works and 4 all not only for admins!)
* + Using nmc-rtv_maps.ini at same direction like mapcycle.txt

* + No CLASSIC Voting at end of map (Takes maps wich good for actual player amount)

* and some special things more....
*
*/

#include <amxmodx>
#include <amxmisc>

#define SELECTMAPS  4
#define MAX_MAP_LENGTH 64

#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: Counting for RTV
new rtv[33], countrtv_activehowmanyvoteshowmanyvotesperctimevote;

new 
g_coloredMenus
new bool:g_selected false

public plugin_init()
{
    
register_plugin("NMC-RTV""0.1""XCODER");
    
register_clcmd("say""rockthevote");
    
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");
    
// New: For RTV - Amount & Percent of Player to Start the RTV
    
howmanyvotes register_cvar("amx_howmanyvotes""6"); // how many players typed rtv to start voting promptly
    
howmanyvotesperc register_cvar("amx_howmanypercentage""0.20"); // in percent of total players, default 20% (0.20%)
    
timevote register_cvar("amx_timevote""4"); // After how many Minutes RTV can be used? (Std. 5)
    
    
rtv_active 328932;
    
count 0;
    
    
    
/*
    Only for CS
    -----------
    if (cstrike_running())
        register_event("TeamScore", "team_score", "a")
    */
    
    
get_localinfo("lastMap"g_lastMap31)
    
set_localinfo("lastMap""")

    
    
    new 
maps_ini_file[64]
    
get_configsdir(maps_ini_file63);
    
format(maps_ini_file63"nmc-rtv_maps.ini"maps_ini_file);
    
    
/*
    if (!file_exists(maps_ini_file))
        get_cvar_string("mapcyclefile", maps_ini_file, 63)
    
    */
    
    
if (loadSettings(maps_ini_file))
        
console_print(0,"~~~~ NMC-RTV - settings loaded ~~~~~~~");
    
    
    
    
g_coloredMenus colored_menus()
    
}

public  
client_disconnect(id)
{
    if (
rtv[id-1] == id)
    {
        
rtv[id-1] = 0;
        
count--;
    }
}


/*

TOTALY NEW PART - ROCK THE VOTE

*/

public rockthevote(id)
{
    new 
said[192];
    
read_args(said192);
    if((
contain(said"/rockthevote") != -1) || (contain(said"rockthevote") != -1) || (contain(said"rtv") != -1))
    {
        if(
get_gametime() < (get_pcvar_float(timevote) * 60.0))
            
client_print(idprint_chat"[RTV] Vote is currently not allowed. Wait %d minutes.", (floatround(((get_pcvar_float(timevote) * 60.0) - get_gametime()) / 60.0)));
        else
        {
            if    (
rtv[id-1] == id)
                
client_print(0print_chat"[RTV] %d Players choose RTV until now. Waiting for more! Type: rtv to accept the request"count);
            else
            {
                
rtv[id-1] = id;
                
count++;
                
                static 
num;
                
num get_playersnum();
                
num floatround((get_pcvar_float(howmanyvotesperc) * num));
                if((
num == count) || (count >= get_pcvar_num(howmanyvotes)))
                {
                    
// OK - LETS ROCKN ROLL, UNTIL NOW THE VOTE CAN STARTS!!!
                    
rtv_active++;
                    
                    
//refreshMapPool() - Check all 90 Seconds the pool
                    
set_task(90.0"refreshMapPool");
                    
voteNextmap(rtv_active);
                    return 
PLUGIN_CONTINUE;
                } else {
                    
rtv_active--;
                }
                static 
name[32];
                
get_user_nameidnamecharsmaxname ) );
                
                
// NEW, Show HUD to ALL:
                
set_hudmessage(210000.050.35120.010.00.50.154);
                
show_hudmessage(0"[RTV] %s is requesting a Mapchange. Need %d more Player requests OR %d^%^% Percent of the current Players to start it! (Type: rtv)"name, (get_pcvar_num(howmanyvotes)-count), (floatround(get_pcvar_float(howmanyvotesperc) * 100.00)));
                
//OLD STYLE: client_print ( 0, print_chat, "%s ~RTV~ was added. Need %d or %d^%^%  to start a Voting!", name, (get_pcvar_num(howmanyvotes)-count), (floatround(get_pcvar_float(howmanyvotesperc) * 100.00)))
                
                // Use Sound Event
                
if(count == 1)
                    
client_cmd(0"spk Gman/Gman_Choose2");
                    
            }
        }
    }
    return 
PLUGIN_CONTINUE;
}


/*

NEW PART FOR RTV ENDS

*/


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)
        
// Original: client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_EXT", steptime)
        // NEW, Show HUD to ALL:
        
set_hudmessage(210000.050.35120.010.00.50.154);
        
show_hudmessage(0"[NMC] The Map %s will be extended to next %.0f minutes"mapnamesteptime);
        
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)
    
// If Voting is running over RTV then directly...
    
if(rtv_active == 1)
    {
    
set_hudmessage(210000.050.35120.010.00.50.154);
    
show_hudmessage(0"[RTV] The Map-Voting is over. Changing to %s in 10 Seconds!"smap);    
    
set_task(15.0"xc_loadmapnow"); // starting mapchange at 15 seconds
    
rtv_active--; // reset it    
    
} else {
    
// otherwise set the map normal as next
    // Original: client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_NEXT", smap)
    
set_hudmessage(210000.050.35120.010.00.50.154);
    
show_hudmessage(0"[NMC] The Voting is over. Next Map: %s"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)
            
client_print(0print_chat"%L"LANG_PLAYER"CHOSE_EXT"name)
        else if (
key SELECTMAPS)
        {
            new 
map[32];
            
ArrayGetString(g_mapNameg_nextName[key], mapcharsof(map));
            
client_print(0print_chat"%L"LANG_PLAYER"X_CHOSE_X"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(rtv_active)
{
    
    
    
    new 
winlimit get_cvar_num("mp_winlimit")
    new 
maxrounds get_cvar_num("mp_maxrounds")
    
    
/*
    * TEMP CUTTET:
    * DONT WORKS WITH MY MODIFICATIONS...
    * BUT NEED IT FOR THE CLASSICAL EVENTS LIKE MAP ENDS ...
    
    if (winlimit)
    {
        new c = winlimit - 2
        
        if ((c > g_teamScore[0]) && (c > g_teamScore[1]))
        {
            g_selected = false
            //return
        }
    }
    else if (maxrounds)
    {
        if ((maxrounds - 2) > (g_teamScore[0] + g_teamScore[1]))
        {
            g_selected = false
            //return
        }
    } else {
        new timeleft = get_timeleft()
        
        if (timeleft < 1 || timeleft > 129)
        {
            g_selected = false
            //return
        }
    }
    
    // Patch: If rtv_enabled = false return! (dont works...)
    if(rtv_active != 1 && g_selected)
    {
        g_selected = false
        return
    }
        
    if (g_selected)
        return
    
    */
    
    
if(rtv_active != 1)
    {
        
g_selected false
        
return
    } else
        
g_selected true;
    
    
    new 
menu[512], amkeys = (1<<SELECTMAPS 1)

    new 
pos format(menu511g_coloredMenus "\y%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"%d. %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)

    
// Patch: RTV Option added, no EXTEND if RTV is running!
    
if (rtv_active != && (winlimit maxrounds) == && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max")))
    {
        
pos += format(menu[pos], 511"%d. %L^n"SELECTMAPS 1LANG_SERVER"EXTED_MAP"mapname)
        
mkeys |= (1<<SELECTMAPS)
    }

    
format(menu[pos], 511"%d. %L"SELECTMAPS+2LANG_SERVER"NONE")
    new 
MenuName[64]
    
    
format(MenuName63"%L""en""CHOOSE_NEXTM")
    
show_menu(0mkeysmenu15MenuName)
    
set_task(15.0"checkVotes")
    
// Original: client_print(0, print_chat, "%L", LANG_SERVER, "TIME_CHOOSE")
    // NEW: Show HUD to ALL
    
set_hudmessage(210000.050.35120.010.00.50.154);
    
show_hudmessage(0"[NMC] Its time for a new map ;)...");
    
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;
}

public 
refreshMapPool()
{
    
loadSettings("nmc-rtv_maps.ini");
    
set_task(90.0"refreshMapPool");
}

loadSettings(filename[])
{
    
    if (!
file_exists(filename))
        return 
0
    
        
    
new szText[32]
    new 
currentMap[32]
    new 
szTmp[32], minplayersmaxplayers// testing XXXX
    
    
new buff[256];
    
    
get_mapname(currentMap31)

    new 
fp=fopen(filename,"r");
    
ArrayClear(g_mapName);
    while (!
feof(fp))
    {
        
buff[0]='^0';
        
szText[0]='^0';
        
szTmp[0]='^0';
        
        
fgets(fpbuffcharsof(buff));        
        
parse(buffszTextcharsof(szText), szTmpcharsof(szTmp));
        if(
szText[0] == '#')
        {
            
minplayers str_to_num(szText[1])
            
maxplayers str_to_num(szTmp)
            continue
        }
        
        new 
chplayers get_playersnum();
                
        if(
chplayers  >= minplayers && maxplayers chplayers)
        {
        
            if (
szText[0] != ';' &&
                
szText[0] != '#' &&
                
ValidMap(szText) &&
                !
equali(szTextg_lastMap) &&
                !
equali(szTextcurrentMap))
            {
                
console_print(0,"NMC_RTV Circle::: ~ %d ~ 1> %d   2> %d"szTextminplayersmaxplayers);
                
ArrayPushString(g_mapNameszText);
                ++
g_mapNums;
            }
        }
        
    }
    
    
fclose(fp);

    return 
g_mapNums
}

public 
xc_loadmapnow()
{
    
/// RTV has spoken..., CHANGE MAP NOW:
    
new xchash_nextmap[MAX_MAP_LENGTH];
    
get_cvar_string("amx_nextmap"xchash_nextmapcharsmax(xchash_nextmap));
    
server_cmd("amx_map %s"xchash_nextmap);
}

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)

And here is a example of the .ini file
(#<MinPlayers> <MaxPlayers>)

Quote:
#0 10
op4_campgrounds
#6 15
mario_xmas
mario_land
killbox
killbox_us
#5 23
mario_air
And its working but there are some Problems after a time and the Code is TOTALY bad modified, my last scripts are many years ago...

Some Problems i noticed:
- If the Part i comment out (see above) is not commented out, the RTV and mapchooser goes crazy...
- The Votings are not more rly balanced, but may its also a other problem...

So, i'll hope someone can help me to fitup the code for "stable" running and a better structure for the code

(Sry for my broken english)

Greetings

Last edited by XCoder; 05-04-2010 at 09:27.
XCoder is offline
 


Thread Tools
Display Modes

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 03:43.


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