-
Notifications
You must be signed in to change notification settings - Fork 1
/
recsdm_shop.sma
414 lines (335 loc) · 11.6 KB
/
recsdm_shop.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <reapi>
/* ■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG START ■■■■■■■■■■■■■■■■■■■■■■■■■■■■ */
// ОПОВЕЩЕНИЕ В ЧАТ
#define ADVERT
#if defined ADVERT
#define ADVERT_TEXT "^3CSDM^4 магазин на букву ^3Ш^4, или пиши ^3/shop^4 в чат!"
new const Float:ADVERT_INTERVAL = 200.0; // каждые n секунд
#endif
// % выпадение рандомной возможности из магазина (при каждом респауне)
#define FREE_ITEM_CHANCE 5
#if defined FREE_ITEM_CHANCE
#define chance(%1) (%1 > random(100))
#endif
// МЕНЮ
enum any:MENU_DATA {MENU_NAME[128], MENU_PRICE, MENU_FLAG};
enum any:SERVICES_LIST {
SERVICE_SILENT_STEPS = 0,
SERVICE_BHOP,
SERVICE_GRAVITY,
SERVICE_200HP200AP,
SERVICE_FAST_RUN,
SERVICE_MULTIJUMP,
SERVICE_MOLOTOV,
SERVICE_OPACITY,
SERVICE_VAMPIRE,
SERVICE_AUTORELOAD,
SERVICE_RPG7
};
new const menuData[][MENU_DATA] = {
{"Тихий шаг", 1500, ADMIN_ALL},
{"Банни-хоп", 2000, ADMIN_ALL},
{"Гравитация", 2000, ADMIN_ALL},
{"200 HP + 200 AP", 3000, ADMIN_ALL},
{"Быстрый бег", 4000, ADMIN_ALL},
{"Двойной прыжок", 4500, ADMIN_ALL},
{"Молотов", 5000, ADMIN_ALL},
{"Полупрозрачность", 8000, ADMIN_ALL},
{"Вампиризм", 8000, ADMIN_ALL},
{"Автоперезарядка", 8000, ADMIN_ALL},
{"RPG-7", 10000, ADMIN_ALL}
};
new const menuCmds[][] = {
"say shop",
"say_team shop",
"say /shop",
"say_team /shop",
"say /csdm_shop",
"say_team /csdm_shop",
"shop",
"csdm_shop",
"showbriefing"
}
/* ■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG END ■■■■■■■■■■■■■■■■■■■■■■■■■■■■ */
enum any:HOOK_CHAINS {
HookChain:ON_SPAWN_EQUIP_POST,
HookChain:PLAYER_KILLED_POST,
HookChain:PLAYER_RESET_MAXSPEED_PRE,
HookChain:PLAYER_JUMP_PRE
};
new HookChain:hookChain[HOOK_CHAINS];
new menuId, menuId_Callback;
#if defined ADVERT
const TASK_ADVERT = 291;
#endif
new pActiveServices[MAX_CLIENTS + 1][sizeof menuData];
new pServiceMJ_jumps[MAX_CLIENTS + 1], pServiceMJ_jumpsDone[MAX_CLIENTS + 1];
new pServiceVampire_Hud;
// OUTISDE NATIVES
native isCsdmStarted();
native GiveRPG7(playerId);
native GiveUserMolotov(playerId);
native IsUserHasMolotov(playerId);
// PLUGIN INIT
public plugin_init() {
register_plugin("ReCSDM Shop", "1.0", "szawesome");
RegisterForwards();
}
// PLUGIN EXECUTE
public OnConfigsExecuted() {
if(isCsdmStarted()) {
EnableForwards();
BuildMenu();
#if defined ADVERT
set_task_ex(ADVERT_INTERVAL, "SendAdvertMessage", TASK_ADVERT, .flags = SetTask_Repeat);
#endif
pServiceVampire_Hud = CreateHudSyncObj();
} else {
pause("ad");
}
}
// FORWARDS
public client_putinserver(id) {
for(new i; i < sizeof menuData; i++) {
pActiveServices[id][i] = false;
}
}
public client_disconnected(id) {
for(new i; i < sizeof menuData; i++) {
pActiveServices[id][i] = false;
}
}
public CBasePlayer_Killed_Post(victim, killer, gibs) {
for(new i; i < sizeof menuData; i++) {
pActiveServices[victim][i] = false;
}
/*
Вроде-как само сбрасывается после смерти
rg_set_user_footsteps(victim, false);
set_entvar(victim, var_maxspeed, 250.0);
set_entvar(victim, var_gravity, 1.0);
*/
if(pActiveServices[killer][SERVICE_VAMPIRE]) {
if(victim == killer || !is_user_alive(killer)) {
return HC_CONTINUE;
}
new Float:killerHealth = Float:get_entvar(killer, var_health);
new Float:healthAdd = get_member(victim, m_bHeadshotKilled) ? 15.0 : 10.0;
set_entvar(killer, var_health, floatclamp(killerHealth + healthAdd, killerHealth, 100.0));
set_hudmessage(0, 255, 0, -1.0, 0.15, 0, 6.0, 2.0);
ShowSyncHudMsg(killer, pServiceVampire_Hud, "Вампиризм +%0.f HP", healthAdd);
}
if(pActiveServices[killer][SERVICE_AUTORELOAD]) {
if(victim == killer || !is_user_alive(killer)) {
return HC_CONTINUE;
}
rg_instant_reload_weapons(killer, 0);
}
return HC_CONTINUE;
}
#if defined FREE_ITEM_CHANCE
public CBasePlayer_OnSpawnEquip_Post(id, bool:addDefault, bool:equipGame) {
if(is_user_alive(id)) {
if(chance(FREE_ITEM_CHANCE)) {
new itemKey = random(sizeof menuData);
GiveItem(id, itemKey);
client_print_color(id, print_team_default, "^4Поздравляем! Ты получил ^3%s^4 с шансом ^3%d%%%^4!", menuData[itemKey][MENU_NAME], FREE_ITEM_CHANCE);
}
}
}
#endif
public CBasePlayer_ResetMaxSpeed_Pre(id) {
return pActiveServices[id][SERVICE_FAST_RUN] ? HC_SUPERCEDE : HC_CONTINUE;
}
public CBasePlayer_Jump_Pre(id) {
if(pActiveServices[id][SERVICE_BHOP]) {
new const iFlags = get_entvar(id, var_flags);
if(iFlags & FL_WATERJUMP || get_entvar(id, var_waterlevel) >= 2 || !(iFlags & FL_ONGROUND)) {
return HC_CONTINUE;
}
new Float:flVelocity[3];
get_entvar(id, var_velocity, flVelocity);
flVelocity[2] = 250.0;
set_entvar(id, var_velocity, flVelocity);
set_entvar(id, var_gaitsequence, 6);
set_entvar(id, var_fuser2, 0.0);
}
if(pActiveServices[id][SERVICE_MULTIJUMP]) {
new additionalJumps;
if(get_user_flags(id) & ADMIN_BAN) {
additionalJumps = 2;
} else {
additionalJumps = 1;
}
new iFlags = get_entvar(id, var_flags);
static Float:flJumpTime[MAX_CLIENTS + 1];
if (pServiceMJ_jumpsDone[id] && (iFlags & FL_ONGROUND)) {
pServiceMJ_jumpsDone[id] = 0;
flJumpTime[id] = get_gametime();
return HC_CONTINUE;
}
static Float:flGameTime;
if ((get_entvar(id, var_oldbuttons) & IN_JUMP || iFlags & FL_ONGROUND) || ((flGameTime = get_gametime()) - flJumpTime[id]) < 0.2) {
return HC_CONTINUE;
}
if (pServiceMJ_jumpsDone[id] >= additionalJumps && !pServiceMJ_jumps[id]) {
return HC_CONTINUE;
}
flJumpTime[id] = flGameTime;
new Float:flVelocity[3];
get_entvar(id, var_velocity, flVelocity);
flVelocity[2] = 275.0;
set_entvar(id, var_velocity, flVelocity);
pServiceMJ_jumpsDone[id]++;
if (pServiceMJ_jumps[id] && pServiceMJ_jumpsDone[id] > additionalJumps) {
pServiceMJ_jumps[id]--;
}
}
return HC_CONTINUE;
}
// CUSTOM FUNTIONS
#if defined ADVERT
public SendAdvertMessage() {
client_print_color(0, print_team_default, ADVERT_TEXT);
}
#endif
RegisterForwards() {
#if defined FREE_ITEM_CHANCE
DisableHookChain(hookChain[ON_SPAWN_EQUIP_POST] = RegisterHookChain(RG_CBasePlayer_OnSpawnEquip, "CBasePlayer_OnSpawnEquip_Post", true));
#endif
DisableHookChain(hookChain[PLAYER_KILLED_POST] = RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", true));
DisableHookChain(hookChain[PLAYER_RESET_MAXSPEED_PRE] = RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "CBasePlayer_ResetMaxSpeed_Pre", false));
DisableHookChain(hookChain[PLAYER_JUMP_PRE] = RegisterHookChain(RG_CBasePlayer_Jump, "CBasePlayer_Jump_Pre", false));
}
EnableForwards() {
for(new i; i < sizeof hookChain; i++) {
if(hookChain[i]) {
EnableHookChain(hookChain[i]);
}
}
}
BuildMenu() {
for(new i = 0; i < sizeof menuCmds; i++) {
register_clcmd(menuCmds[i], "ShowMenu");
}
menuId = menu_create("\r[CSDM]\w Магазин", "menuIdHandler");
menuId_Callback = menu_makecallback("menuIdCallback");
new menuName[128], menuKey[sizeof menuData];
for(new i = 0; i < sizeof menuData; i++) {
if(menuData[i][MENU_PRICE] < 1) continue;
num_to_str(i, menuKey, charsmax(menuKey));
formatex(menuName, charsmax(menuName), "%s \r[%d$]\w", menuData[i][MENU_NAME], menuData[i][MENU_PRICE]);
menu_additem(menuId, menuName, menuKey, menuData[i][MENU_FLAG], menuId_Callback);
}
menu_setprop(menuId, MPROP_BACKNAME, "Назад");
menu_setprop(menuId, MPROP_NEXTNAME, "Далее");
menu_setprop(menuId, MPROP_EXITNAME, "Выход");
menu_setprop(menuId, MPROP_PERPAGE, 7);
menu_setprop(menuId, MPROP_EXIT, MEXIT_ALL);
menu_setprop(menuId, MPROP_NUMBER_COLOR, "\w");
}
public menuIdCallback(id, menu, item) {
if(item < 0) {
return PLUGIN_HANDLED;
}
new key[sizeof menuData], name[128], access, callback;
menu_item_getinfo(menu, item, access, key, sizeof key, name, sizeof name - 1, callback);
new playerMoney = get_member(id, m_iAccount);
new menuPrice = menuData[str_to_num(key)][MENU_PRICE];
new menuNewItemName[128];
// menu_item_setname меняет название пункта навсегда, поэтому надо возвращать по дефолту вот так:
formatex(menuNewItemName, charsmax(menuNewItemName), "%s \r[%d$]\w", menuData[item][MENU_NAME], menuData[item][MENU_PRICE]);
menu_item_setname(menu, item, menuNewItemName);
// а потом уже отображать состояние пунктов:
if(pActiveServices[id][item]) {
formatex(menuNewItemName, charsmax(menuNewItemName), "%s \r[\yактивировано\r]\w", menuData[item][MENU_NAME]);
menu_item_setname(menu, item, menuNewItemName);
return ITEM_DISABLED;
}
if(playerMoney < menuPrice) {
return ITEM_DISABLED;
}
return ITEM_IGNORE;
}
public menuIdHandler(id, menu, item) {
if(!is_user_alive(id)) {
return PLUGIN_HANDLED;
}
if(item == MENU_EXIT || item < 0) {
return PLUGIN_HANDLED;
}
new key[sizeof menuData], name[128], access, callback;
menu_item_getinfo(menu, item, access, key, sizeof key, name, sizeof name - 1, callback);
if(GiveItem(id, item)) {
rg_add_account(id, -menuData[item][MENU_PRICE], AS_ADD);
client_print_color(id, print_team_default, "^4Ты купил ^3%s^4!", menuData[item][MENU_NAME]);
}
return PLUGIN_HANDLED;
}
public ShowMenu(id) {
if(!is_user_alive(id)) {
return PLUGIN_HANDLED;
}
return menu_display(id, menuId, 0);
}
GiveItem(id, key) {
if(!is_user_alive(id)) {
return PLUGIN_HANDLED;
}
if(key < 0) {
return PLUGIN_HANDLED;
}
switch(key) {
case SERVICE_SILENT_STEPS: {
// SERVICE_SILENT_STEPS
rg_set_user_footsteps(id, true);
}
case SERVICE_BHOP: {
// SERVICE_BHOP
}
case SERVICE_GRAVITY: {
// SERVICE_GRAVITY
set_entvar(id, var_gravity, 0.5);
}
case SERVICE_FAST_RUN: {
// SERVICE_FAST_RUN
set_entvar(id, var_maxspeed, 400.0);
}
case SERVICE_200HP200AP: {
// SERVICE_200HP200AP
set_entvar(id, var_health, 200.0);
rg_set_user_armor(id, 200, ARMOR_VESTHELM);
}
case SERVICE_MULTIJUMP: {
// SERVICE_MULTIJUMP
}
case SERVICE_MOLOTOV: {
// SERVICE_MOLOTOV
if(IsUserHasMolotov(id)) {
client_print(id, print_center, "#Cstrike_TitlesTXT_Already_Have_One");
return false;
}
GiveUserMolotov(id);
}
case SERVICE_OPACITY: {
// SERVICE_OPACITY
set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 50);
}
case SERVICE_VAMPIRE: {
// SERVICE_VAMPIRE
}
case SERVICE_AUTORELOAD: {
// SERVICE_AUTORELOAD
}
case SERVICE_RPG7: {
// SERVICE_RPG7
GiveRPG7(id);
}
default: return false;
}
pActiveServices[id][key] = true;
return true;
}