AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   add mapchooser countdown to the end of the voting (https://forums.alliedmods.net/showthread.php?t=204951)

Seem0n 01-05-2013 03:30

add mapchooser countdown to the end of the voting
 
1 Attachment(s)
Hey. how to add mapchooser countdown to the end of the voting, the menu HELP

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <dhudmessage>

#define PLUGIN_NAME    "Nextmap Chooser"
#define PLUGIN_VERSION    "2.0"
#define PLUGIN_AUTHOR    "UFPS.Team"

#define SELECTMAPS        5
#define MAPS_MAX        128
#define AUTO_LANG        -76

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

new g_mapNums
new g_mapName        [MAPS_MAX][32]

new 
g_nextName        [SELECTMAPS]
new 
g_voteCount        [SELECTMAPS 2]
new 
g_mapVoteNum
new g_teamScore        [2]
new 
g_lastMap        [32]
new 
g_rtv_count
new g_rtv_vote        [33]

new 
g_MENU            [512]
new 
g_MENU_keys =    ( << SELECTMAPS )
new 
g_MENU_name        [64]
new 
g_MENU_title    [128]

new const 
speak[][] = { "one""two""three""four""five""six""seven""eight""nine""ten" }

new 
g_coloredMenus        0
new bool:g_rtv            false
new bool:g_lastround    false
new bool:g_changemap    false
new bool:g_selected        false
new Float:g_timelimit    0.0

new pcv_lastround
new pcv_extendmap_max
new pcv_extendmap_step
new pcv_vote_time
new timevote
new Hud
new pcv_votemap_ratio
new pcv_amx_nextmap
new pcv_mp_chattime
new pcv_mp_timelimit
new pcv_mp_winlimit
new pcv_mp_maxrounds


public plugin_init( )
{
    
register_pluginPLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR )

    
register_dictionary    "common.txt" )
    
register_dictionary    "mapchooser.txt" )

    
register_clcmd"say rockthevote""cmd_say_rtv" )
    
register_clcmd"say /rockthevote""cmd_say_rtv" )
    
register_clcmd"say rtv""cmd_say_rtv" )
    
register_clcmd"say /rtv""cmd_say_rtv" )

    
register_clcmd"say_team rockthevote""cmd_say_rtv" )
    
register_clcmd"say_team /rockthevote""cmd_say_rtv" )
    
register_clcmd"say_team rtv""cmd_say_rtv" )
    
register_clcmd"say_team /rtv""cmd_say_rtv" )

    
pcv_vote_time        pcvar_register"amx_vote_time""15" )
    
timevote register_cvar("amx_timevote""5")
    
Hud CreateHudSyncObj()
    
pcv_votemap_ratio    pcvar_register"amx_votemap_ratio""0.60" )
    
pcv_extendmap_max     pcvar_register"amx_extendmap_max""45" )
    
pcv_extendmap_step     pcvar_register"amx_extendmap_step""15" )

    
pcv_mp_chattime        get_cvar_pointer"mp_chattime"  )
    
pcv_mp_timelimit    get_cvar_pointer"mp_timelimit" )
    
pcv_mp_winlimit        get_cvar_pointer"mp_winlimit"  )
    
pcv_mp_maxrounds    get_cvar_pointer"mp_maxrounds" )
    
pcv_amx_nextmap        get_cvar_pointer"amx_nextmap"  )

    if( !
pcv_amx_nextmap )
        
pcv_amx_nextmap    register_cvar"amx_nextmap",    ""FCVAR_SERVER FCVAR_EXTDLL FCVAR_SPONLY )

    if( 
cstrike_running( ) )
    {
        
pcv_lastround register_cvar"amx_lastround""1" )
        
register_event"TeamScore""team_score""a" )
        
register_logevent"evRoundStart"2"0=World triggered""1=Round_Start" )
    }

    
register_event"30""mapChange""a" )

    
g_coloredMenus colored_menus( )

    
get_localinfo"lastMap"g_lastMapcharsmaxg_lastMap ) )
    
set_localinfo"lastMap""" )

    
set_cvar_float"sv_restart"1.0 )
}

public 
plugin_cfg( )
{
    new 
mapcycle[64]
    
get_configsdirmapcyclecharsmaxmapcycle ) )
    
formatmapcyclecharsmaxmapcycle ), "%s/maps.ini"mapcycle )

    if( !
file_existsmapcycle ) )
        
get_cvar_string"mapcyclefile"mapcyclecharsmaxmapcycle ) )

    if( !
file_existsmapcycle ) )
        
copymapcyclecharsmaxmapcycle ), "mapcycle.txt" )

    if( 
loadSettingsmapcycle) )
        
set_task15.0"voteNextmap"987456""0"b" )

    
formatexg_MENU_namecharsmaxg_MENU_name ), "%L""en""CHOOSE_NEXTM" )
    
