amx_votemod - Run time error 4: index out of bounds

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
134
Реакции
40
Помог
2 раз(а)
Ошибка
L 03/10/2023 - 01:10:41: [AMXX] Displaying debug trace (plugin "amx_votemod.amxx", version "4.6")
L 03/10/2023 - 01:10:41: [AMXX] Run time error 4: index out of bounds
L 03/10/2023 - 01:10:41: [AMXX] [0] amx_votemod.sma::LoadHUD (line 165)
ОС
Linux
Amx Mod X
amxx version
AMX Mod X 1.9.0.5294 (http://www.amxmodx.org)
Authors:
David "BAILOPAN" Anderson, Pavol "PM OnoTo" Marko
Felix "SniperBeamer" Geyer, Jonny "Got His Gun" Bergstrom
Lukasz "SidLuke" Wlasinski, Christian "Basic-Master" Hammacher
Borja "faluco" Ferrer, Scott "DS" Ehlert
Compiled: Dec 3 2021 15:54:56
Built from: https://github.com/alliedmodders/amxmodx/commit/363871a
Build ID: 5294:363871a
Core mode: JIT+ASM32
Билд
version
Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
ReHLDS version: 3.13.0.783-dev
Build date: 18:45:08 Feb 12 2023 (3228)
Build from: https://github.com/dreamstalker/rehlds/commit/1796459
ReGamedll
game version
ReGameDLL version: 5.21.0.556-dev
Build date: 08:43:58 Jul 22 2022
Build from: https://github.com/s1lentq/ReGameDLL_CS/commit/1081301
Версия Metamod
meta version
Metamod-r v1.3.0.131, API (5:13)
Metamod-r build: 18:51:02 Jul 11 2022
Metamod-r from: https://github.com/theAsmodai/metamod-r/commit/adc9414
Список метамодулей
meta list
Currently loaded plugins:
description stat pend file vers src load unload
[ 1] AMX Mod X RUN - amxmodx_mm_i386.so v1.9.0.5294 ini Start ANY
[ 2] ReAimDetector RUN - reaimdetector_amxx_i386.so v0.2.2 pl1 ANY Never
[ 3] FakeMeta RUN - fakemeta_amxx_i386.so v1.9.0.5294 pl1 ANY ANY
[ 4] ReAPI RUN - reapi_amxx_i386.so v5.21.0.248-dev pl1 ANY Never
[ 5] Ham Sandwich RUN - hamsandwich_amxx_i386.so v1.9.0.5294 pl1 ANY ANY
[ 6] Engine RUN - engine_amxx_i386.so v1.9.0.5294 pl1 ANY ANY
6 plugins, 6 running
Список плагинов
amxx plugins
Currently loaded plugins:
name version author file status
[ 1] Vote Mod 4.6 Soloist amx_votemod.amx debug
1 plugins, 1 running
Автор плагина
Soloist
Версия плагина
Version 4.6
Исходный код
https://forums.alliedmods.net/showthread.php?t=21585

new const VOTEMOD_PLUGIN[] = "Vote Mod"
new const VOTEMOD_AUTHOR[] = "Soloist"
new const VOTEMOD_VERSION[] = "4.6"

/*
Vote mod starts a vote on the beginning of each map and allows
you to chose a Counter-Strike mini mod.

Features
- A cfg file where the server op adds in the plugin he/she wants to use.

Client Commands:
* showmods - displays the mods on the server

Admin Commands:
* amx_votemod - Admin with vote flag can starts the vote
* amx_votemenu - Admins can select what mod they want

Server Commands:
* amx_defaultcfg <cfg file>
* amx_addvotemenu <menu text> <CVAR/On Command> <Off Command>

Future Plans
* Add a cfg file for maps that should not start a vote.

Written By Soloist
Version 4.6
Last Updated On 09/24/06

*************************************************************************************

Changelog
Version 4.6
* Doesn't restart round when No Mod is voted
Version 4.5
* Fixed HUD channel problem
* Add the ability to load mods by cfg files.
* Added a minimum number of players for the mod.
* Added default cfg file
Version 4.1
* Fixed HUD message error
* Attempt to fix the HUD channel problem with it convicting with other plugins
Version 4.0
* Change the Setting hostname Define to a CVAR
* The hostname is set automaticly now.
* Added HUD message displaying which mod is loaded
* Added a boolean so that only one vote can be started
Version 3.5
* Changed server command to amx_addvotemenu <menu text> <CVAR/On Command> <Off Command>
* so now the server can run mods with on/off commands i.e. GabenMod
* Added client command showmods to display mods on the server
* Cleaned Code
Version 3.0
* There must be 2 players before vote starts
* Cleaned Code
Version 2.6
* Made No Mod the default if no votes are made
* Fixed Admin Menu bug
Version 2.5
* Added Admin Menu
* Cleaned Code
Version 2.1
* Fixed No Mod Bug
Version 2.0
* Reworked code.
* Added a config file.
* All mods are supported
Version 1.1
* Clean up code
* Fixed counting bug
* Added define for setting the hostname
Version 1.0
* Release of the plugin
*/

// ---------- Adjust below settings to your liking ---------------------------------------
#define ADMINVOTEMOD ADMIN_VOTE // Admin access for the vote mod command
#define ADMINVOTEMENU ADMIN_LEVEL_A // Admin access for vote menu command

//#define DEBUG // Comment this out if you don't want added server print messages.
// ---------- Adjust above settings to your liking ---------------------------------------

#include <amxmodx>
#include <amxmisc>

#define MAXMENUS 9
#define STRINGSIZE 32
#define STRINGLENGTH STRINGSIZE - 1

new menuNumber = 0;
new menuBody[MAXMENUS][STRINGSIZE];
new minPlayers[MAXMENUS];
new menuCmd1[MAXMENUS][STRINGSIZE];
new menuCmd2[MAXMENUS][STRINGSIZE];
new defaultCfgFile[STRINGSIZE];

new bool:voteStarted;
new count[10];
new name[24];
new playerNum;
new loaded = -1;

new menu[512];
new keys;

new hostname[75]

new configs[128];

public plugin_init()
{
register_plugin(VOTEMOD_PLUGIN, VOTEMOD_VERSION, VOTEMOD_AUTHOR);

register_cvar("VoteMod_Version", VOTEMOD_VERSION, FCVAR_SERVER|FCVAR_SPONLY);
set_cvar_string("VoteMod_Version", VOTEMOD_VERSION);

register_menucmd(register_menuid("Vote_Mod"), 1023, "Vote");
register_menucmd(register_menuid("Vote_Admin"), 1023, "VoteAdmin");

register_concmd("amx_votemod", "ShowVote", ADMINVOTEMOD, "- starts a vote for a minimod");
register_concmd("amx_votemenu", "ShowVoteAdmin", ADMINVOTEMENU, "- displays a menu to choose a mod");

register_clcmd("showmods", "ShowMods", 0, " - shows the mods on the server");

register_srvcmd("amx_addvotemenu", "AddVoteMenu", 0, "<menu text> <CVAR/On Command> <Off Command> - Add a menu item to the Vote Mod Plugin");
register_srvcmd("amx_defaultcfg", "DefaultCfg", 0, "<Default cfg - Default CFG file");

register_cvar("vm_numplayers", "2");
register_cvar("vm_sethostname", "0");

// Add menu items
get_configsdir(configs, 127);
server_cmd("exec %s/VoteMod/votemenu.cfg", configs);

set_task(5.0, "plugin_start");
set_task(5.0, "SetDefaults");

return PLUGIN_CONTINUE;
}

public plugin_start()
{
if(get_cvar_num("vm_sethostname") == 1)
get_cvar_string("hostname", hostname, 74);
}

public plugin_end()
{
if(get_cvar_num("vm_sethostname") == 1)
set_cvar_string("hostname", hostname);
}
public client_putinserver()
{
playerNum++;
if(playerNum == get_cvar_num("vm_numplayers") && loaded == -1)
set_task(20.0,"ShowVote");
}

public client_disconnect(id)
playerNum--;

public LoadHUD()
{
new hudmessage[76]
format(hudmessage, 75, "%s is currently running", menuBody[loaded]);

for(new i = 1; i <= get_playersnum(); i++)
{
if(is_user_connected(i))
{
set_hudmessage(i, 255, 0, 0.01, 0.75, 0, 6.0, 5.0, 0.0, 0.0, -1)
show_hudmessage(i, "%s", hudmessage);
}
}

set_task(1.0, "LoadHUD");

return PLUGIN_CONTINUE;
}

public SetDefaults()
{
if(!equal(defaultCfgFile, ""))
{
server_cmd("exec %s/VoteMod/%s", configs, defaultCfgFile);
#if defined DEBUG
server_print("Exec %s", defaultCfgFile);
#endif
}

for(new i = 0; i < menuNumber; i++)
{
if(equal(menuCmd2[i], ""))
{
if(containi(menuCmd1[i], ".cfg") == -1)
{
set_cvar_num(menuCmd1[i], 0);

#if defined DEBUG
server_print("Setting %s", menuCmd1[i]);
#endif
}
}
else
{
server_cmd(menuCmd2[i]);

#if defined DEBUG
server_print("Setting %s", menuCmd2[i]);
#endif
}
}
}

public AddVoteMenu()
{
// AddMenu(const sMenuBody[], const sMinPlayers[], const sMenuCmd1[], const sMenuCmd2[])
new menuBody[STRINGSIZE], minPlayers[STRINGSIZE], menuCmd1[STRINGSIZE], menuCmd2[STRINGSIZE];
read_argv(1, menuBody, STRINGLENGTH);
read_argv(2, minPlayers, 1);
read_argv(3, menuCmd1, STRINGLENGTH);
read_argv(4, menuCmd2, STRINGLENGTH);

AddMenu(menuBody, minPlayers, menuCmd1, menuCmd2);
}

public AddMenu(const sMenuBody[], const sMinPlayers[], const sMenuCmd1[], const sMenuCmd2[])
{
copy(menuBody[menuNumber], STRINGLENGTH, sMenuBody);
minPlayers[menuNumber] = str_to_num(sMinPlayers);
copy(menuCmd1[menuNumber], STRINGLENGTH, sMenuCmd1);
copy(menuCmd2[menuNumber], STRINGLENGTH, sMenuCmd2);

server_print("Menu item %d added to Vote Mod: ^"%s^" - Min Players %d", menuNumber, menuBody[menuNumber], minPlayers[menuNumber]);

menuNumber++;
}

public DefaultCfg()
{
new defaultCfg[STRINGSIZE];
read_argv(1, defaultCfg, STRINGLENGTH);

copy(defaultCfgFile, STRINGLENGTH, defaultCfg);

server_print("Default cfg = %s", defaultCfg);
}

public ShowVoteAdmin(id, level, cid)
{
if(!cmd_access(id, level, cid, 0))
return PLUGIN_HANDLED;

if(voteStarted)
return PLUGIN_HANDLED;

new len = format(menu, 511, "Vote Mod Admin Menu^n");
for(new i = 0; i < menuNumber; i++)
{
server_print("MinPlayers = %d - Server Players = %d", minPlayers[i], get_playersnum())
if(minPlayers[i] <= get_playersnum())
{
keys |= (1<<i);
len += format(menu[len], 511-len, "%d. Change to %s^n", i+1, menuBody[i]);
}
}

keys |= (1<<9);
len += format(menu[len], 511-len, "^n0. Cancel");

show_menu(id, keys, menu, 15, "Vote_Admin");

return PLUGIN_CONTINUE;
}

public VoteAdmin(id, key, level, cid)
{
if(!cmd_access(id, level, cid, 0))
return PLUGIN_HANDLED;

get_user_name(id, name, 23);

client_print(0, print_chat, "%s changed mod to %s", name, menuBody[key]);
server_print("%s changed mod to %s", name, menuBody[key]);
SetCvars(key);

return PLUGIN_CONTINUE;
}

public ShowVote(id, level, cid)
{
if (!cmd_access(id, level, cid, 0))
return PLUGIN_HANDLED;

if(voteStarted)
return PLUGIN_HANDLED;

new len = format(menu, 511, "Vote For Which Mod You Want^n");
for(new i = 0; i < menuNumber; i++)
{
if(minPlayers[i] <= get_playersnum())
{
keys |= (1<<i);
len += format(menu[len], 511-len, "%d. %s^n", i+1, menuBody[i]);
#if defined DEBUG
server_print("Added %s to menu", menuBody[i]);
#endif
}
}

len += format(menu[len], 511-len, "^n0. None");
keys |= (1<<9);

show_menu(0, keys, menu, 15, "Vote_Mod");
voteStarted = true;

set_task(25.0,"CheckVotes");

return PLUGIN_CONTINUE;
}

public Vote(id, key)
{
get_user_name(id, name, 23);

if(key != 9)
{
client_print(0, print_chat, "%s voted %s", name, menuBody[key]);
server_print("%s voted %s", name, menuBody[key]);
count[key]++;
}
else if(key == 9)
{
client_print(0, print_chat, "%s voted %s", name, "no mod");
server_print("%s voted %s", name, "no mod");
count[key]++;
}

return PLUGIN_HANDLED;
}

public CheckVotes()
{
new best = 9;
new noVotes = 0;

for(new a = 0; a < 9; a++)
{
if(count[a] > count[best])
best = a;
else
noVotes++;
}

if(noVotes == 10)
best = 9;

if(best != 9)
{
client_print(0, print_chat, "%s won with %d votes", menuBody[best], count[best]);

#if defined DEBUG
server_print("%s won with %d votes", menuBody[best], count[best]);
#endif
}
else if(best == 9)
{
client_print(0, print_chat, "%s won with %d votes", "No mod", count[best]);

#if defined DEBUG
server_print("%s won with %d votes", "No mod", count[best]);
#endif
}

loaded = best;
SetCvars(best);
}

public SetCvars(num)
{
SetDefaults();

new sethostname[75];

if(num != 9)
{
if(get_cvar_num("vm_sethostname") == 1)
{
format(sethostname, 74, "%s *%s*", hostname, menuBody[num]);
set_cvar_string("hostname", sethostname);
}

if(equal(menuCmd2[num], ""))
{
if(containi(menuCmd1[num], ".cfg") == -1)
set_cvar_num(menuCmd1[num], 1);
else
server_cmd("exec %s/VoteMod/%s", configs, menuCmd1[num]);
}
else
server_cmd(menuCmd1[num]);

set_cvar_num("sv_restart", 5);

#if defined DEBUG
server_print("%s Loaded", menuBody[num]);
#endif
}
else if(num == 9)
{
if(get_cvar_num("vm_sethostname") == 1)
{
format(sethostname, 74, "%s *%s*", hostname, "No Mod");
set_cvar_string("hostname", sethostname);
}

#if defined DEBUG
server_print("%s Loaded", "No Mod");
#endif
}

for(new i = 0; i < 10; i++)
count[i]=0;

voteStarted = false;

set_task(0.5, "LoadHUD");

return PLUGIN_CONTINUE;
}

public ShowMods(id)
{
client_print(id, print_console, "Current Mods On The Server:");

for(new i = 0; i < menuNumber; i++)
client_print(id, print_console, "%d. %s - Min Players: %d", (i+1), menuBody[i], minPlayers);

return PLUGIN_CONTINUE;
}
Видел топик с такой же проблемой на другом форуме, но без решения, но было много критики в адрес автора и использования set_task(1.0, "LoadHUD"). Хотел бы сразу уточнить, какой оптимальный параметр лучше использовать, если название мода в худе все ровно не будет изменено до следующего голосования.
 
В этой теме было размещено решение! Перейти к решению.
Сообщения
1,082
Реакции
58
Помог
11 раз(а)
L 03/10/2023 - 01:10:41: [AMXX] Displaying debug trace (plugin "amx_votemod.amxx", version "4.6")
L 03/10/2023 - 01:10:41: [AMXX] Run time error 4: index out of bounds
L 03/10/2023 - 01:10:41: [AMXX] [0] amx_votemod.sma::LoadHUD (line 165)
Ошибка возникает потому что, ты обращаешься к ячейке массива которой не существует!
Код:
-#define MAXMENUS        9
+#define MAXMENUS       10
 
Сообщения
1,082
Реакции
58
Помог
11 раз(а)
Rayn, ошибка осталась? В любом случае, ты выходишь за пределы этого массива menuBody[loaded]
Строка 356
Код:
best = 9;
строка 375
Код:
loaded = best;
строка 165
Код:
format(hudmessage, 75, "%s is currently running", menuBody[loaded]);
ты можешь обратиться в этот интервал массивов menuBody[0]...menuBody[8]
 
Последнее редактирование:
Сообщения
134
Реакции
40
Помог
2 раз(а)
Code_0xABC, хорошо спасибо, я понял это и поменял то значение. Плагин не мой, ссылка на источник в исходном коде. На данный момент ошибка продолжает появляться. Если поможет, то это происходит, когда я использую команду amx_votemenu, она открывает меню в котором админ может выбрать мод без голосования, после нажатия одного из пунктов меню вызванного данной командой в консоли фиксируется ошибка. Меню которое вызывается командой amx_votemod ошибок не вызывает.
 
Сообщения
3,593
Реакции
1,576
Помог
141 раз(а)
Попробуй так:
Код:
public VoteAdmin(id, key, level, cid)
{
    if(!cmd_access(id, level, cid, 0))
        return PLUGIN_HANDLED;

    get_user_name(id, name, 23);

    client_print(0, print_chat, "%s changed mod to %s", name, menuBody[key]);
    server_print("%s changed mod to %s", name, menuBody[key]);
+   loaded = key;
    SetCvars(key);

    return PLUGIN_CONTINUE;
}
 
Сообщения
1,053
Реакции
212
Предупреждения
9
Помог
6 раз(а)
там ошибка из-за get_playersnum
 
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу