-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzp_bot_buy_extra_items.sma
204 lines (173 loc) · 5.35 KB
/
zp_bot_buy_extra_items.sma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <amxmodx>
#include <amxmisc>
#include <zombieplague>
#define PLUGIN_VERSION "0.5"
#define EXTRA_ITEM_NAME_LENGTH 64
#define EXTRA_ITEM_NAME_LENGTH_DOUBLE EXTRA_ITEM_NAME_LENGTH * 2
#define EXTRA_TASK_ID 532
new Array:ListOfExtraItems
#define EXTRA_FREE "zp_bot_buy_extra_item_for_free"
// https://github.com/EfeDursun125/AMXX-ZP-Bot-Buy-Extra-Items
// use this to save bots ammo packs
#define EXTRA_TIME_MIN "zp_bot_buy_extra_item_time_min"
#define EXTRA_TIME_MAX "zp_bot_buy_extra_item_time_max"
public plugin_init()
{
register_plugin("[ZP] Bot Buy Extra Items", PLUGIN_VERSION, "EfeDursun125")
register_cvar("zp_bot_buy_extra_item_version", PLUGIN_VERSION)
register_cvar(EXTRA_FREE, "0")
register_cvar(EXTRA_TIME_MIN, "10.0")
register_cvar(EXTRA_TIME_MAX, "60.0")
register_concmd("zp_bot_buy_extra_item_list", "cmd_list_extra", _, "Lists the all detected extra items bots can buy", 0)
}
public plugin_cfg()
{
load_data()
}
public plugin_end()
{
ArrayDestroy(ListOfExtraItems)
}
public zp_round_started(gamemode, id)
{
new i
new maxPlayers = get_maxplayers() + 1
new Float:min = get_cvar_float(EXTRA_TIME_MIN)
new Float:max = get_cvar_float(EXTRA_TIME_MAX)
for (i = 1; i < maxPlayers; i++)
{
if (!is_user_connected(i))
continue
if (!is_user_bot(i))
continue
set_task(random_float(min, max), "bot_buy_extra_item", i + EXTRA_TASK_ID)
}
}
public bot_buy_extra_item(id)
{
if (ArraySize(ListOfExtraItems) <= 0)
{
set_fail_state("ERROR: we failed to find extra items...")
return
}
id -= EXTRA_TASK_ID
if (!is_user_alive(id))
return
if (!is_user_bot(id))
return
if (!zp_has_round_started())
{
set_task(random_float(get_cvar_float(EXTRA_TIME_MIN), get_cvar_float(EXTRA_TIME_MAX)), "bot_buy_extra_item", id + EXTRA_TASK_ID)
return
}
if (zp_force_buy_extra_item(id, ArrayGetCell(ListOfExtraItems, random_num(0, ArraySize(ListOfExtraItems) - 1)), get_cvar_num(EXTRA_FREE)))
{
// rarely get one more %33.333
if (random_num(1, 3) == 1)
set_task(random_float(get_cvar_float(EXTRA_TIME_MIN), get_cvar_float(EXTRA_TIME_MAX)), "bot_buy_extra_item", id + EXTRA_TASK_ID)
}
else
{
// try to buy something else %67.777
if (random_num(1, 3) != 1)
set_task(random_float(get_cvar_float(EXTRA_TIME_MIN), get_cvar_float(EXTRA_TIME_MAX)), "bot_buy_extra_item", id + EXTRA_TASK_ID)
}
}
public load_data()
{
ListOfExtraItems = ArrayCreate(1, 1)
new path[256]
get_configsdir(path, charsmax(path))
formatex(path, charsmax(path), "%s/zp_extraitems.ini", path)
new file = fopen(path, "rt")
if (!file)
{
// are we using zpsp?
get_configsdir(path, charsmax(path))
formatex(path, charsmax(path), "%s/zpsp_extraitems.ini", path)
file = fopen(path, "rt")
if (!file)
{
// latest version?
get_configsdir(path, charsmax(path))
formatex(path, charsmax(path), "%s/zpsp_configs/zpsp_extraitems.ini", path)
file = fopen(path, "rt")
if (!file)
{
set_fail_state("ERROR: zp_extraitems.ini is not found, plugin works by reading zp_extraitems.ini | you can put latest copy of zp_extraitems.ini to configs folder, don't forget to update the copy when you add new extra items.")
return
}
}
}
new id
new lineText[EXTRA_ITEM_NAME_LENGTH_DOUBLE], left[EXTRA_ITEM_NAME_LENGTH], right[EXTRA_ITEM_NAME_LENGTH]
while (!feof(file))
{
fgets(file, lineText, EXTRA_ITEM_NAME_LENGTH_DOUBLE)
replace(lineText, EXTRA_ITEM_NAME_LENGTH_DOUBLE, "^n", "")
if (!lineText[0] || lineText[0] == ';')
continue
trim(lineText)
strtok(lineText, left, EXTRA_ITEM_NAME_LENGTH_DOUBLE, right, EXTRA_ITEM_NAME_LENGTH, '=')
trim(left)
if (!equal(left, "NAME"))
continue
trim(right)
id = zp_get_extra_item_id(right)
if (id != -1)
ArrayPushCell(ListOfExtraItems, id)
}
fclose(file)
}
public cmd_list_extra(id, level, cid)
{
if (!cmd_access(id, ADMIN_KICK, cid, 1))
return PLUGIN_HANDLED
// if extra item id list is 0, we cannot write the extra item names
if (ArraySize(ListOfExtraItems) <= 0)
{
console_print(id, "ERROR: NO EXTRA ITEMS FOUND!")
return PLUGIN_HANDLED
}
new path[256]
get_configsdir(path, charsmax(path))
formatex(path, charsmax(path), "%s/zp_extraitems.ini", path)
new file = fopen(path, "rt")
if (!file)
{
// are we using zpsp?
get_configsdir(path, charsmax(path))
formatex(path, charsmax(path), "%s/zpsp_extraitems.ini", path)
file = fopen(path, "rt")
if (!file)
{
// latest version?
get_configsdir(path, charsmax(path))
formatex(path, charsmax(path), "%s/zpsp_configs/zpsp_extraitems.ini", path)
file = fopen(path, "rt")
if (!file)
{
console_print(id, "ERROR: NO EXTRA ITEM INI FILE FOUND!")
return PLUGIN_HANDLED
}
}
}
new id
new lineText[EXTRA_ITEM_NAME_LENGTH_DOUBLE], left[EXTRA_ITEM_NAME_LENGTH], right[EXTRA_ITEM_NAME_LENGTH]
while (!feof(file))
{
fgets(file, lineText, EXTRA_ITEM_NAME_LENGTH_DOUBLE)
replace(lineText, EXTRA_ITEM_NAME_LENGTH_DOUBLE, "^n", "")
if (!lineText[0] || lineText[0] == ';')
continue
trim(lineText)
strtok(lineText, left, EXTRA_ITEM_NAME_LENGTH_DOUBLE, right, EXTRA_ITEM_NAME_LENGTH, '=')
trim(left)
if (!equal(left, "NAME"))
continue
trim(right)
console_print(id, "--> %s", right)
}
fclose(file)
return PLUGIN_HANDLED
}