cmdmenu plugin
cmdmenu plugin
Download : Click Here
Introduction 😉
It was requested here. I took original Super Mapchooser v2.0 plugin well-known in Russia and rewrite about half of code to bring new functionality and to improve. It was not so easy task. I spent 16 hours 😉
Description
It is simple plugin for limit-based next map vote with one key feature and some effects.
Key features
Vote for next map occurs at the beginning of the last round. Screen is faded, players are frozen and vote begins… and some other effects. See screenshots.
Key improvements from v2.0
– true ML support
– pcvars
– support for round-based limits
Attention
My version of plugin is suitable for CS 1.6 only but not for CSDM, GunGame or other mods that are don’t have rounds in general. It is because it relies on rounds.
Plugin requires AMXX nextmap base plugin (nextmap.amxx).
Notes
Plugin manipulates with mp_timelimit of map to make sure that last round will be and will be completed.
In case of ANY map management plugin if you have option ‘extend map’ you SHOULD restore mp_timelimit value using one of 2 methods:
1. Recommended Create such record into server.cfg file:
mapchangecfgfile mapchange.cfg
Then create text file named mapchange.cfg in the same folder. Then put into that file cvars that should be restored after EACH map change. I mean true HLDS cvars which are exist with AND without AMXX presence.
2. Put such cvars into amxx.cfg file.
Cvars
amx_extendmap_max – base AMXX cvar, default 90 minutes;
amx_extendmap_step – base AMXX cvar, default 15 minutes;
amx_vote_answers – show what players voted for, 1=yes, 0=no, default 1;
mapchooser_votetime – delay between when vote starts and when votes are tallied, default 15 seconds;
mapchooser_votemaps – how many maps offer for vote besides ‘prolong current map’ option, from 1 to 8, default 5 maps;
Color for vote results in RRRGGGBBB format, where RRR, GGG, BBB – numbers from 0 to 255, def. 000 255 100 – light green:
mapchooser_result_red RRR – red component;
mapchooser_result_green GGG – green component;
mapchooser_result_blue BBB – blue component.
Credits:
TRUE RED – for the idea and testing the plugin;
fysiks – advices, eforie – ML.
—
Current version: v3.0 04/26/2012
The most recent changed files are attached directly.
#include <amxmodx>
new const PLUGIN[] = “Super Mapchooser”
new const VERSION[] = “2.0”
new const AUTHOR[] = “Prayer”
#define FLOAT_TIMELIMIT “mp_timelimit”
#define STRING_NEXTMAP “amx_nextmap”
#define NUM_MAXROUNDS “mp_maxrounds”
#define NUM_WINLIMIT “mp_winlimit”
#define NUM_SM_VOTEMAPS “mapchooser_votemaps”
#define NUM_SM_LANG “mapchooser_lang”
#define NUM_SM_TIME “mapchooser_votetime”
#define NUM_SM_RED “mapchooser_result_red”
#define NUM_SM_GREEN “mapchooser_result_green”
#define NUM_SM_BLUE “mapchooser_result_blue”
#define TASK_PLUGIN_ID 44747477 // +=:D
#define TASK_SCREEN_ID 979699 // +=:D:=+
#define TASK_RESULT_ID 12111 // 😮
const HudLen = 512
new Array:g_mapName
new g_mapNums
new g_saveids[10]
new g_voteCount[10]
new g_nextName[10]
new g_lastMap[32]
new g_currentMap[32]
new g_mapVoteNum
new g_votemaps
new g_maxspeed = 320
new bool:hasBlocked = false
new bool:forceBlock = true
new bool:voteStarted = true
new bool:hasExtend = false
new timeleft
new bool:hasBlind[33] = { false, … }
new g_msgScreenFade
new PlayersVoted = 0
new PlayersNum = 0
new
g_result_red,
g_result_green,
g_result_blue
new MenuName[96]
enum ChatColor
{
CHATCOLOR_NORMAL = 1, // Normal
CHATCOLOR_GREEN, // Green Color
CHATCOLOR_TEAM_COLOR, // Red, grey, blue
CHATCOLOR_GREY, // grey
CHATCOLOR_RED, // Red
CHATCOLOR_BLUE, // Blue
}
new g_TeamName[][] =
{
“”,
“TERRORIST”,
“CT”,
“SPECTATOR”
}
new g_msgSayText
new g_msgTeamInfo
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar(“amx_extendmap_max”, “90.0”)//Максимальное количество минут. Когда несколько раз продлевается карта – это значение будет максимальным в timelimit’е
register_cvar(“amx_extendmap_step”, “15.0”)//На сколько минут продлевать карту, если проголосовали за ее продление.
register_cvar(NUM_SM_LANG, “0”)//0-Русский, 1-English
register_cvar(NUM_SM_TIME, “15”)//Сколько времени в секундах должно идти голосование
register_cvar(NUM_SM_VOTEMAPS, “5”)//Сколько карт выводить на голосование не считая карты, которую продливают в голосовании
// Каким цветом показывать результаты голосования. Формат RGB
register_cvar(NUM_SM_RED, “255”)//Красный
register_cvar(NUM_SM_GREEN, “255”)//Зеленый
register_cvar(NUM_SM_BLUE, “255”)//Синий
register_event(“ScreenFade”, “EVENT_ScreenFade”, “be”)
register_event(“TextMsg”, “EVENT_RestartRound”, “a”, “2&#Game_C”,”2&#Game_w”)
g_msgSayText = get_user_msgid(“SayText”)
g_msgTeamInfo = get_user_msgid(“TeamInfo”)
g_msgScreenFade = get_user_msgid(“ScreenFade”)
}
public plugin_cfg()
{
g_votemaps = get_cvar_num(NUM_SM_VOTEMAPS)
if(g_votemaps > 8)
set_cvar_num(NUM_SM_VOTEMAPS, 8)
else if(g_votemaps < 1)
set_cvar_num(NUM_SM_VOTEMAPS, 1)
g_votemaps = get_cvar_num(NUM_SM_VOTEMAPS)
register_menucmd(register_menuid(“superMapChooserMenu”), (-1^(-1<<(g_votemaps + 1))), “countVote”)
g_mapName = ArrayCreate(32)
get_localinfo(“lastMap”, g_lastMap, sizeof g_lastMap -1)
set_localinfo(“lastMap”, “”)
new maps_ini_file[64]
get_localinfo(“amxx_configsdir”, maps_ini_file, sizeof maps_ini_file -1)
format(maps_ini_file, sizeof maps_ini_file -1, “%s/maps.ini”, maps_ini_file)
if(!file_exists(maps_ini_file))
get_cvar_string(“mapcyclefile”, maps_ini_file, sizeof maps_ini_file -1)
if(loadSettings(maps_ini_file))
cmdReloadTimer()
g_maxspeed = get_cvar_num(“sv_maxspeed”)
// bugfix: need for timeleft (cs time == amxx time): !(!(remaining == left)) || !(remaining != left) 😮
server_cmd(“sv_restart 1”)
get_mapname(g_currentMap, sizeof g_currentMap -1)
}
public client_disconnect(id)
{
remove_task(id+TASK_SCREEN_ID)
remove_task(id+TASK_RESULT_ID)
hasBlind[id] = false
}
public EVENT_RestartRound()
cmdReloadTimer()
public cmdReloadTimer()
{
if(voteStarted)
{
PlayersVoted = 0
PlayersNum = 0
forceBlock = true
hasBlocked = false
voteStarted = false
new players[32], num, pid
get_players(players, num)
for(new i=0;i<num;i++)
{
pid = players[i]
hasBlind[pid] = false
remove_task(pid+TASK_SCREEN_ID)
remove_task(pid+TASK_RESULT_ID)
message_begin(MSG_ONE, g_msgScreenFade, _, pid)
write_short(1<<0)
write_short(1<<0)
write_short(1<<0)
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(0)
message_end()
}
if(!hasExtend)
{
switch(get_cvar_num(NUM_SM_LANG))
{
//ĮГолосование прервано!
case 0: colorChat(0, CHATCOLOR_RED, “Голосование прервано !”)
case 1: colorChat(0, CHATCOLOR_RED, “Voting is interrupted!”)
}
}
set_cvar_num(“sv_maxspeed”, g_maxspeed)
remove_task(TASK_PLUGIN_ID)
set_task(8.0, “taskListening”, TASK_PLUGIN_ID, “”, 0, “b”)
taskListening()
}
}
public taskListening()
{
timeleft = get_timeleft()
if(!hasBlocked && (timeleft <= (get_cvar_num(NUM_SM_TIME) + 14)))
{
change_task(TASK_PLUGIN_ID, 1.0)
hasBlocked = true
}
else if(timeleft <= (5 + get_cvar_num(NUM_SM_TIME)))//5 sekynd – skoka ostaetsia do smeni karti posle okon4ania golosovania
{
remove_task(TASK_PLUGIN_ID)
forceBlock = false
hasBlocked = false
hasExtend = false
g_result_red = get_cvar_num(NUM_SM_RED)
g_result_green = get_cvar_num(NUM_SM_GREEN)
g_result_blue = get_cvar_num(NUM_SM_BLUE)
set_cvar_num(“sv_maxspeed”, 0)
switch(get_cvar_num(NUM_SM_LANG))
{
//Проголосуйте за следующую карту
case 0: format(MenuName, sizeof MenuName -1, “Проголосуйте за следующую карту”)
case 1: format(MenuName, sizeof MenuName -1, “Vote for the next map”)
}
cmdVoteNextmap()
}
}
public cmdVoteNextmap()
{
new
winlimit,
maxrounds
winlimit = get_cvar_num(NUM_WINLIMIT)
maxrounds = get_cvar_num(NUM_MAXROUNDS)
new
mkeys = ((1<<g_votemaps) + 1),
menu[HudLen],
a
new pos = format(menu, HudLen -1, ” \r%s:^n^n”, MenuName)
new dmax = (g_mapNums > g_votemaps) ? g_votemaps : g_mapNums
new unki = 0
for(g_mapVoteNum = 0; g_mapVoteNum < dmax; g_mapVoteNum++)
{
a = random_num(0, g_mapNums -1)
while(isInMenu(a))
{
if(++a >= g_mapNums)
{
a = 0
}
}
g_nextName[g_mapVoteNum] = a
pos += format(menu[pos], HudLen -1, ” \y%d.\w %a^n”, g_mapVoteNum + 1, ArrayGetStringHandle(g_mapName, a))
g_saveids[unki] = a
unki++
mkeys |= (1<<g_mapVoteNum)
g_voteCount[g_mapVoteNum] = 0
}
g_voteCount[g_votemaps] = 0
g_voteCount[g_votemaps + 1] = 0
new language = get_cvar_num(NUM_SM_LANG)
if(((winlimit + maxrounds) == 0) && (get_cvar_float(FLOAT_TIMELIMIT) < get_cvar_float(“amx_extendmap_max”)))
{
switch(language)
{
//продлить
case 0: pos += format(menu[pos], HudLen -1, ” \y%d.\w %s \y[продлить]”, g_votemaps + 1, g_currentMap)
case 1: pos += format(menu[pos], HudLen -1, ” \y%d.\w %s \y[prolong]”, g_votemaps + 1, g_currentMap)
}
mkeys |= (1<<g_votemaps)
}
set_task(get_cvar_float(NUM_SM_TIME), “checkVotes”, TASK_PLUGIN_ID)
new players[32], pid
get_players(players, PlayersNum)
for(new i=0;i<PlayersNum;i++)
{
pid = players[i]
hasBlind[pid] = true
show_menu(pid, mkeys, menu, get_cvar_num(NUM_SM_TIME), “superMapChooserMenu”)
switch(language)
{
//Голосование начато!
case 0: colorChat(pid, CHATCOLOR_GREEN, “Голосование начато !”)
case 1: colorChat(pid, CHATCOLOR_GREEN, “Voting started”)
}
client_cmd(pid, “spk gman/gman_choose1”)
message_begin(MSG_ONE, g_msgScreenFade, _, pid)
write_short(1<<12) // Duration
write_short(1<<9) // Hold time
write_short(1<<0) // Fade type
write_byte(0) // Red
write_byte(0) // Green
write_byte(0) // Blue
write_byte(255) // Alpha
message_end()
set_task(1.0, “cmdFadeScreen”, pid+TASK_SCREEN_ID, “”, 0, “b”)
}
voteStarted = true
log_amx(“Super Vote: Voting for the nextmap started”)
}
public checkVotes()
{
new bolt = 0
for(new a = 0; a < g_mapVoteNum; a++)
{
if(g_voteCount[bolt] < g_voteCount[a])
{
bolt = a
}
}
//clear removed channel #2 :/
set_hudmessage(_,_,_,_,_,_,_,_,_,_,2)
show_hudmessage(0, ” “)
new players[32], num, pid
get_players(players, num)
if((g_voteCount[g_votemaps] > g_voteCount[bolt]) && (g_voteCount[g_votemaps] > g_voteCount[g_votemaps + 1]))
{
new Float:steptime = get_cvar_float(“amx_extendmap_step”)
set_cvar_float(FLOAT_TIMELIMIT, get_cvar_float(FLOAT_TIMELIMIT) + steptime)
set_hudmessage(255, 127, 0, -1.0, 0.25, 2, 0.1, 10.0, 0.05, 1.0, 1)
for(new i=0;i<num;i++)
{
pid = players[i]
switch(get_cvar_num(NUM_SM_LANG))
{
case 0:
{
//Голосование завершено. Эта карта продлена на %.0f мин
colorChat(pid, CHATCOLOR_GREEN, “Голосование завершено.^x01 Эта карта продлена на %.0f мин”, steptime)
//Эта карта продлена на %.0f мин
show_hudmessage(pid, “Эта карта продлена на %.0f мин”, steptime)
}
case 1:
{
colorChat(pid, CHATCOLOR_GREEN, “Voting is finished. This map is prolonged on %.0f minutes”, steptime)
show_hudmessage(pid, “This map is prolonged on %.0f minutes”, steptime)
}
}
}
log_amx(“Super Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes”, g_currentMap, steptime)
hasExtend = true
cmdReloadTimer()
return
}
new smap[32]
if(g_voteCount[bolt] && (g_voteCount[g_votemaps + 1] <= g_voteCount[bolt]))
{
ArrayGetString(g_mapName, g_nextName[bolt], smap, sizeof smap -1)
set_cvar_string(STRING_NEXTMAP, smap)
}
get_cvar_string(STRING_NEXTMAP, smap, sizeof smap -1)
set_hudmessage(255, 127, 0, -1.0, 0.42, 2, 0.1, 10.0, 0.05, 1.0, 1)
for(new i=0;i<num;i++)
{
pid = players[i]
remove_task(pid+TASK_RESULT_ID)
switch(get_cvar_num(NUM_SM_LANG))
{
case 0:
{
//Голосование завершено.^x01 Следующая карта:^x04 %s
colorChat(pid, CHATCOLOR_GREEN, “Голосование завершено.^x01 Следующая карта:^x04 %s”, smap)
//Следующая карта %s
show_hudmessage(pid, “Следующая карта %s”, smap)
}
case 1:
{
colorChat(pid, CHATCOLOR_GREEN, “Voting is finished.^x01 Nextmap:^x04 %s”, smap)
show_hudmessage(pid, “Nextmap will be %s”, smap)
}
}
}
log_amx(“Super Vote: Voting for the nextmap finished. The nextmap will be %s”, smap)
}
public countVote(id, key)
{
if(!voteStarted && forceBlock)
return PLUGIN_HANDLED
if(get_cvar_float(“amx_vote_answers”))
{
new name[32]
get_user_name(id, name, sizeof name -1)
if(key == g_votemaps)
{
switch(get_cvar_num(NUM_SM_LANG))
{
//Голосование завершено.^x01 Следующая карта:^x04 %s
case 0: colorChat(0, CHATCOLOR_GREEN, “%s^x01 проголосовал за^x04 продление карты”, name)
case 1: colorChat(0, CHATCOLOR_GREEN, “%s^x01 chose^x04 map extending”, name)
}
}
else if(key < g_votemaps)
{
new map[32]
ArrayGetString(g_mapName, g_nextName[key], map, sizeof map -1)
switch(get_cvar_num(NUM_SM_LANG))
{
//%s^x01 проголосовал за^x04 продление карты
case 0: colorChat(0, CHATCOLOR_GREEN, “%s^x01 проголосовал за^x04 %s”, name, map)
case 1: colorChat(0, CHATCOLOR_GREEN, “%s^x01 chose^x04 %s”, name, map)
}
}
cmdShowResults(id+TASK_RESULT_ID)
set_task(0.8, “cmdShowResults”, id+TASK_RESULT_ID, “”, 0, “b”)
}
client_cmd(id, “spk UI/buttonclickrelease”)
g_voteCount[key]++
PlayersVoted++
return PLUGIN_HANDLED
}
public cmdShowResults(pid)
{
static id
id = pid-TASK_RESULT_ID
if(is_user_connected(id))
{
static i, len, language, message[HudLen]
language = get_cvar_num(NUM_SM_LANG)
switch(language)
{
//Результаты голосования
case 0: len = format(message, sizeof message -1, “Результаты голосования^n^n”)
case 1: len = format(message, sizeof message -1, “Results of voting^n^n”)