register_menucmdregister_menuidg_MENU_name ), ( -^ ( -<< ( SELECTMAPS ) ) ), "countVote" )
}

public 
countVoteidkey )
{
    if( 
get_cvar_float"amx_vote_answers" ) )
    {
        new 
name[32]
        
get_user_nameidnamecharsmaxname ) )

        if( 
key == SELECTMAPS )
            
ColorChat0NORMAL"!y[!gСервер!y] %L"LANG_PLAYER"CHOSE_EXT"name )

        else if( 
key SELECTMAPS )
        {
            new 
map[32]
            
copymapcharsmaxmap ), g_mapName[g_nextName[key]] )
            
ColorChat0NORMAL"!y[!gСервер!y] %L"LANG_PLAYER"X_CHOSE_X"namemap )
        }
    }

    
g_voteCount[key]++

    return 
PLUGIN_HANDLED
}

public 
voteNextmap( )
{
    if( !
g_mapNums ) return 0

    
new winlimit get_pcvar_numpcv_mp_winlimit )
    new 
maxrounds get_pcvar_numpcv_mp_maxrounds )

    if( 
g_rtv )
    {
        
winlimit 0
        maxrounds 
= -1
    
}

    if( 
winlimit )
    {
        new 
winlimit 2

        
if( ( g_teamScore[0] ) && ( g_teamScore[1] ) )
        {
            
g_selected false
            
return 0
        
}
    }

    else if( 
maxrounds )
    {
        if( ( 
maxrounds ) > ( g_teamScore[0] + g_teamScore[1] ) )
        {
            
g_selected false
            
return 0
        
}
    }
    
    else
    {
        new 
timeleft get_timeleft( )

        if( 
timeleft || timeleft 129 )
        {
            
g_selected false
            
return 0
        
}
    }

    if( 
g_selected ) return 0

    g_selected 
true

    
new posa

    g_MENU_keys 
= ( << SELECTMAPS )

    new 
dmax clampg_mapNums0SELECTMAPS )

    for( 
g_mapVoteNum 0g_mapVoteNum dmaxg_mapVoteNum++ )
    {
        
random_num0g_mapNums )

        while( 
isInMenu) ) { if( ++>= g_mapNums 0; }

        
g_nextName[g_mapVoteNum] = a
        pos 
+= formatg_MENU[pos], charsmaxg_MENU ), "%d. %s^n"g_mapVoteNum 1g_mapName[a] )
        
g_MENU_keys |= ( << g_mapVoteNum )
        
g_voteCount[g_mapVoteNum] = 0
    
}

    
g_MENU[pos++] = '^n'
    
g_voteCount[SELECTMAPS] = 0
    g_voteCount
[SELECTMAPS 1] = 0
    
    
new mapname[32]
    
get_mapnamemapnamecharsmaxmapname ) )
    
    if( ( 
winlimit maxrounds ) == && ( get_pcvar_floatpcv_mp_timelimit ) < get_pcvar_floatpcv_extendmap_max ) ) )
    {
        
pos += formatg_MENU[pos], charsmaxg_MENU ), "%d. %L^n"SELECTMAPS 1LANG_SERVER"EXTED_MAP"mapname)
        
g_MENU_keys |= ( << SELECTMAPS )
    }
    
    
formatg_MENU[pos], charsmaxg_MENU ), "%d. %L"SELECTMAPS 2LANG_SERVER"NONE" )
        
set_task0.0"countDown"10 )

        return 
1
}

stock bool:isInMenuid )
{
    for( new 
ag_mapVoteNuma++ )
        if( 
id == g_nextName[a] ) return true

    
return false
}

public 
countDowntimer )
{
    if( 
timer )
    {
        
client_cmd,"spk ^"fvox/%s^""speak[timer-1] )
        
        
set_dhudmessage(02550, -1.00.1300.01.00.00.0);
        
show_dhudmessage(0"Голосование начнётся через %i секунд"timer)
        
        
set_hudmessage(1001001000.030.4300.01.00.00.0, -1);
        
ShowSyncHudMsg(0Hud"%s"g_MENU)
        
        
set_task(1.0"countDown", --timer)
    }
    else
    {
        
set_task0.0"showMenu" )
    }
}

public 
showMenu( )
{
    new 
Float:votetime floatclampget_pcvar_float pcv_vote_time ), 10.060.0 )

    new 
menu[512], players[32], playernum
    get_players
playersnum"ch" )

    for( new 
inumi++ )
    {
        
player players[i]

        
formatexg_MENU_titlecharsmaxg_MENU_title ), g_coloredMenus "\r%L:\w^n^n" "%L:^n"player"CHOOSE_NEXTM" )
        
formatexmenucharsmaxmenu ), "%s%s"g_MENU_titleg_MENU )
        
show_menuplayerg_MENU_keysmenufloatroundvotetime ), g_MENU_name )
    }

    
set_taskvotetime 0.5"checkVotes" )

    
client_cmd(0"spk UI/buttonclickrelease")
}    

public 
checkVotes( )
{
    new 
0

    
for( new ag_mapVoteNum; ++)
        if( 
g_voteCount[b] < g_voteCount[a] ) a

    
if( g_voteCount[SELECTMAPS] > g_voteCount[b] && g_voteCount[SELECTMAPS] > g_voteCount[SELECTMAPS 1] )
    {
        if( !
g_timelimit )
            
g_timelimit get_pcvar_floatpcv_mp_timelimit )

        new 
Float:steptime get_pcvar_floatpcv_extendmap_step )

        new 
mapname[32]
        
get_mapnamemapnamecharsmaxmapname ) )

        
set_pcvar_floatpcv_mp_timelimitget_pcvar_floatpcv_mp_timelimit ) + steptime )
        
ColorChat0NORMAL"%L"LANG_PLAYER"CHO_FIN_EXT"steptime )
        
set_dhudmessage(0255255,  -1.00.1326.03.00.11.5)
        
show_dhudmessage(0"ВНИМАНИЕ: Карта продлена на %.0f минут^n"steptime)
        
client_cmd(0"speak ^"barney/letsgo^"");

        return
    }

    new 
smap[32]
    if( 
g_voteCount[b] && g_voteCount[SELECTMAPS 1] <= g_voteCount[b] )
    {
        
copysmapcharsmaxsmap ), g_mapName[g_nextName[b]] )
        
set_pcvar_stringpcv_amx_nextmapsmap )
    }

    
get_pcvar_stringpcv_amx_nextmapsmapcharsmaxsmap ) )
    
ColorChat0NORMAL"%L"LANG_PLAYER"CHO_FIN_NEXT"smap )
    
    
set_dhudmessage(0255255, -1.00.1326.03.00.11.5)
    
show_dhudmessage(0"ВНИМАНИЕ: Карта %s победила с %d голосов"smapg_voteCount[b])
    
client_cmd(0"speak ^"barney/letsgo^"");
    
    new 
players[32], num
    get_players
playersnum"ch" )

    if( 
g_rtv )
    {
        if( 
pcv_lastround && get_pcvar_numpcv_lastround ) )
        {
            if( !
g_timelimit )
                
g_timelimit get_pcvar_floatpcv_mp_timelimit )

            
set_pcvar_floatpcv_mp_timelimit0.0 )

            
g_rtv false
            g_changemap 
true
            g_lastround 
false
            
            set_dhudmessage
(25500, -1.00.17,  26.03.00.11.5)
            
show_dhudmessage0"Играем последний раунд...")
            
            return
        }
    
        else
            
g_rtv false
    
}

    else if( 
num )
    {
        if( 
pcv_lastround )
        {
            
set_task90.0 floatclampget_pcvar_float pcv_vote_time ), 10.060.0 ), "initiateLastRound"23478""0"d" )
            return
        }
    }

    
set_task1.0"delayMapChange" )
}

public 
initiateLastRound( )
{
    if( !
get_pcvar_numpcv_lastround ) ) return PLUGIN_CONTINUE

    
if( !g_timelimit )
        
g_timelimit get_pcvar_floatpcv_mp_timelimit )

    
g_lastround true
    set_pcvar_float
pcv_mp_timelimit0.0 )

    
set_dhudmessage02550, -1.00.1726.03.00.11.5)
    
show_dhudmessage0"Следующий раунд последний...")

    return 
PLUGIN_CONTINUE
}

public 
evRoundStart( )
{
    if( !
pcv_lastround ) return PLUGIN_CONTINUE

    
if( !get_pcvar_numpcv_lastround ) ) return PLUGIN_CONTINUE

    
if( g_lastround )
    {
        
g_changemap true
        g_lastround 
false

        set_dhudmessage
(25500, -1.00.1726.03.00.11.5)
        
show_dhudmessage0"Играем последний раунд...")
    }
    
    else if( 
g_changemap )
    {
/*
        message_begin    ( MSG_ALL, SVC_INTERMISSION )
        message_end        ( )
*/

        
set_pcvar_floatpcv_mp_timelimit1.0 )
    }

    return 
PLUGIN_CONTINUE
}

public 
mapChange ( )
{
    new 
Float:chattime get_pcvar_float pcv_mp_chattime )

    if ( 
chattime 1.0 )
    {
        
chattime 1.0
        set_pcvar_float 
pcv_mp_chattimechattime )
    }

    
set_taskchattime 1.0"delayMapChange" )

    return 
PLUGIN_CONTINUE
}

