Skip to content

Commit 75915aa

Browse files
committed
core: add cvar mapm_only_external_vote_items
add priority support in native mapm_add_map_to_list
1 parent 72034ac commit 75915aa

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

addons/amxmodx/configs/map_manager.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ mapm_vote_time "10"
3939
// По умолчанию пункты начинаются с 1, ставите квар равным 4 и начало будет с 5.
4040
mapm_vote_item_offset "0"
4141

42+
// Блокирует встроенное в ядро добавление карт в голосование.
43+
// При "1" можно добиться жесткого ограничения карт по текущему онлайну при голосовании,
44+
// если вклчен аддон "Online Sorter"
45+
mapm_only_external_vote_items "0"
46+
4247

4348
// Scheduler
4449

addons/amxmodx/scripting/include/map_manager.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ native mapm_block_load_maplist();
5252
* @param name Map name
5353
* @param minplayers Min players for sort
5454
* @param maxplayers Max players for sort
55+
* @param priority Map priority
5556
*
5657
* @return 0 if invalid map or already in array
5758
*/
58-
native mapm_add_map_to_list(name[], minplayers = 0, maxplayers = 32);
59+
native mapm_add_map_to_list(name[], minplayers = 0, maxplayers = 32, priority = 0);
5960

6061
/**
6162
* Get map index in mapslist array.

addons/amxmodx/scripting/map_manager_core.sma

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#endif
88

99
#define PLUGIN "Map Manager: Core"
10-
#define VERSION "3.0.9"
10+
#define VERSION "3.0.10"
1111
#define AUTHOR "Mistrick"
1212

1313
#pragma semicolon 1
@@ -50,7 +50,8 @@ enum Cvars {
5050
RANDOM_NUMS,
5151
PREPARE_TIME,
5252
VOTE_TIME,
53-
VOTE_ITEM_OFFSET
53+
VOTE_ITEM_OFFSET,
54+
ONLY_EXTERNAL_VOTE_ITEMS
5455
};
5556

5657
new g_pCvars[Cvars];
@@ -72,7 +73,7 @@ new g_iShowPercent;
7273
new g_bShowSelects;
7374
new g_iTimer;
7475
new g_bCanExtend;
75-
new g_iMaxItems;
76+
new g_iExternalMaxItems;
7677
new g_iCurMap;
7778

7879
new g_iRandomNums[MAX_VOTELIST_SIZE + 1];
@@ -100,6 +101,7 @@ public plugin_init()
100101
g_pCvars[PREPARE_TIME] = register_cvar("mapm_prepare_time", "5"); // seconds
101102
g_pCvars[VOTE_TIME] = register_cvar("mapm_vote_time", "10"); // seconds
102103
g_pCvars[VOTE_ITEM_OFFSET] = register_cvar("mapm_vote_item_offset", "0");
104+
g_pCvars[ONLY_EXTERNAL_VOTE_ITEMS] = register_cvar("mapm_only_external_vote_items", "0");
103105

104106
g_hForwards[MAPLIST_LOADED] = CreateMultiForward("mapm_maplist_loaded", ET_IGNORE, FP_CELL, FP_STRING);
105107
g_hForwards[MAPLIST_UNLOADED] = CreateMultiForward("mapm_maplist_unloaded", ET_IGNORE);
@@ -187,7 +189,8 @@ public native_add_map_to_list(plugin, params)
187189
enum {
188190
arg_name = 1,
189191
arg_minplayers,
190-
arg_maxplayers
192+
arg_maxplayers,
193+
arg_priority
191194
};
192195

193196
new map_info[MapStruct];
@@ -199,6 +202,10 @@ public native_add_map_to_list(plugin, params)
199202

200203
map_info[MinPlayers] = get_param(arg_minplayers);
201204
map_info[MaxPlayers] = get_param(arg_maxplayers);
205+
206+
new priority = clamp(get_param(arg_priority), 0, 100);
207+
map_info[MapPriority] = priority ? priority : 100;
208+
202209
ArrayPushArray(g_aMapsList, map_info);
203210

204211
return 1;
@@ -237,15 +244,15 @@ public native_block_show_vote(plugin, params)
237244
}
238245
public native_get_votelist_size(plugin, params)
239246
{
240-
if(g_iMaxItems) {
241-
return g_iMaxItems;
247+
if(g_iExternalMaxItems) {
248+
return g_iExternalMaxItems;
242249
}
243250
return min(min(get_num(VOTELIST_SIZE), MAX_VOTELIST_SIZE), ArraySize(g_aMapsList));
244251
}
245252
public native_set_votelist_max_items(plugin, params)
246253
{
247254
enum { arg_value = 1 };
248-
g_iMaxItems = get_param(arg_value);
255+
g_iExternalMaxItems = get_param(arg_value);
249256
}
250257
public native_push_map_to_votelist(plugin, params)
251258
{
@@ -255,7 +262,7 @@ public native_push_map_to_votelist(plugin, params)
255262
arg_ignore_check
256263
};
257264

258-
if(g_iMaxItems && g_iVoteItems >= g_iMaxItems) {
265+
if(g_iExternalMaxItems && g_iVoteItems >= g_iExternalMaxItems) {
259266
return PUSH_CANCELED;
260267
}
261268

@@ -446,12 +453,12 @@ prepare_vote(type)
446453
new ret;
447454
ExecuteForward(g_hForwards[PREPARE_VOTELIST], ret, type);
448455

449-
if(g_iMaxItems) {
450-
vote_max_items = g_iMaxItems;
451-
g_iMaxItems = 0;
456+
if(g_iExternalMaxItems) {
457+
vote_max_items = g_iExternalMaxItems;
458+
g_iExternalMaxItems = 0;
452459
}
453460

454-
if(g_iVoteItems < vote_max_items) {
461+
if(!get_num(ONLY_EXTERNAL_VOTE_ITEMS) && g_iVoteItems < vote_max_items) {
455462
new map_info[MapStruct];
456463
for(new random_map; g_iVoteItems < vote_max_items; g_iVoteItems++) {
457464
do {
@@ -463,6 +470,10 @@ prepare_vote(type)
463470
}
464471
}
465472

473+
if(!g_iVoteItems) {
474+
log_amx("Started vote with ZERO items. Check your maps list!");
475+
}
476+
466477
ExecuteForward(g_hForwards[CAN_BE_EXTENDED], ret, type);
467478
g_bCanExtend = !ret;
468479

0 commit comments

Comments
 (0)