Skip to content

Commit 5e44e94

Browse files
committed
advanced_lists: initial release
1 parent 9741540 commit 5e44e94

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include <amxmodx>
2+
#include <map_manager>
3+
4+
#if AMXX_VERSION_NUM < 183
5+
#include <colorchat>
6+
#endif
7+
8+
#define PLUGIN "Map Manager: Advanced lists"
9+
#define VERSION "0.0.1"
10+
#define AUTHOR "Mistrick"
11+
12+
new const FILE_MAP_LISTS[] = "maplists.ini";
13+
14+
enum (+=100) {
15+
TASK_CHECK_LIST = 150
16+
};
17+
18+
enum _:MapListInfo {
19+
StartTime,
20+
StopTime,
21+
ClearOldList,
22+
FileList[256]
23+
};
24+
25+
new Array:g_aLists;
26+
new g_iCurList = -1;
27+
28+
public plugin_init()
29+
{
30+
register_plugin(PLUGIN, VERSION, AUTHOR);
31+
}
32+
public plugin_cfg()
33+
{
34+
new file_path[256]; get_localinfo("amxx_configsdir", file_path, charsmax(file_path));
35+
format(file_path, charsmax(file_path), "%s/%s", file_path, FILE_MAP_LISTS);
36+
37+
if(!file_exists(file_path)) {
38+
set_fail_state("Maplists file doesn't exist.");
39+
}
40+
41+
new f = fopen(file_path, "rt");
42+
43+
if(!f) {
44+
set_fail_state("Can't read maplists file.");
45+
}
46+
47+
// <start> <stop> <filename> <clear old list>
48+
49+
g_aLists = ArrayCreate(MapListInfo, 1);
50+
51+
new list_info[MapListInfo];
52+
new text[256], start[6], stop[6], file_list[128], clr[4]
53+
while(!feof(f)) {
54+
fgets(f, text, charsmax(text));
55+
trim(text);
56+
57+
if(!text[0] || text[0] == ';') continue;
58+
59+
parse(text, start, charsmax(start), stop, charsmax(stop), file_list, charsmax(file_list), clr, charsmax(clr));
60+
61+
list_info[StartTime] = get_int_time(start);
62+
list_info[StopTime] = get_int_time(stop);
63+
list_info[ClearOldList] = str_to_num(clr);
64+
copy(list_info[FileList], charsmax(list_info[FileList]), file_list);
65+
66+
ArrayPushArray(g_aLists, list_info);
67+
68+
// server_print("%d %d %s %d", list_info[StartTime], list_info[StopTime], list_info[FileList], list_info[ClearOldList]);
69+
}
70+
fclose(f);
71+
72+
if(!ArraySize(g_aLists)) {
73+
// pause plugin?
74+
}
75+
76+
task_check_list();
77+
set_task(60.0, "task_check_list", TASK_CHECK_LIST, .flags = "b");
78+
}
79+
public task_check_list()
80+
{
81+
new hours, mins; time(hours, mins);
82+
new cur_time = hours * 60 + mins;
83+
84+
new list_info[MapListInfo];
85+
86+
for(new i, found_newlist, size = ArraySize(g_aLists); i < size; i++) {
87+
ArrayGetArray(g_aLists, i, list_info);
88+
89+
if(list_info[StartTime] <= list_info[StopTime]) {
90+
if(g_iCurList != i && list_info[StartTime] <= cur_time <= list_info[StopTime]) {
91+
found_newlist = true;
92+
}
93+
} else {
94+
if(g_iCurList != i && (list_info[StartTime] <= cur_time <= 24 * 60 || cur_time <= list_info[StopTime])) {
95+
found_newlist = true;
96+
}
97+
}
98+
99+
if(found_newlist) {
100+
found_newlist = false;
101+
g_iCurList = i;
102+
mapm_load_maplist(list_info[FileList], list_info[ClearOldList]);
103+
log_amx("loaded new maplist[%s]", list_info[FileList]);
104+
}
105+
}
106+
}
107+
get_int_time(string[])
108+
{
109+
new left[4], right[4]; strtok(string, left, charsmax(left), right, charsmax(right), ':');
110+
return str_to_num(left) * 60 + str_to_num(right);
111+
}

0 commit comments

Comments
 (0)