public 
delayMapChange( )
{
    new 
nextmap[32]
    
get_pcvar_stringpcv_amx_nextmapnextmapcharsmaxnextmap ) )
    
server_cmd"changelevel %s"nextmap )
}

loadSettingsfilename[] )
{
    if( !
file_existsfilename ) )
    {
        
log_amx"Mapcycle file ^"%s^" not found"filename )
        return 
0
    
}

    
g_mapNums 0

    
new currentMap[32], map[32], string[256]
    
get_mapnamecurrentMapcharsmaxcurrentMap ) )

    new 
file fopenfilename"r" )
    
    while( !
feoffile ) )
    {
        
fgetsfilestringcharsmax( string ) )

        if
        (
            ( 
string[0] != ';' ) &&
            ( 
string[0] != '/' ) &&
            
parsestringmapcharsmaxmap ) ) &&
            
isValidMapmapcharsmaxmap ), currentMap ) &&
            
isMapCyclemap ) == -1
        
)
        {
            
copyg_mapName[g_mapNums++], charsmaxg_mapName[] ), map )
        }
    
    }

    
fclosefile )

    return 
g_mapNums
}

stock bool:isValidMapmap[], const len, const currentMap[] )
{
    
remove_quotes map )
    
strtolowermap )

    while( 
replacemaplen"/""" ) ) {}
    while( 
replacemaplen"\", "" ) ) {}
    while( replace( map, len, "
:", "" ) ) {}
    while( replace( map, len, "
*", "" ) ) {}
    while( replace( map, len, "
?", "" ) ) {}
    while( replace( map, len, "
>", "" ) ) {}
    while( replace( map, len, "
<", "" ) ) {}
    while( replace( map, len, "
|", "" ) ) {}
    while( replace( map, len, "
.", "" ) ) {}

    if( is_map_valid( map ) && !equali( map, g_lastMap ) && !equali( map, currentMap ) ) return true

    return false
}

stock isMapCycle( map[] )
{
    for( new i; i < g_mapNums; i++ )
        if( equali( g_mapName[i], map ) ) return i

    return -1
}

public team_score( )
{
    new team[2]

    read_data( 1, team, 1 )
    g_teamScore[( team[0]=='C' ) ? 0 : 1] = read_data( 2 )
}

public pcvar_register( const pcvar_name[], const pcvar_value[] )
{
    new pcvar_index = get_cvar_pointer( pcvar_name )
    
    if( !pcvar_index )
        pcvar_index = register_cvar( pcvar_name, pcvar_value )

    return pcvar_index
}

public cmd_say_rtv( id )
{
    if( get_gametime( ) < ( get_pcvar_float( timevote ) * 60.0 ) )
    {
        new timeleft = floatround( get_pcvar_float( timevote ) * 60.0 - get_gametime( ) )

        ColorChat( id, NORMAL, "
!y[!g&#1057;ервер!y] Голосование будет доступно через !t%d!y минут !t%d!y сек.", timeleft / 60, timeleft % 60 )
    
}

    else
    {
        if( 
g_rtv_vote[id 1] == id ColorChatidNORMAL"!y[!gСервер!y] !tВы уже проголосовали..." )

        else
        {
            
g_rtv_vote[id 1] = id
            g_rtv_count
++
    
            static 
players[32], num
            get_players
playersnum"ch" )

            new 
Float:voteratio floatclampget_pcvar_float pcv_votemap_ratio ), 0.01.0 )

            
num floatroundvoteratio num )

            if( 
num <= g_rtv_count )
            {
                 
g_rtv true
                voteNextmap
( )

                return 
PLUGIN_CONTINUE
            
}

            static 
name[32]
            
get_user_nameidnamecharsmaxname ) )
    
            
ColorChat0NORMAL"!y[!gСервер!y] !t%s!y проголосовал. Для голосования нужно еще !g%d!y голосов [!t%d^%^%!y]"namenum g_rtv_countfloatroundvoteratio 100.0 ) );
        }
    }

    return 
PLUGIN_CONTINUE
}

public 
client_disconnectid )
{
    if( 
g_rtv_vote[id 1] == id )
    {
        
g_rtv_vote[id 1] = 0
        g_rtv_count
--
    }
}

public 
plugin_end( )
{
    if( 
g_timelimit )
        
set_pcvar_floatpcv_mp_timelimitg_timelimit )

    new 
current_map[32]
    
get_mapnamecurrent_mapcharsmaxcurrent_map ) )

    
set_localinfo"lastMap"current_map )

    return 
PLUGIN_CONTINUE



alonelive 01-05-2013 12:33

Re: add mapchooser countdown to the end of the voting
 
Try this:

https://forums.alliedmods.net/showthread.php?p=1038314


All times are GMT -4. The time now is 13:42.

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