· 6 years ago · Oct 08, 2019, 05:46 PM
1/* Plugin generated by AMXX-Studio */
2/* -------------------------------------------------------------------------------------------------
3
4 _____ __ ___ _ __ ____ ____ ___ ____ ____
5 /__ / / |/ / | | / // _// __ \ |__ \ / __ \ / __ \
6 / / / /|_/ / | | / / / / / /_/ / __/ / / / / / / / / /
7 / /__ / / / / | |/ /_/ / / ____/ / __/ _ / /_/ /_ / /_/ /
8 /____//_/ /_/ |___//___//_/ /____/(_)\____/(_)\____/
9 BETA VERSION!!!
10
11 Zombie Plague 4.3/5.0 Addon
12 ZM VIP - Zombie Plague VIP addon that enables special abilities for players
13 and adds VIP system, status and API to server.
14
15 Official thread: https://forums.alliedmods.net/showthread.php?t=119719
16
17 Author: aaarnas
18
19--------------------------------------------------------------------------------------------------*/
20
21// Ignore thease. Just values for settings.
22#define OFF 0
23#define ON 1
24#define FORCED 2
25#define NEW 1
26#define OLD 2
27#define VAULT 1
28
29#define VERSION "1.9.1 BETA"
30
31// --------------- USER CONFIGURATION START --------------- USER CONFIGURATION START ---------------
32// --------------- USER CONFIGURATION START --------------- USER CONFIGURATION START ---------------
33// --------------- USER CONFIGURATION START --------------- USER CONFIGURATION START ---------------
34// --------------- USER CONFIGURATION START --------------- USER CONFIGURATION START ---------------
35// -------------------------------------------------------------------------------------------------
36// Choose your using zombie plague version:
37// NEW - Zombie Plague 5.0 or later. (zp_plugin_50.zip | zp508a.zip and later ... )
38// OLD - Zombie Plague 4.3 or earlier. (zp_plugin_43.zip)
39// Zombie Plague Advanced - Not supported.
40// Daugiau pluginu https://forums.alliedmods.net/showthread.php?t=242196?t=242196
41
42#define MODIFICATION NEW
43// -------------------------------------------------------------------------------------------------
44// Set wich system to use loading privileges:
45// FORCED - Just vips.ini file. Ignores amxmodx.
46// ON - vips.ini and amxmodx (users.ini/database (flag t))
47// OFF - Disables vips.ini file and reads only from amxmodx (users.ini/database (flag t))
48#define VIPS_FILE_SYSTEM ON
49// -------------------------------------------------------------------------------------------------
50// Set if you want to enable extra items menu system (/vm)
51// ON - Enabled
52// OFF - Dissabled
53#define EXTRA_ITEMS ON
54// -------------------------------------------------------------------------------------------------
55// Vip privileges flag in users.ini file (t) if NOT using VIPS_FILE_SYSTEM [FORCED] mode.
56#define VIP_SYS_FLAG ADMIN_LEVEL_H
57// -------------------------------------------------------------------------------------------------
58// Admin flag (from users.ini). Allow access to VIP admin panel, zm_vip_freevip_hour cvar(cmd).
59#define ADMIN_SYS_FLAG ADMIN_LEVEL_E //(ADMIN_LEVEL_E flag is "q")
60// -------------------------------------------------------------------------------------------------
61// Name of configs/vips.ini|zm_cip.cfg file. In fact, no reason to change.
62#define VIPS_FILE "vips.ini"
63#define CONFIGS_FILE "zm_vip.cfg"
64// -------------------------------------------------------------------------------------------------
65//--------------- USER CONFIGURATION END --------------- USER CONFIGURATION END ---------------
66//--------------- USER CONFIGURATION END --------------- USER CONFIGURATION END ---------------
67//--------------- USER CONFIGURATION END --------------- USER CONFIGURATION END ---------------
68//--------------- USER CONFIGURATION END --------------- USER CONFIGURATION END ---------------
69//--------------- USER CONFIGURATION END --------------- USER CONFIGURATION END ---------------
70//////////////////////////// Editing anyting further - taking own risk /////////////////////////////
71////////// This means - no support. Using/stealing anything without credits - not allowed //////////
72
73#define EMPTY(%1) (%1[0]==EOS)
74#define BIT(%1) (1<<%1)
75#define FLAG_A (1<<0)
76#define FLAG_B (1<<1)
77#define FLAG_C (1<<2)
78#define FLAG_D (1<<3)
79#define FLAG_E (1<<4)
80#define FLAG_F (1<<4)
81#define FLAG_K (1<<10)
82#define FLAG_N (1<<13)
83
84#define LOAD_FROM_INI (1<<31)
85#define LOAD_FROM_DAT (1<<30)
86#define LOAD_FROM_AMX (1<<29)
87#define LOAD_FROM_NAMES (1<<28)
88#define LOAD_FROM_MAIN (1<<27)
89#define LOAD_MASK 0xFC000000
90
91#include <amxmodx>
92#include <amxmisc>
93#include <hamsandwich>
94#include <fakemeta>
95#include <engine>
96#include <fun>
97#include <regex>
98#if MODIFICATION == NEW
99#include <cstrike>
100#define ZP_ITEM_AVAILABLE 0
101#define ZP_ITEM_NOT_AVAILABLE 1
102#define ZP_ITEM_DONT_SHOW 2
103#define ZP_CLASS_AVAILABLE 0
104#define ZP_CLASS_NOT_AVAILABLE 1
105#define ZP_CLASS_DONT_SHOW 2
106native zp_core_is_zombie(id)
107forward zp_fw_core_spawn_post(id)
108forward zp_fw_core_infect_pre(id, attacker)
109forward zp_fw_core_infect_post(id, attacker)
110forward zp_fw_core_cure_post(id, attacker)
111native zp_ammopacks_get(id)
112native zp_ammopacks_set(id, amount)
113native zp_class_human_menu_text_add(const text[])
114forward zp_fw_class_human_select_pre(id, classid)
115native zp_class_human_register(const name[], const description[], health, Float:speed, Float:gravity)
116native zp_class_zombie_menu_text_add(const text[])
117forward zp_fw_class_zombie_select_pre(id, classid)
118native zp_class_zombie_register(const name[], const description[], health, Float:speed, Float:gravity)
119native zp_items_register(const name[], cost)
120forward zp_fw_items_select_pre(id, itemid, ignorecost)
121forward zp_fw_items_select_post(id, itemid, ignorecost)
122native zp_items_show_menu(id)
123native zp_items_menu_text_add(const text[])
124native cs_set_player_model(id, const model[])
125forward zp_fw_grenade_fire_pre(id)
126forward zp_fw_grenade_frost_pre(id)
127#else
128native zp_get_user_bombardier(id)
129#define ZP_TEAM_ANY 0
130native zp_get_user_zombie(id)
131native zp_get_user_next_class(id)
132native zp_set_user_zombie_class(id, classid)
133native zp_register_zombie_class(const name[], const info[], const model[], const clawmodel[], hp, speed, Float:gravity, Float:knockback)
134native zp_override_user_model(id, const newmodel[], modelindex = 0)
135native zp_get_user_nemesis(id)
136native zp_get_user_survivor(id)
137forward zp_user_infect_attempt(id, infector, nemesis)
138forward zp_user_infected_post(id, infector, nemesis)
139forward zp_user_humanized_post(id, survivor)
140forward zp_user_infected_pre(id, infector, nemesis)
141forward zp_extra_item_selected(id, itemid)
142forward zp_round_started(gamemode, id)
143native zp_register_extra_item(const name[], cost, teams)
144native zp_force_buy_extra_item(id, itemid, ignorecost = 0)
145native zp_get_extra_item_id(const name[])
146native zp_get_user_ammo_packs(id)
147native zp_set_user_ammo_packs(id, amount)
148#define ZP_PLUGIN_HANDLED 97
149#endif
150
151new cvar_multijump, cvar_multijump_allow, cvar_armor, cvar_extra_hp_human, cvar_extra_hp_zombie,
152cvar_extra_gravity_human, cvar_extra_gravity_zombie ,cvar_unlimited_clip, cvar_no_fall_dmg,
153cvar_extra_dmg, cvar_extra_frags, cvar_extra_kill_ammo, cvar_extra_armor, cvar_extra_infect_ammo,
154cvar_extra_infect_health, cvar_extra_ignore_for_special, cvar_damage_reward, cvar_viponly_class,
155cvar_chat_viptag, cvar_vip_connected_to_server, cvar_freevip_flags, cvar_vipniscoretable,
156cvar_grenades_immunity, cvar_gamemode_disable_flags
157#if VIPS_FILE_SYSTEM != FORCED
158new cvar_amx_auth_flags
159#endif
160#if VIPS_FILE_SYSTEM != OFF
161new cvar_vip_store_ini
162#endif
163new cvar_amxmodx_flags, cvar_vip_price, cvar_vip_buy_duration, cvar_vip_buy_flags,
164cvar_vip_buy_in_extra_items
165
166#if EXTRA_ITEMS == ON
167new cvar_buys_per_round
168#if MODIFICATION == OLD
169new chached_show_vip_items
170#else
171new cvar_vip_show_vip_items
172#endif
173#endif
174
175enum _:player_attributes
176{
177 AT_MULTIJUMP, //a(0)
178 AT_ARMOR, //b(1)
179 AT_UNLIMITED_CLIP, //c(2)
180 AT_NO_FALL_DMG, //d(3)
181 AT_DAMAGE_REWARD, //e(4)
182 AT_EXTRA_DMG, //f(5)
183 AT_EXTRA_HP, //g(6)
184 AT_EXTRA_GRAVITY, //h(7)
185 AT_EXTRA_FRAGS, //i(8)
186 AT_EXTRA_KILL_AMMO, //j(9)
187 AT_EXTRA_ARMOR, //k(10)
188 AT_EXTRA_INFECT_AMMO, //l(11)
189 AT_EXTRA_INFECT_HEALTH, //m(12)
190 AT_EXTRA_ITEMS, //n(13)
191 AT_VIP_MODEL, //o(14)
192 AT_VIP_CLASS, //p(15)
193 AT_CHATTAG, //q(16)
194 AT_VIPINSCORE, //r(17)
195 AT_GRENADE_IMMUNITY //s(18)
196}
197
198new p_attribs[33][player_attributes]
199
200#define AT_NONE (1<<25) // z
201
202#define ZV_DURATION_IGNORE -1
203#define ZV_DURATION_PERMANENT 0
204#define ZV_DURATION_TILL_DISCONNECT ~'t'
205#define ZV_DURATION_TILL_MAP ~('t'|'m')
206
207enum ClassType:cltypes {
208 EXTRA_ITEM = 1,
209 CLASS_ZOMBIE,
210 CLASS_HUMAN
211}
212#define VipsItemHandle trie_vip_items
213new Trie:trie_vip_items
214
215new p_bought_per_round[33]
216new bool:p_zombie[33]
217new p_jumpsnum[33]
218new Float:p_damage[33]
219new Float:p_grenade_time[33]
220
221new p_vip_model_zombie[15]
222new p_vip_model_human[15]
223
224new is_amxmodx_new_version
225#if MODIFICATION == NEW
226new is_module_ammopacks_loaded
227#endif
228
229new Trie:trie_vips_database
230new Array:array_vips_database
231new Array:array_vips_database_nick
232new amx_password_field_string[30]
233enum _:VipCnt {
234
235 INI,
236 DAT,
237 MAIN,
238 NAMES,
239 AMX
240}
241new total_vips_count[VipCnt] //0 - main, 1 - names, 2 - amx
242#define VIPCNT(%1) total_vips_count[%1]
243#define VIPINC(%1) total_vips_count[%1]++
244#define VIPDEC(%1) total_vips_count[%1]--
245enum _:vips_database_type
246{
247 AUTH[40],
248 PASS[30],
249 SETTINGS,
250 FLAGS,
251 TIMESTAMP,
252 INDEX
253}
254new p_data[33][vips_database_type]
255
256#if EXTRA_ITEMS == ON
257new registered_extra_items_num
258#if MODIFICATION == NEW
259new bool:p_views_extra_items_menu[33]
260#else
261enum _:item_struct {
262
263 item_plid,
264 item_name[100],
265 item_cost,
266 item_team
267}
268#define ZP_TEAM_ZOMBIE (1<<0)
269#define ZP_TEAM_HUMAN (1<<1)
270#define ZP_TEAM_NEMESIS (1<<2)
271#define ZP_TEAM_SURVIVOR (1<<3)
272new Array:array_vip_extra_items
273new fw_extraitemselected
274#endif
275#endif
276
277new vip_buy_extra_item = -1
278
279new current_gamemode
280
281new bool:freevip_enabled
282new bool:freevip_inform[33]
283new bool:first_spawn[33]
284new freevip_hours[4]
285new maxplayers
286new msg_saytext
287new msg_scoreattrib
288
289new const MAXCLIP[] = { -1, 13, -1, 10, 1, 7, -1, 30, 30, 1, 30, 20, 25, 30, 35, 25, 12, 20, 10, 30, 100, 8, 30, 30, 20, 2, 7, 30, 30, -1, 50 }
290
291#define IS_PLAYER(%1) (1<=%1<=maxplayers)
292#define ATTRIB(%1,%2) p_attribs[%1][%2]
293
294#define CURRENCY_MONEY 0
295#define CURRENCY_AMMO_PACKS 1
296public plugin_init() {
297
298 register_plugin("ZM VIP", VERSION, "aaarnas")
299 register_dictionary("zm_vip.txt")
300
301 new amxmodx_version[20], amxmodx_version_num
302 get_amxx_verstring(amxmodx_version, charsmax(amxmodx_version))
303 replace_all(amxmodx_version, charsmax(amxmodx_version), ".", "")
304 amxmodx_version_num = str_to_num(amxmodx_version)
305 is_amxmodx_new_version = amxmodx_version_num>=183
306
307 /////////////////////// CVARS REGISTRATION ///////////////////////
308 cvar_multijump = register_cvar("zm_vip_mutijump", "1")
309 cvar_multijump_allow = register_cvar("zm_vip_multijump_allow", "ab")
310 cvar_armor = register_cvar("zm_vip_armor", "65")
311 cvar_unlimited_clip = register_cvar("zm_vip_unlimited_clip", "0")
312 cvar_no_fall_dmg = register_cvar("zm_vip_no_fall_dmg", "1")
313 cvar_extra_dmg = register_cvar("zm_vip_extra_dmg", "1.2")
314 cvar_extra_hp_human = register_cvar("zm_vip_extra_hp_human", "50")
315 cvar_extra_hp_zombie = register_cvar("zm_vip_extra_hp_zombie", "500")
316 cvar_extra_gravity_human = register_cvar("zm_vip_extra_gravity_human", "0")
317 cvar_extra_gravity_zombie = register_cvar("zm_vip_extra_gravity_zombie", "0")
318 cvar_extra_frags = register_cvar("zm_vip_extra_frags", "0")
319 cvar_extra_kill_ammo = register_cvar("zm_vip_extra_kill_ammo", "1")
320 cvar_extra_armor = register_cvar("zm_vip_extra_armor", "0")
321 cvar_extra_infect_ammo = register_cvar("zm_vip_extra_infect_ammo", "1")
322 cvar_extra_infect_health = register_cvar("zm_vip_extra_infect_health", "100")
323 cvar_extra_ignore_for_special = register_cvar("zm_vip_extra_ignore_for_special", "1")
324 cvar_damage_reward = register_cvar("zm_vip_damage_reward", "1000")
325 cvar_viponly_class = register_cvar("zm_viponly_class", "1")
326 cvar_chat_viptag = register_cvar("zm_vip_chattag", "1")
327 cvar_vip_connected_to_server = register_cvar("zm_vip_connected_to_server", "1") // 1-chat/2-hud/3-dhud
328 cvar_vipniscoretable = register_cvar("zm_vipinscoretable", "1")
329#if VIPS_FILE_SYSTEM != FORCED
330 cvar_amx_auth_flags = register_cvar("zm_vip_amx_auth_flags", "0")
331#endif
332 cvar_amxmodx_flags = register_cvar("zm_vip_amxmodx_flags", "t")
333 cvar_grenades_immunity = register_cvar("zm_vip_grenades_immunity", "0")
334 cvar_gamemode_disable_flags = register_cvar("zm_vip_gamemode_disable_flags", "0")
335 register_concmd("zm_vip_freevip_hour", "set_freevip_hour", ADMIN_CVAR)
336 cvar_freevip_flags = register_cvar("zm_vip_freevip_flags", "0")
337#if VIPS_FILE_SYSTEM != OFF
338 cvar_vip_store_ini = register_cvar("zm_vip_store_ini", "0")
339#endif
340 cvar_vip_price = register_cvar("zm_vip_price", "0")
341 cvar_vip_buy_duration = register_cvar("zm_vip_buy_duration", "1d") // 1h - val, 1d - day// t - tepm/ tm - temp till map
342
343 cvar_vip_buy_flags = register_cvar("zm_vip_buy_flags", "0")
344 cvar_vip_buy_in_extra_items = register_cvar("zm_vip_buy_in_extra_items", "1")
345
346#if EXTRA_ITEMS == ON
347 cvar_buys_per_round = register_cvar("zm_vip_buys_per_round", "0")
348#if MODIFICATION == NEW
349 cvar_vip_show_vip_items = register_cvar("zm_vip_show_vip_items", "2")
350#endif
351#if MODIFICATION != NEW
352 fw_extraitemselected = CreateMultiForward("zv_extra_item_selected", ET_CONTINUE, FP_CELL, FP_CELL)
353#endif
354#endif
355 maxplayers = get_maxplayers()
356
357 msg_saytext = get_user_msgid("SayText")
358 msg_scoreattrib = get_user_msgid("ScoreAttrib")
359
360 register_clcmd("say /vm", "show_vip_menu")
361 register_clcmd("open_vip_menu", "show_vip_menu_console")
362 register_clcmd("say /vip", "show_vip_info")
363 register_clcmd("say /vips", "show_vips_online")
364
365 register_concmd("zm_vip_list", "cmd_list_vips", ADMIN_SYS_FLAG)
366 register_concmd("amx_reloadvips", "cmd_vips_reload", ADMIN_SYS_FLAG)
367 register_concmd("zm_vip_reload", "cmd_vips_reload", ADMIN_SYS_FLAG)
368 register_concmd("zm_vip_remove", "cmd_vips_remove", ADMIN_SYS_FLAG)
369
370 register_menu("Menu Buy", MENU_KEY_0|MENU_KEY_1, "forward_buy_menu_handler")
371
372 register_event("HLTV", "forward_event_round_start", "a", "1=0", "2=0")
373 register_event("DeathMsg", "forward_event_deathmsg", "a")
374 register_event("ResetHUD", "forward_event_reset_hud", "be")
375 register_message(get_user_msgid("CurWeapon"), "message_cur_weapon")
376 register_message(msg_saytext, "message_say_text")
377 register_forward(FM_CmdStart, "forward_cmdstart")
378#if MODIFICATION != NEW
379 RegisterHam(Ham_Spawn, "player", "forward_player_spawn", 1)
380#endif
381 RegisterHam(Ham_TakeDamage, "player", "forward_player_takedamage_pre")
382 RegisterHam(Ham_TakeDamage, "player", "forward_player_takedamage_post", 1)
383 RegisterHam(Ham_Think, "grenade", "forward_grenade_think")
384
385 trie_vips_database = TrieCreate()
386 array_vips_database = ArrayCreate(45, 15)
387
388 register_cvar("zp_vip_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
389 set_cvar_string("zp_vip_version", VERSION)
390}
391
392
393public plugin_natives() {
394
395 register_library("zm_vip")
396
397 set_native_filter("native_filter")
398
399 register_native("zv_get_user_flags", "native_zv_get_user_flags")
400 register_native("zv_set_user_flags", "native_zv_set_user_flags")
401 register_native("zv_remove_user_flags", "native_zv_remove_user_flags")
402
403#if MODIFICATION == NEW
404#if EXTRA_ITEMS == ON
405 register_native("zv_items_register", "native_zv_items_register", 1)
406#endif
407 register_native("zv_class_human_register", "native_zv_class_human_register", 1)
408 register_native("zv_class_zombie_register", "native_zv_class_zombie_register", 1)
409#else
410 register_native("zv_register_zombie_class", "native_zv_register_zombie_class", 1)
411#if EXTRA_ITEMS == ON
412 register_native("zv_register_extra_item", "native_zv_register_extra_item", 1)
413 register_native("zv_register_extra_item2", "native_zv_register_extra_item2", 1)
414 register_native("zv_force_buy_extra_item", "native_zv_force_buy_extra_item", 1)
415 register_native("zv_get_extra_item_id", "native_zv_get_extra_item_id", 1)
416#endif
417#endif
418}
419#if MODIFICATION == NEW
420native zp_class_nemesis_get(id)
421native zp_class_survivor_get(id)
422native zp_class_assassin_get(id)
423native zp_class_sniper_get(id)
424#endif
425new natives_filter_out
426enum {
427 NATIVE_ZP_CLASS_NEMESIS_GET,
428 NATIVE_ZP_CLASS_SURVIVOR_GET,
429 NATIVE_ZP_CLASS_ASSASSIN_GET,
430 NATIVE_ZP_CLASS_SNIPER_GET,
431 NATIVE_ZP_CLASS_BOMBARDIER_GET,
432 NATIVE_OVERRIDE_USER_MODEL
433}
434public native_filter(const name[], index, trap) {
435
436 if (!trap) {
437#if MODIFICATION == NEW
438 if (equal(name, "zp_class_nemesis_get")) natives_filter_out |= BIT(NATIVE_ZP_CLASS_NEMESIS_GET)
439 else if(equal(name, "zp_class_survivor_get")) natives_filter_out |= BIT(NATIVE_ZP_CLASS_SURVIVOR_GET)
440 else if(equal(name, "zp_class_assassin_get")) natives_filter_out |= BIT(NATIVE_ZP_CLASS_ASSASSIN_GET)
441 else if(equal(name, "zp_class_sniper_get")) natives_filter_out |= BIT(NATIVE_ZP_CLASS_SNIPER_GET)
442#else
443 if (equal(name, "zp_get_user_bombardier")) natives_filter_out |= BIT(NATIVE_ZP_CLASS_BOMBARDIER_GET)
444#endif
445#if MODIFICATION == OLD
446 else if (equal(name, "zp_override_user_model")) {
447 p_vip_model_zombie[0] = EOS
448 p_vip_model_human[0] = EOS
449 log_amx("ERROR: Vip models are not compatible with old Zombie Plague 4.3 version. Use Zombie Plague 4.3 patched or 5.0 to enable this feature.")
450 log_amx("Download: https://forums.alliedmods.net/showthread.php?t=72505")
451 natives_filter_out |= BIT(NATIVE_OVERRIDE_USER_MODEL)
452 }
453 else if (equal(name, "zp_get_user_zombie")) {
454 set_fail_state("ERROR: This plugin compiled with MODIFICATION - OLD setting. \
455 This supports only Zombie plague 4.3 versions.^nPlugin was unable to\
456 detect this version, so probably, modification is incorrect.")
457 }
458#endif
459 else {
460 return PLUGIN_CONTINUE;
461 }
462 return PLUGIN_HANDLED;
463
464 }
465 return PLUGIN_CONTINUE;
466}
467
468public plugin_precache() {
469#if EXTRA_ITEMS == ON && MODIFICATION == OLD
470 new value_str[5]
471 read_config("zm_vip_show_vip_items", value_str, charsmax(value_str))
472 chached_show_vip_items = str_to_num(value_str)
473#endif
474#if MODIFICATION == NEW
475 read_config("zm_vip_model_zombie", p_vip_model_zombie, charsmax(p_vip_model_zombie))
476 read_config("zm_vip_model_human", p_vip_model_human, charsmax(p_vip_model_human))
477
478 if (!EMPTY(p_vip_model_zombie)) {
479
480 new model_path[128]
481 formatex(model_path, charsmax(model_path), "models/player/%s/%s.mdl", p_vip_model_zombie, p_vip_model_zombie)
482 precache_model(model_path)
483 formatex(model_path, charsmax(model_path), "models/player/%s/%sT.mdl", p_vip_model_zombie, p_vip_model_zombie)
484 if (file_exists(model_path)) precache_model(model_path)
485 }
486 if (!EMPTY(p_vip_model_human)) {
487
488 new model_path[128]
489 formatex(model_path, charsmax(model_path), "models/player/%s/%s.mdl", p_vip_model_human, p_vip_model_human)
490 precache_model(model_path)
491 formatex(model_path, charsmax(model_path), "models/player/%s/%sT.mdl", p_vip_model_human, p_vip_model_human)
492 if (file_exists(model_path)) precache_model(model_path)
493 }
494#endif
495}
496public plugin_cfg() {
497#if MODIFICATION == NEW
498
499 if (!LibraryExists("zp50_core", LibType_Library))
500 set_fail_state("ERROR: This plugin compiled with MODIFICATION - NEW setting. \
501 This supports only Zombie plague 5 version and higher.^nPlugin was unable to\
502 detect main Zombie Plague Core plugin.")
503
504 is_module_ammopacks_loaded = LibraryExists("zp50_ammopacks", LibType_Library)
505#endif
506 new file_link[45]
507 get_configsdir(file_link, charsmax(file_link))
508 format(file_link, charsmax(file_link), "%s/%s", file_link, CONFIGS_FILE)
509 if (file_exists(file_link)) {
510 server_cmd("exec %s", file_link)
511 server_exec()
512 }
513 else {
514 log_amx("WARNING: Missing ^"%s^" file in configs folder. Can't load cvars values.", CONFIGS_FILE)
515 }
516
517 get_cvar_string("amx_password_field", amx_password_field_string, charsmax(amx_password_field_string))
518#if VIPS_FILE_SYSTEM != OFF
519 load_ini_file()
520#endif
521 load_datafile()
522
523#if VIPS_FILE_SYSTEM != FORCED
524 new num = admins_num()
525 for (new i=0; i<num; i++) {
526 if (admins_lookup(i, AdminProp_Access)&VIP_SYS_FLAG) {
527 VIPINC(AMX)
528 }
529 }
530#endif
531 if (!VIPCNT(DAT) && !VIPCNT(INI) && !VIPCNT(AMX))
532 log_amx("WARNING: No VIPs loaded from zm_vip system. Maybe there aren't any.")
533
534 if (get_pcvar_num(cvar_vip_price) > 0 && get_pcvar_num(cvar_vip_buy_in_extra_items)) {
535
536 new buy_vip_text[30], langid = LANG_SERVER
537 LookupLangKey(buy_vip_text, charsmax(buy_vip_text), "BUY_VIP", langid)
538#if MODIFICATION == NEW
539 vip_buy_extra_item = zp_items_register(buy_vip_text, get_pcvar_num(cvar_vip_price))
540#else
541 vip_buy_extra_item = zp_register_extra_item(buy_vip_text, get_pcvar_num(cvar_vip_price), ZP_TEAM_ANY)
542#endif
543 }
544
545#if EXTRA_ITEMS == ON
546 if (!registered_extra_items_num)
547 log_amx("WARRNING: No vip extra item plugins loaded.")
548#endif
549 set_task(1.0, "vip_time_check", 0, _, _, "b")
550
551 server_print("-------------------------------------------------------------------------------")
552 server_print("This server using ZM VIP %s by aaarnas", VERSION)
553 server_print("Successfully loaded %d VIPs", VIPCNT(DAT)+VIPCNT(INI)+VIPCNT(AMX))
554 server_print("-------------------------------------------------------------------------------")
555}
556
557_get_pcvar_flags(pcvar) {
558
559 new flags[30]
560 get_pcvar_string(pcvar, flags, charsmax(flags))
561
562 if (flags[0] == '0')
563 return 0;
564
565 return read_flags(flags);
566}
567set_user_atribs(id, double_attrib_update = false) {
568
569 if (id == 0) return;
570
571 new hour_flags = 0
572
573 new gamemode_disable_flags = 0
574 if (current_gamemode != 0) {
575 gamemode_disable_flags = _get_pcvar_flags(cvar_gamemode_disable_flags)
576 }
577
578 if(freevip_enabled && freevip_hour_check()) {
579
580 hour_flags = _get_pcvar_flags(cvar_freevip_flags)
581 if (hour_flags == 0)
582 hour_flags = -1
583
584 if (!freevip_inform[id]) {
585 freevip_inform[id] = true
586 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L!", id, "FREE_VIP_GOT")
587 else _client_print_color(id, "^4[ZMVIP] ^1%L!", id, "FREE_VIP_GOT")
588 client_cmd(id, "spk /sound/buttons/bell1.wav")
589 }
590 }
591 else if (freevip_inform[id]) {
592 freevip_inform[id] = false
593 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L...", id, "FREE_VIP_EXPIRED")
594 else _client_print_color(id, "^4[ZMVIP] ^1%L...", id, "FREE_VIP_EXPIRED")
595 client_cmd(id, "spk /sound/buttons/blip1.wav")
596 }
597
598 static i, d, value
599 static const double_attribs[] = {
600 AT_MULTIJUMP,
601 AT_EXTRA_HP,
602 AT_EXTRA_GRAVITY
603 }
604 d = 0
605
606 for(i=0; i<player_attributes;) {
607
608 if (double_attrib_update) {
609
610 if (d >= sizeof(double_attribs))
611 break;
612
613 i = double_attribs[d++];
614 }
615
616 if (p_data[id][FLAGS] == 0 && hour_flags == 0)
617 break;
618
619 if (!(BIT(i) & p_data[id][FLAGS]) && !(BIT(i) & hour_flags) || (BIT(i) & gamemode_disable_flags)) {
620 i++
621 continue;
622 }
623
624 value = 0
625 switch(i) {
626 case AT_MULTIJUMP: {
627 new jnum = get_pcvar_num(cvar_multijump)
628 if(jnum) {
629 static nflags, isspecial
630 nflags = _get_pcvar_flags(cvar_multijump_allow)
631 isspecial = is_special_character(id)
632
633 if((nflags & FLAG_A && !p_zombie[id]) || (nflags & FLAG_B && p_zombie[id]) && !isspecial) value = jnum
634 else if((nflags & FLAG_C && !p_zombie[id]) || (nflags & FLAG_D && p_zombie[id]) && isspecial) value = jnum
635 }
636 }
637 case AT_ARMOR: value = get_pcvar_num(cvar_armor)
638 case AT_UNLIMITED_CLIP: value = get_pcvar_num(cvar_unlimited_clip)
639 case AT_NO_FALL_DMG: value = get_pcvar_num(cvar_no_fall_dmg)
640 case AT_EXTRA_DMG: value = ((get_pcvar_float(cvar_extra_dmg)>0)?1:0)
641 case AT_EXTRA_HP: value = get_pcvar_num(p_zombie[id]?cvar_extra_hp_zombie:cvar_extra_hp_human)
642 case AT_EXTRA_GRAVITY: value = (get_pcvar_float(p_zombie[id]?cvar_extra_gravity_zombie:cvar_extra_gravity_human)>0.0)?1:0
643 case AT_EXTRA_FRAGS: value = get_pcvar_num(cvar_extra_frags)
644 case AT_EXTRA_KILL_AMMO: value = get_pcvar_num(cvar_extra_kill_ammo)
645 case AT_EXTRA_ARMOR: value = get_pcvar_num(cvar_extra_armor)
646 case AT_EXTRA_INFECT_AMMO: value = get_pcvar_num(cvar_extra_infect_ammo)
647 case AT_EXTRA_INFECT_HEALTH: value = get_pcvar_num(cvar_extra_infect_health)
648#if EXTRA_ITEMS == ON
649 case AT_EXTRA_ITEMS: value = p_data[id][FLAGS]?1:0
650#endif
651 case AT_DAMAGE_REWARD: value = get_pcvar_num(cvar_damage_reward)
652#if MODIFICATION != OLD
653 case AT_VIP_MODEL: value = (p_vip_model_zombie[0]!=EOS||p_vip_model_human[0]!=EOS)
654#endif
655 case AT_VIP_CLASS: value = get_pcvar_num(cvar_viponly_class)
656 case AT_CHATTAG: value = get_pcvar_num(cvar_chat_viptag)
657 case AT_VIPINSCORE: value = get_pcvar_num(cvar_vipniscoretable)
658 case AT_GRENADE_IMMUNITY: value = _get_pcvar_flags(cvar_grenades_immunity)
659 }
660 ATTRIB(id, i) = value
661
662 if (!double_attrib_update)
663 i++
664 }
665}
666public forward_event_round_start() {
667
668 arrayset(p_bought_per_round, 0, sizeof(p_bought_per_round))
669 current_gamemode = 0
670}
671public forward_event_deathmsg() {
672
673 static attacker, victim
674 attacker = read_data(1)
675 victim = read_data(2)
676
677 if (attacker == victim)
678 return;
679
680 if(IS_PLAYER(attacker)) {
681 if (get_pcvar_num(cvar_extra_ignore_for_special) && is_special_character(attacker))
682 return;
683
684 if (ATTRIB(attacker, AT_EXTRA_ARMOR) && !p_zombie[attacker] && p_zombie[victim])
685 set_user_armor(attacker, get_user_armor(attacker)+ATTRIB(attacker, AT_EXTRA_ARMOR))
686 if(ATTRIB(attacker, AT_EXTRA_KILL_AMMO))
687 zv_currency_give(attacker, p_attribs[attacker][AT_EXTRA_KILL_AMMO])
688 if(ATTRIB(attacker, AT_EXTRA_FRAGS))
689 set_user_frags(attacker, get_user_frags(attacker)+ATTRIB(attacker, AT_EXTRA_FRAGS))
690 }
691}
692
693public forward_event_reset_hud(id) {
694
695 if (ATTRIB(id, AT_VIPINSCORE)) {
696 if(is_user_alive(id)) {
697 message_begin(MSG_ALL, msg_scoreattrib)
698 write_byte(id)
699 write_byte(4)
700 message_end()
701 }
702 }
703}
704#if MODIFICATION == NEW
705public zp_fw_core_spawn_post(id) {
706#else
707public forward_player_spawn(id) {
708#endif
709#if MODIFICATION == NEW
710 p_zombie[id] = zp_core_is_zombie(id)?true:false
711#else
712 p_zombie[id] = zp_get_user_zombie(id)?true:false
713#endif
714 set_user_atribs(id)
715
716 if (first_spawn[id]) {
717 set_task(1.0, "show_vip_timeleft", id, _, _, "a", 6)
718 first_spawn[id] = false
719 }
720}
721
722public forward_player_takedamage_pre(victim, inflictor, attacker, Float:damage, damage_type) {
723
724 if(damage_type & DMG_FALL && ATTRIB(victim, AT_NO_FALL_DMG)) return HAM_SUPERCEDE;
725 else if(IS_PLAYER(attacker) && ATTRIB(attacker, AT_EXTRA_DMG)) {
726
727 if (get_pcvar_num(cvar_extra_ignore_for_special) && is_special_character(attacker))
728 return HAM_IGNORED;
729
730 SetHamParamFloat(4, damage*get_pcvar_float(cvar_extra_dmg))
731 return HAM_HANDLED;
732 }
733
734 return HAM_IGNORED;
735}
736public forward_player_takedamage_post(victim, inflictor, attacker, Float:damage, damage_type) {
737
738 if(IS_PLAYER(attacker) && ATTRIB(attacker, AT_DAMAGE_REWARD)) {
739
740 if(p_damage[attacker] > ATTRIB(attacker, AT_DAMAGE_REWARD)) {
741
742 zv_currency_give(attacker, 1)
743 p_damage[attacker] = 0.0
744 }
745 else
746 p_damage[attacker] += damage
747 }
748}
749
750public forward_cmdstart(id, uc_handle) {
751
752 static button, flags
753 button = get_uc(uc_handle, UC_Buttons)
754 flags = entity_get_int(id, EV_INT_flags)
755
756 if(flags & FL_ONGROUND)
757 p_jumpsnum[id] = 0
758
759 if(button & IN_JUMP && !(get_user_oldbutton(id) & IN_JUMP)) {
760
761 if(!(flags & FL_ONGROUND) && ++p_jumpsnum[id] <= ATTRIB(id, AT_MULTIJUMP)) {
762
763 static Float:velocity[3]
764 entity_get_vector(id, EV_VEC_velocity, velocity)
765 velocity[2] = random_float(265.0,285.0)
766 entity_set_vector(id,EV_VEC_velocity,velocity)
767 }
768 }
769}
770#define EV_NADE_TYPE EV_INT_flTimeStepSound
771#define NADE_TYPE_INFECTION 1111
772public forward_grenade_think(ent) {
773
774 if (is_valid_ent(ent) && entity_get_int(ent, EV_NADE_TYPE) == NADE_TYPE_INFECTION) {
775 p_grenade_time[entity_get_edict(ent, EV_ENT_owner)] = get_gametime()
776 }
777}
778// Credits: MeRcyLeZZ
779public message_cur_weapon(msg_id, msg_dest, msg_entity)
780{
781 if (!is_user_alive(msg_entity) || get_msg_arg_int(1) != 1) return;
782
783 static weapon, clip
784 weapon = get_msg_arg_int(2)
785 clip = get_msg_arg_int(3)
786
787 if (MAXCLIP[weapon] > 2 && ATTRIB(msg_entity, AT_UNLIMITED_CLIP)) {
788
789 set_msg_arg_int(3, get_msg_argtype(3), MAXCLIP[weapon])
790
791 if (clip < 2) {
792
793 static wname[32], weapon_ent
794 get_weaponname(weapon, wname, sizeof wname - 1)
795 weapon_ent = find_ent_by_owner(-1, wname, msg_entity)
796 // OFFSET_CLIPAMMO OFFSET_LINUX_WEAPONS
797 set_pdata_int(weapon_ent, 51, MAXCLIP[weapon], 4)
798 }
799 }
800}
801
802enum _:ChanellsStruct {
803 channel[8],
804 translation[42]
805}
806new const chat_channels[][ChanellsStruct] = {
807 {"CT", "^1(Humans) ^4[VIP] ^3%s^1 : %s"},
808 {"T", "^1(Zombies) ^4[VIP] ^3%s^1 : %s"},
809 {"CT_Dead", "^1*DEAD*(Humans) ^4[VIP] ^3%s^1 : %s"},
810 {"T_Dead", "^1*DEAD*(Zombies) ^4[VIP] ^3%s^1 : %s"},
811 {"Spec", "^1(Spectator) ^4[VIP] ^3%s^1 : %s"},
812 {"All", "^4[VIP] ^3%s : ^1%s"},
813 {"AllDead", "^1*DEAD* ^4[VIP] ^3%s^1 : %s"},
814 {"AllSpec", "^1*SPEC* ^4[VIP] ^3%s^1 : %s"}
815}
816
817public message_say_text(msg_id, msg_dest, msg_entity) {
818
819 if (!ATTRIB(msg_dest, AT_CHATTAG))
820 return;
821
822 static message[250]
823 get_msg_arg_string(2, message, charsmax(message))
824
825 if (ATTRIB(msg_dest, AT_CHATTAG) == 1) {
826 if (message[0] == '#' && message[9] == 'C' && equali(message, "#Cstrike_Chat_", 14)) {
827 new i
828
829 for (i=0; i<sizeof(chat_channels); i++) {
830 if (equal(message[14], chat_channels[i][channel])) {
831
832 set_msg_arg_string(2, chat_channels[i][translation])
833 get_user_name(msg_dest, message, charsmax(message))
834 set_msg_arg_string(3, message)
835 return;
836 }
837 }
838 }
839 else {
840 format(message, charsmax(message), "^4[VIP]%s", message)
841 set_msg_arg_string(2, message)
842 }
843 }
844 else if (ATTRIB(msg_dest, AT_CHATTAG) == 2) {
845 if (message[9] == 'C' && equali(message, "#Cstrike_Chat_", 14)) {
846
847 get_msg_arg_string(4, message, charsmax(message))
848 static tag_index
849
850 do {
851 tag_index = findtag(message, "<VIP>")
852 if (tag_index != -1) {
853 while (message[tag_index+5] != EOS) {
854 message[tag_index] = message[tag_index+5]; tag_index++
855 }
856 message[tag_index] = EOS
857 }
858 }
859 while (tag_index != -1)
860 ;
861
862 if (ATTRIB(msg_dest, AT_CHATTAG))
863 format(message, charsmax(message), "<VIP> %s", message)
864
865 set_msg_arg_string(4, message)
866 }
867 }
868}
869
870public client_infochanged(id) {
871
872 new info[5]
873 read_argv(1, info, charsmax(info))
874 if (equal(info, "name"))
875 VipsDBGet(id)
876}
877
878public client_putinserver(id) {
879
880 p_data[id][FLAGS] = 0
881 p_data[id][SETTINGS] = 0
882 p_data[id][TIMESTAMP] = 0
883 first_spawn[id] = true
884 arrayset(p_attribs[id], 0, player_attributes)
885 freevip_inform[id] = false
886 p_grenade_time[id] = 0.0
887 p_damage[id] = 0.0
888 p_jumpsnum[id] = 0
889
890 if (!VipsDBGet(id))
891 return;
892
893 if (p_data[id][TIMESTAMP] > 0 && p_data[id][TIMESTAMP] < get_systime()) {
894
895 VipsDBRemove(id)
896 return;
897 }
898
899 if (p_data[id][FLAGS]) {
900 new authid[30], ip[30], name[45]
901 get_user_name(id, name, charsmax(name))
902 get_user_authid(id, authid, charsmax(authid))
903 get_user_ip(id, ip, charsmax(ip), 1)
904 log_amx("[ZMVIP] VIP Connected: %s (%s) [%s].", name, authid, ip)
905 }
906
907 if (ATTRIB(id, AT_CHATTAG) && get_pcvar_num(cvar_vip_connected_to_server)) {
908
909 new name[35]
910 get_user_name(id, name, charsmax(name))
911 switch (get_pcvar_num(cvar_vip_connected_to_server)) {
912 case 1:
913 if (is_amxmodx_new_version) client_print_color(0, 0, "^4[VIP] %s ^1%L.", name, LANG_PLAYER, "CONNECTED_TO_SERVER")
914 else _client_print_color(0, "^4[VIP] %s ^1%L.", name, LANG_PLAYER, "CONNECTED_TO_SERVER")
915 case 2: {
916 set_hudmessage(255, 170, 0, 0.02, 0.71, 0, 6.0, 6.0)
917 show_hudmessage(0, "[VIP] %s %L", name, LANG_PLAYER, "CONNECTED_TO_SERVER")
918 }
919 case 3: {
920 if (is_amxmodx_new_version) {
921 set_dhudmessage(255, 170, 0, 0.02, 0.71, 0, 6.0, 6.0)
922 show_dhudmessage(0, "[VIP] %s %L", name, LANG_PLAYER, "CONNECTED_TO_SERVER")
923 }
924 else {
925 _set_dhudmessage(255, 170, 0, 0.02, 0.71, 0, 6.0, 6.0)
926 _show_dhudmessage(0, "[VIP] %s %L", name, LANG_PLAYER, "CONNECTED_TO_SERVER")
927 }
928 }
929 }
930 }
931}
932public client_disconnect(id) {
933
934 p_data[id][FLAGS] = 0
935 p_damage[id] = 0.0
936 p_jumpsnum[id] = 0
937 p_data[id][SETTINGS] = 0
938
939 if (p_data[id][TIMESTAMP] == ZV_DURATION_TILL_DISCONNECT) {
940 VipsDBRemove(id)
941 return;
942 }
943
944 if (p_data[id][TIMESTAMP] == ZV_DURATION_TILL_MAP) {
945 p_data[id][PASS][charsmax(p_data[][PASS])] = floatround(get_gametime()*100, floatround_floor)
946 VipsDBSet(id)
947 }
948}
949
950public show_vip_info(id) {
951
952 if (file_exists("vip.txt")) {
953
954 show_motd(id, "vip.txt")
955 }
956 else {
957 log_amx("WARNING: Missing vip.txt file in cstrike directory. It's used by /vip command to show information about privileges on server.")
958 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "NO_VIP_TXT")
959 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "NO_VIP_TXT")
960 print_admin_contacts(id)
961 }
962}
963public show_vips_online(id) {
964
965 new bool:first = true, message[256], len
966
967 for (new i=0; i<maxplayers; i++) {
968
969 if (p_data[i][FLAGS]) {
970
971 if (!first) {
972
973 message[len++] = ','
974 message[len++] = ' '
975 }
976 message[len++] = '^4'
977 message[len] = EOS
978 len += get_user_name(i, message[len], charsmax(message)-len)
979 message[len++] = '^1'
980 message[len] = EOS
981
982 first = false
983 }
984 }
985
986 if (first) {
987 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L...", id, "NO_VIP_ONLINE")
988 else _client_print_color(id, "^4[ZMVIP] ^1%L...", id, "NO_VIP_ONLINE")
989 }
990 else {
991 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L: %s.", id, "ONLINE_VIPS", message)
992 else _client_print_color(id, "^4[ZMVIP] ^1%L: %s.", id, "ONLINE_VIPS", message)
993 }
994
995 print_admin_contacts(id)
996
997 return PLUGIN_CONTINUE;
998}
999show_buy_menu(id) {
1000
1001 new duration = get_cvar_duration(cvar_vip_buy_duration)
1002
1003 if (duration == -1) {
1004 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "SERVER_CONFIG_ERROR")
1005 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "SERVER_CONFIG_ERROR")
1006 return;
1007 }
1008
1009 new timeleft[100]
1010 convert_duration_to_string(id, duration, timeleft, charsmax(timeleft))
1011
1012 new menu[250]
1013 formatex(menu, charsmax(menu),\
1014 "\r%L^n^n\
1015 %L: \y%d %L^n\
1016 \r%L: \y%s^n^n\
1017 \r1. \w%L^n^n\
1018 \r0. \w%L", id, "BUY_VIP_PRIVILEGE",
1019 id, "PRICE", get_pcvar_num(cvar_vip_price), id, zv_get_currency()==CURRENCY_AMMO_PACKS?"AMMO_PACKS":"MONEY",
1020 id, "TIME", timeleft,
1021 id, "BUY", id, "EXIT")
1022
1023 show_menu(id, MENU_KEY_0|MENU_KEY_1, menu, -1, "Menu Buy")
1024}
1025
1026public forward_buy_menu_handler(id, key) {
1027
1028 if (key == 0) {
1029
1030 new player_has = zv_currency_get(id)
1031
1032 if (player_has >= get_pcvar_num(cvar_vip_price)) {
1033
1034 new duration
1035 duration = get_cvar_duration(cvar_vip_buy_duration)
1036
1037 if (duration == -1) {
1038 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "SERVER_CONFIG_ERROR")
1039 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "SERVER_CONFIG_ERROR")
1040 print_admin_contacts(id)
1041 return;
1042 }
1043
1044 zv_currency_set(id, player_has-get_pcvar_num(cvar_vip_price))
1045 native_zv_set_user_flags(id, duration, _get_pcvar_flags(cvar_vip_buy_flags))
1046
1047 if (duration >= 0) {
1048
1049 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "PURCHASED_VIP")
1050 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "PURCHASED_VIP")
1051 }
1052 else {
1053 if (duration == ZV_DURATION_TILL_MAP) {
1054
1055 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "PURCHASED_VIP_TILL_MD")
1056 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "PURCHASED_VIP_TILL_MD")
1057 }
1058 else if (duration == ZV_DURATION_TILL_DISCONNECT) {
1059
1060 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "PURCHASED_VIP_TILL_D")
1061 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "PURCHASED_VIP_TILL_D")
1062 }
1063 }
1064 client_cmd(id, "spk /sound/buttons/bell1.wav")
1065 }
1066 else {
1067 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L %L!", id, "NOT_ENOUGHT", id,\
1068 zv_get_currency()==CURRENCY_AMMO_PACKS?"AMMO_PACKS":"MONEY")
1069 else _client_print_color(id, "^4[ZMVIP] ^1%L %L!", id, "NOT_ENOUGHT", id,\
1070 zv_get_currency()==CURRENCY_AMMO_PACKS?"AMMO_PACKS":"MONEY")
1071 client_cmd(id, "spk /sound/buttons/blip1.wav")
1072 }
1073 }
1074}
1075
1076//////////////////////// VIP MENU FUNCTIONS //////////////////////
1077public show_vip_menu_console(id) {
1078
1079 show_vip_menu(id)
1080 return PLUGIN_HANDLED;
1081}
1082public show_vip_menu(id) {
1083#if EXTRA_ITEMS == OFF
1084 if (p_data[id][FLAGS]) {
1085
1086 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "ALREADY_VIP_INFO")
1087 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "ALREADY_VIP_INFO")
1088 }
1089 else if (get_pcvar_num(cvar_vip_price) > 0) {
1090 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "YOU_ARE_NOT_VIP")
1091 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "YOU_ARE_NOT_VIP")
1092 show_buy_menu(id)
1093 return PLUGIN_CONTINUE;
1094 }
1095 else {
1096 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "YOU_ARE_NOT_VIP_INFO")
1097 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "YOU_ARE_NOT_VIP_INFO")
1098 return PLUGIN_CONTINUE;
1099 }
1100#else
1101 if (!ATTRIB(id, AT_EXTRA_ITEMS)) {
1102
1103 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "YOU_ARE_NOT_VIP_MENU")
1104 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "YOU_ARE_NOT_VIP_MENU")
1105 show_buy_menu(id)
1106 return PLUGIN_CONTINUE;
1107 }
1108
1109 new maximum = get_pcvar_num(cvar_buys_per_round)
1110 if (maximum && p_bought_per_round[id] > maximum) {
1111
1112 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L", id, "EXCEEDED_BUY_LIMIT", maximum)
1113 else _client_print_color(id, "^4[ZMVIP] ^1%L", id, "EXCEEDED_BUY_LIMIT", maximum)
1114 return PLUGIN_CONTINUE;
1115 }
1116#if MODIFICATION == NEW
1117
1118 if (is_user_alive(id)) {
1119 p_views_extra_items_menu[id] = true
1120 zp_items_show_menu(id)
1121 p_views_extra_items_menu[id] = false
1122 }
1123 else {
1124 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "NOT_ALIVE")
1125 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "NOT_ALIVE")
1126 }
1127#else
1128
1129 if(registered_extra_items_num) {
1130
1131 new item_data[item_struct], item_string[250], menu_header[40]
1132 formatex(menu_header, charsmax(menu_header), "\r%L:", id, "VIP_MENU_TOP")
1133 new menu = menu_create(menu_header, "show_vip_menu_handler")
1134
1135 new bool:special = is_special_character(id)?true:false;
1136 new info[5]
1137
1138 for(new i=0; i<registered_extra_items_num; i++) {
1139
1140 ArrayGetArray(array_vip_extra_items, i, item_data)
1141
1142 if (item_data[item_team] > 0
1143 && (item_data[item_team]&ZP_TEAM_ZOMBIE && !p_zombie[id])
1144 || (item_data[item_team]&ZP_TEAM_HUMAN && p_zombie[id])
1145 || (item_data[item_team]&(ZP_TEAM_NEMESIS|ZP_TEAM_SURVIVOR) && !special)
1146 )
1147 continue;
1148
1149 formatex(item_string, charsmax(item_string), "%s \y%d %L", \
1150 item_data[item_name], item_data[item_cost], id, zv_get_currency()==CURRENCY_AMMO_PACKS?"AMMO_PACKS":"MONEY")
1151 num_to_str(i, info, charsmax(info))
1152 menu_additem(menu, item_string, info)
1153 }
1154
1155 if(menu_items(menu)) menu_display(id, menu, 0)
1156 else {
1157 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "NO_ITEMS_FOR_TEAM")
1158 else _client_print_color(id, "^4[ZMVIP] ^3%L.", id, "NO_ITEMS_FOR_TEAM")
1159 }
1160 }
1161 else {
1162 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "NO_PLUGINS_LOADED")
1163 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "NO_PLUGINS_LOADED")
1164 }
1165#endif
1166#endif
1167 static timeleft[100]
1168 convert_duration_to_string(id, max(p_data[id][TIMESTAMP]-get_systime(), 0), timeleft, charsmax(timeleft))
1169
1170 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1VIP %L: ^3%s", id, "TIMELEFT", timeleft)
1171 else _client_print_color(id, "^4[ZMVIP] ^1VIP %L: ^3%s", id, "TIMELEFT", timeleft)
1172
1173 return PLUGIN_CONTINUE
1174}
1175#if MODIFICATION != NEW && EXTRA_ITEMS == ON
1176public show_vip_menu_handler(id, menu, item)
1177{
1178 if(item == MENU_EXIT )
1179 {
1180 menu_destroy(menu)
1181 return PLUGIN_HANDLED
1182 }
1183
1184 new item_id, _blank, info[5]
1185 menu_item_getinfo(menu, item, _blank, info, charsmax(info), "", _blank, _blank)
1186
1187 item_id = str_to_num(info)
1188
1189 new retval, item_data[item_struct]
1190 ArrayGetArray(array_vip_extra_items, item_id, item_data)
1191
1192 if (chached_show_vip_items)
1193 ExecuteForward(fw_extraitemselected, retval, id, item_data[item_plid])
1194 else
1195 ExecuteForward(fw_extraitemselected, retval, id, item_id)
1196
1197 if (retval < ZP_PLUGIN_HANDLED) {
1198 zv_currency_set(id, zv_currency_get(id)-item_data[item_cost])
1199 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L '^4%s^1'", id, "PURCHASED", item_data[item_name])
1200 else _client_print_color(id, "^4[ZMVIP] ^1%L '^4%s^1'", id, "PURCHASED", item_data[item_name])
1201 p_bought_per_round[id]++
1202 }
1203
1204 menu_destroy(menu)
1205 return PLUGIN_HANDLED
1206}
1207#endif
1208public vip_time_check() {
1209
1210 static id, timestamp
1211 timestamp = get_systime()
1212
1213 for (id=1; id<33; id++) {
1214 if (p_data[id][TIMESTAMP] > 0 && p_data[id][TIMESTAMP] < timestamp) {
1215
1216 native_zv_remove_user_flags(id)
1217 }
1218 }
1219}
1220
1221is_special_character(id) {
1222
1223 if(p_zombie[id]) {
1224#if MODIFICATION == NEW
1225 if(!(natives_filter_out & BIT(NATIVE_ZP_CLASS_NEMESIS_GET)) && zp_class_nemesis_get(id)
1226 || !(natives_filter_out & BIT(NATIVE_ZP_CLASS_ASSASSIN_GET)) && zp_class_assassin_get(id)
1227 )
1228 return true;
1229#else
1230 if(zp_get_user_nemesis(id)
1231 || !(natives_filter_out & BIT(NATIVE_ZP_CLASS_BOMBARDIER_GET)) && zp_get_user_bombardier(id)
1232 )
1233 return true;
1234#endif
1235 }
1236 else {
1237#if MODIFICATION == NEW
1238 if(!(natives_filter_out & BIT(NATIVE_ZP_CLASS_SURVIVOR_GET)) && zp_class_survivor_get(id)
1239 || !(natives_filter_out & BIT(NATIVE_ZP_CLASS_SNIPER_GET)) && zp_class_sniper_get(id)
1240 )
1241 return true;
1242#else
1243 return zp_get_user_survivor(id)
1244#endif
1245 }
1246 return false;
1247}
1248
1249check_named_privileges(id, nick[], pass[]) {
1250
1251 new num
1252 if (!array_vips_database_nick || !(num = VIPCNT(NAMES))) {
1253 p_data[id][SETTINGS] = 0
1254 p_data[id][FLAGS] = 0
1255 return false;
1256 }
1257
1258 for (new index=0; index<num; index++) {
1259 ArrayGetArray(array_vips_database_nick, index, p_data[id])
1260 if (p_data[id][SETTINGS] & FLAG_C) {
1261 if (((p_data[id][SETTINGS]&FLAG_N)?contain(nick, p_data[id][AUTH]):containi(nick, p_data[id][AUTH])) == -1)
1262 continue;
1263 }
1264 else {
1265 if (!((p_data[id][SETTINGS]&FLAG_N)?equal(nick, p_data[id][AUTH]):equali(nick, p_data[id][AUTH])))
1266 continue;
1267 }
1268
1269 if (!EMPTY(p_data[id][PASS])) {
1270
1271 p_data[id][PASS][charsmax(p_data[][PASS])] = EOS
1272 if (!equal(p_data[id][PASS], pass)) {
1273 if (p_data[id][SETTINGS] & FLAG_K) {
1274 return false;
1275 }
1276 else {
1277 client_print(id, print_console, "[ZMVIP] %L.", id, "PASS_NOT_MATCH")
1278 continue;
1279 }
1280 }
1281 }
1282 p_data[id][INDEX] = index
1283 return true;
1284 }
1285
1286 p_data[id][SETTINGS] = 0
1287 p_data[id][FLAGS] = 0
1288 return false;
1289}
1290public cmd_vips_remove(id, level, cid) {
1291
1292 if(id != 0 && !(get_user_flags(id) & level))
1293 return PLUGIN_HANDLED;
1294
1295 if (read_argc() < 1) {
1296 console_print(id, "[ZM VIP] %L: zm_vip_remove <NICK/AUTH/IP>.", id, "USAGE")
1297 return PLUGIN_HANDLED;
1298 }
1299
1300 new argument[40]
1301 read_argv(1, argument, charsmax(argument))
1302
1303 new player = cmd_target(id, argument, CMDTARGET_OBEY_IMMUNITY|CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS)
1304 if (!player)
1305 return PLUGIN_HANDLED;
1306
1307 new name[40]
1308 get_user_name(player, name, charsmax(name))
1309
1310 if (!p_data[player][FLAGS]) {
1311 console_print(id, "[ZM VIP] %L", id, "DOES_NOT_HAVE_VIP", name)
1312 return PLUGIN_HANDLED;
1313 }
1314
1315 if (native_zv_remove_user_flags(player))
1316 console_print(id, "[ZM VIP] %L.", id, "PRIVILEGE_REMOVED", name)
1317 else
1318 console_print(id, "[ZM VIP] %L.", id, "PLUGIN_ERROR_REMOVING", name)
1319
1320 return PLUGIN_HANDLED;
1321}
1322
1323public cmd_vips_reload(id, level, cid) {
1324
1325 if(id != 0 && !(get_user_flags(id) & level))
1326 return PLUGIN_HANDLED;
1327
1328 server_cmd("amx_reloadadmins")
1329 server_exec()
1330
1331 TrieClear(trie_vips_database)
1332 ArrayClear(array_vips_database)
1333 if (array_vips_database_nick)
1334 ArrayClear(array_vips_database_nick)
1335
1336 arrayset(total_vips_count, 0, sizeof(total_vips_count))
1337#if VIPS_FILE_SYSTEM != OFF
1338 load_ini_file()
1339#endif
1340 load_datafile()
1341
1342#if VIPS_FILE_SYSTEM != FORCED
1343 new num_admins = admins_num()
1344 for (new i=0; i<num_admins; i++) {
1345 if (admins_lookup(i, AdminProp_Access)&VIP_SYS_FLAG) {
1346 VIPINC(AMX)
1347 }
1348 }
1349#endif
1350 new players[32], num_players, i
1351 get_players(players, num_players, "ch")
1352
1353 for (i=0; i<num_players; i++) {
1354 VipsDBGet(players[i])
1355 }
1356
1357 if (id) {
1358 static authid[30], ip[30], name[45]
1359 get_user_name(id, name, charsmax(name))
1360 get_user_authid(id, authid, charsmax(authid))
1361 get_user_ip(id, ip, charsmax(ip), 1)
1362 log_amx("Cmd exec: zm_vip_reload. By: %s (%s) (%s)", name, authid, ip)
1363 }
1364 else
1365 log_amx("Cmd exec: zm_vip_reload. From server console")
1366
1367 console_print(id, "[ZM VIP] Reloaded %d vips", VIPCNT(DAT)+VIPCNT(INI)+VIPCNT(AMX))
1368 return PLUGIN_HANDLED;
1369}
1370
1371public cmd_list_vips(id, level, cid) {
1372
1373 if(id != 0 && !(get_user_flags(id) & level))
1374 return PLUGIN_HANDLED;
1375
1376 new key[40], i, size = ArraySize(array_vips_database)
1377 new data[vips_database_type]
1378
1379 console_print(id, "Main VIPs: %d", VIPCNT(MAIN)+VIPCNT(NAMES))
1380 new load_types[][] = {"DAT", "INI", "AMX"}
1381 new load_type, flags_str[30], time_str[25]
1382
1383 for (i=0; i<size; i++) {
1384
1385 ArrayGetString(array_vips_database, i, key, sizeof(key))
1386
1387 if (EMPTY(key))
1388 continue;
1389
1390 if (!TrieGetArray(trie_vips_database, key, data, vips_database_type))
1391 continue;
1392
1393 if (data[SETTINGS] & LOAD_FROM_DAT)
1394 load_type = 0
1395#if VIPS_FILE_SYSTEM != OFF
1396 if (data[SETTINGS] & LOAD_FROM_INI)
1397 load_type = 1
1398#endif
1399#if VIPS_FILE_SYSTEM != FORCED
1400 if (data[SETTINGS] & LOAD_FROM_AMX)
1401 load_type = 2
1402#endif
1403 flags_str[0] = EOS
1404 time_str[0] = EOS
1405 if (data[FLAGS] == -1)
1406 add(flags_str, charsmax(flags_str), "All")
1407 else
1408 get_flags(data[FLAGS], flags_str, charsmax(flags_str))
1409
1410 if (data[TIMESTAMP] == ZV_DURATION_PERMANENT)
1411 add(time_str, charsmax(time_str), "Permanent")
1412 else if (data[TIMESTAMP] == ZV_DURATION_TILL_DISCONNECT)
1413 add(time_str, charsmax(time_str), "Disconnect")
1414 else if (data[TIMESTAMP] == ZV_DURATION_TILL_MAP)
1415 add(time_str, charsmax(time_str), "Map change")
1416 else
1417 format_time(time_str, charsmax(time_str), "%Y/%m/%d-%H:%M", data[TIMESTAMP])
1418
1419 console_print(id, "%s| ^"%s^" ^"%s^" ^"%s^"", load_types[load_type],
1420 data[AUTH], flags_str, time_str)
1421 }
1422
1423 if (array_vips_database_nick) {
1424 size = ArraySize(array_vips_database_nick)
1425 for (i=0; i<size; i++) {
1426
1427 ArrayGetArray(array_vips_database_nick, i, data)
1428
1429 if (data[SETTINGS] & LOAD_FROM_DAT)
1430 load_type = 0
1431#if VIPS_FILE_SYSTEM != OFF
1432 if (data[SETTINGS] & LOAD_FROM_INI)
1433 load_type = 1
1434#endif
1435#if VIPS_FILE_SYSTEM != FORCED
1436 if (data[SETTINGS] & LOAD_FROM_AMX)
1437 load_type = 2
1438#endif
1439
1440 if (data[FLAGS] == -1)
1441 add(flags_str, charsmax(flags_str), "All")
1442 else
1443 get_flags(data[FLAGS], flags_str, charsmax(flags_str))
1444
1445 if (data[TIMESTAMP] == ZV_DURATION_PERMANENT)
1446 add(time_str, charsmax(time_str), "Permanent")
1447 else if (data[TIMESTAMP] == ZV_DURATION_TILL_DISCONNECT)
1448 add(time_str, charsmax(time_str), "Disconnect")
1449 else if (data[TIMESTAMP] == ZV_DURATION_TILL_MAP)
1450 add(time_str, charsmax(time_str), "Map change")
1451 else
1452 format_time(time_str, charsmax(time_str), "%Y/%m/%d-%H:%M", data[TIMESTAMP])
1453
1454 console_print(id, "%s| ^"%s^" ^"%s^" ^"%s^"", load_types[load_type],
1455 data[AUTH], flags_str, time_str)
1456 }
1457 }
1458#if VIPS_FILE_SYSTEM != FORCED
1459 console_print(id, "Amx VIPs: %d", VIPCNT(AMX))
1460
1461 new num_admins = admins_num()
1462 for (new i=0; i<num_admins; i++) {
1463 if (admins_lookup(i, AdminProp_Access)&VIP_SYS_FLAG) {
1464 new auth[40]
1465 admins_lookup(i, AdminProp_Auth, auth, charsmax(auth))
1466
1467 console_print(id, "AMX| ^"%s^"", auth)
1468 }
1469 }
1470#endif
1471 return PLUGIN_HANDLED;
1472}
1473
1474public set_freevip_hour(id, level, cid) {
1475
1476 if(id != 0 && !(get_user_flags(id) & level))
1477 return PLUGIN_HANDLED;
1478
1479 if (read_argc() < 2) {
1480
1481 if (freevip_enabled)
1482 console_print(id, "^"zm_vip_freevip_hour^" is ^"%d:%d-%d:%d^"", \
1483 freevip_hours[0], freevip_hours[1], freevip_hours[2], freevip_hours[3])
1484 else
1485 console_print(id, "^"zm_vip_freevip_hour^" is ^"off^"")
1486 return PLUGIN_HANDLED;
1487 }
1488
1489 new string[12], index
1490 read_argv(1, string, charsmax(string))
1491
1492 if(string[0] == 'o' || (string[0] == '0' && string[1] == EOS)) {
1493 freevip_enabled = false
1494 return PLUGIN_HANDLED;
1495 }
1496
1497 if (string[2] == ':') {
1498 freevip_hours[0] = (string[0]-'0')*10+(string[1]-'0')
1499 freevip_hours[1] = (string[3]-'0')*10+(string[4]-'0')
1500 index = 5
1501 }
1502 else if (string[1] == ':') {
1503 freevip_hours[0] = (string[0]-'0')
1504 freevip_hours[1] = (string[2]-'0')*10+(string[3]-'0')
1505 index = 4
1506 }
1507 else {
1508 log_amx("ERROR: Inccorect zm_freevip_hour cvar value! Set correctly, or turn off by typing ^"off^".")
1509 return PLUGIN_HANDLED;
1510 }
1511
1512 if (freevip_hours[0] >= 24 || freevip_hours[1] >= 60) {
1513 log_amx("ERROR: Inccorect zm_freevip_hour cvar value! Set correctly, or turn off by typing ^"off^".")
1514 return PLUGIN_HANDLED;
1515 }
1516
1517 if (string[index++] != '-') {
1518 log_amx("ERROR: Inccorect zm_freevip_hour cvar value! Set correctly, or turn off by typing ^"off^".")
1519 return PLUGIN_HANDLED;
1520 }
1521
1522 if (string[index+2] == ':') {
1523 freevip_hours[2] = (string[index]-'0')*10+(string[index+1]-'0')
1524 freevip_hours[3] = (string[index+3]-'0')*10+(string[index+4]-'0')
1525 }
1526 else if (string[index+1] == ':') {
1527 freevip_hours[2] = (string[index]-'0')
1528 freevip_hours[3] = (string[index+2]-'0')*10+(string[index+3]-'0')
1529 }
1530 else {
1531 log_amx("ERROR: Inccorect zm_freevip_hour cvar value! Set correctly, or turn off by typing ^"off^".")
1532 return PLUGIN_HANDLED;
1533 }
1534
1535 if (freevip_hours[2] >= 24 || freevip_hours[3] >= 60) {
1536 log_amx("ERROR: Inccorect zm_freevip_hour cvar value! Set correctly, or turn off by typing ^"off^".")
1537 return PLUGIN_HANDLED;
1538 }
1539
1540 freevip_enabled = true
1541
1542 return PLUGIN_HANDLED;
1543}
1544
1545freevip_hour_check() {
1546
1547 if (freevip_hours[0] == freevip_hours[2] && freevip_hours[1] == freevip_hours[3]) {
1548 return true;
1549 }
1550
1551 new h, m, s
1552 time(h, m, s)
1553
1554 new hour_low, hour_high
1555 hour_low = freevip_hours[0]*100+freevip_hours[1]
1556 hour_high = freevip_hours[2]*100+freevip_hours[3]
1557
1558 if ((hour_low <= (h*100+m) < hour_high) || (hour_high <= (h*100+m) < hour_low))
1559 return true;
1560
1561 return false
1562}
1563
1564//////////////////////// API STUFF ///////////////////////////
1565#if MODIFICATION == NEW
1566public zp_fw_core_infect_pre(id, attacker) {
1567#else
1568public zp_user_infect_attempt(id, attacker, nemesis) {
1569#endif
1570 if (ATTRIB(id, AT_GRENADE_IMMUNITY) & FLAG_A && p_grenade_time[attacker]
1571 && get_gametime()-p_grenade_time[attacker] < 0.5)
1572#if MODIFICATION == NEW
1573 return PLUGIN_HANDLED;
1574#else
1575 return ZP_PLUGIN_HANDLED;
1576#endif
1577
1578 return PLUGIN_CONTINUE;
1579}
1580#if MODIFICATION == NEW
1581public zp_fw_core_infect_post(id, attacker) {
1582#else
1583public zp_user_infected_post(id, attacker) {
1584#endif
1585 p_zombie[id] = true
1586 p_grenade_time[id] = 0.0
1587
1588 set_user_atribs(id, true)
1589 set_user_atribs(attacker, true)
1590
1591 if (get_pcvar_num(cvar_extra_ignore_for_special) && is_special_character(id))
1592 return;
1593
1594 if (ATTRIB(id, AT_EXTRA_GRAVITY)) {
1595 new Float:gravity = get_user_gravity(id)-get_pcvar_float(cvar_extra_gravity_zombie)
1596 if (gravity < 0.0) gravity = 0.0
1597 set_user_gravity(id, gravity)
1598 }
1599
1600 if(ATTRIB(attacker, AT_EXTRA_INFECT_HEALTH))
1601 set_user_health(attacker, get_user_health(attacker)+ATTRIB(attacker, AT_EXTRA_INFECT_HEALTH))
1602
1603 if(ATTRIB(id, AT_EXTRA_HP))
1604 set_user_health(id, get_user_health(id)+ATTRIB(id, AT_EXTRA_HP))
1605
1606 if(ATTRIB(attacker, AT_EXTRA_FRAGS))
1607 set_user_frags(attacker, get_user_frags(attacker)+ATTRIB(attacker, AT_EXTRA_FRAGS))
1608
1609 if(ATTRIB(attacker, AT_EXTRA_INFECT_AMMO))
1610 zv_currency_give(attacker, p_attribs[attacker][AT_EXTRA_INFECT_AMMO])
1611#if MODIFICATION != OLD
1612 if(ATTRIB(id, AT_VIP_MODEL) && !EMPTY(p_vip_model_zombie))
1613#if MODIFICATION == NEW
1614 cs_set_player_model(id, p_vip_model_zombie)
1615#endif
1616#if MODIFICATION == OLD
1617 if (natives_filter_out & BIT(NATIVE_OVERRIDE_USER_MODEL)) {
1618 log_amx("WARNING: You are using old zombie plague version, that don't support custom VIP models.")
1619 }
1620 else
1621 zp_override_user_model(id, p_vip_model_zombie)
1622#endif
1623#endif
1624}
1625#if MODIFICATION == NEW
1626public zp_fw_core_cure_post(id) {
1627#else
1628public zp_user_humanized_post(id) {
1629#endif
1630 p_zombie[id] = false
1631
1632 set_user_atribs(id, true)
1633
1634 if (get_pcvar_num(cvar_extra_ignore_for_special) && is_special_character(id))
1635 return;
1636
1637 if (ATTRIB(id, AT_EXTRA_GRAVITY)) {
1638 new Float:gravity = get_user_gravity(id)-get_pcvar_float(cvar_extra_gravity_human)
1639 if (gravity < 0.04) gravity = 0.04
1640
1641 set_user_gravity(id, gravity)
1642 }
1643 if(ATTRIB(id, AT_EXTRA_HP))
1644 set_user_health(id, get_user_health(id)+ATTRIB(id, AT_EXTRA_HP))
1645
1646 if(ATTRIB(id, AT_ARMOR))
1647 set_user_armor(id, ATTRIB(id, AT_ARMOR))
1648
1649#if MODIFICATION != OLD
1650 if(ATTRIB(id, AT_VIP_MODEL) && !EMPTY(p_vip_model_human))
1651#if MODIFICATION == NEW
1652 cs_set_player_model(id, p_vip_model_human)
1653#endif
1654#if MODIFICATION == OLD
1655 if (natives_filter_out & BIT(NATIVE_OVERRIDE_USER_MODEL)) {
1656 log_amx("WARNING: You are using old zombie plague version, that don't support custom VIP models.")
1657 }
1658 else
1659 zp_override_user_model(id, p_vip_model_human)
1660#endif
1661#endif
1662}
1663#if MODIFICATION == NEW
1664public zp_fw_gamemodes_start(gamemode) {
1665#else
1666public zp_round_started(gamemode) {
1667 gamemode -= 1
1668#endif
1669 current_gamemode = gamemode
1670}
1671#if MODIFICATION == NEW
1672public zp_fw_grenade_fire_pre(id) {
1673 return (ATTRIB(id, AT_GRENADE_IMMUNITY) & FLAG_B)?PLUGIN_HANDLED:PLUGIN_CONTINUE;
1674}
1675public zp_fw_grenade_frost_pre(id) {
1676 return (ATTRIB(id, AT_GRENADE_IMMUNITY) & FLAG_C)?PLUGIN_HANDLED:PLUGIN_CONTINUE;
1677}
1678#endif
1679#if MODIFICATION == NEW
1680#if EXTRA_ITEMS == ON
1681public zp_fw_items_select_post(id, itemid, ignorecost) {
1682
1683 if (VipsItemIs(EXTRA_ITEM, itemid))
1684 p_bought_per_round[id]++
1685}
1686#endif
1687public zp_fw_items_select_pre(id, itemid, ignorecost) {
1688
1689 if (itemid == vip_buy_extra_item) {
1690 show_buy_menu(id)
1691 return ZP_ITEM_NOT_AVAILABLE;
1692 }
1693#if EXTRA_ITEMS == ON
1694 if (!registered_extra_items_num)
1695 return ZP_ITEM_AVAILABLE;
1696
1697 if (VipsItemIs(EXTRA_ITEM, itemid)) {
1698 if (get_pcvar_num(cvar_vip_show_vip_items) > 0) {
1699
1700 zp_items_menu_text_add("*VIP*")
1701
1702 if (ATTRIB(id, AT_EXTRA_ITEMS)) {
1703 new maximum = get_pcvar_num(cvar_buys_per_round)
1704 if (maximum && p_bought_per_round[id] > maximum) {
1705 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L", id, "EXCEEDED_BUY_LIMIT", maximum)
1706 else _client_print_color(id, "^4[ZMVIP] ^1%L", id, "EXCEEDED_BUY_LIMIT", maximum)
1707 return ZP_ITEM_NOT_AVAILABLE;
1708 }
1709 else {
1710 return ZP_ITEM_AVAILABLE;
1711 }
1712 }
1713 else
1714 return get_pcvar_num(cvar_vip_show_vip_items)==2?ZP_ITEM_NOT_AVAILABLE:ZP_ITEM_DONT_SHOW;
1715 }
1716 }
1717 else if (p_views_extra_items_menu[id])
1718 return ZP_ITEM_DONT_SHOW;
1719#endif
1720 return ZP_ITEM_AVAILABLE;
1721}
1722
1723public zp_fw_class_human_select_pre(id, classid) {
1724
1725 if (!VipsItemHandle)
1726 return ZP_CLASS_AVAILABLE;
1727
1728 if (VipsItemIs(CLASS_HUMAN, classid)) {
1729
1730 zp_class_human_menu_text_add("*VIP*")
1731 return (ATTRIB(id, AT_VIP_CLASS))?ZP_CLASS_AVAILABLE:ZP_CLASS_NOT_AVAILABLE;
1732 }
1733
1734 return ZP_CLASS_AVAILABLE;
1735}
1736
1737public zp_fw_class_zombie_select_pre(id, classid) {
1738
1739 if (!VipsItemHandle)
1740 return ZP_CLASS_AVAILABLE;
1741
1742 if (VipsItemIs(CLASS_ZOMBIE, classid)) {
1743
1744 zp_class_zombie_menu_text_add("*VIP*")
1745 return (ATTRIB(id, AT_VIP_CLASS))?ZP_CLASS_AVAILABLE:ZP_CLASS_NOT_AVAILABLE;
1746 }
1747
1748 return ZP_CLASS_AVAILABLE;
1749}
1750#endif
1751#if MODIFICATION != NEW
1752public zp_user_infected_pre(id) {
1753
1754 if(VipsItemHandle && !ATTRIB(id, AT_VIP_CLASS)) {
1755
1756 if(VipsItemIs(CLASS_ZOMBIE, zp_get_user_next_class(id))) {
1757 zp_set_user_zombie_class(id, 0)
1758 client_print(id, print_center, "%L", id, "VIPONLY_CLASS")
1759 if (is_amxmodx_new_version) client_print_color(id, id, "^4[ZMVIP] ^1%L.", id, "VIPONLY_CLASS_INFO")
1760 else _client_print_color(id, "^4[ZMVIP] ^1%L.", id, "VIPONLY_CLASS_INFO")
1761 }
1762 }
1763}
1764public zp_extra_item_selected(id, itemid) {
1765
1766 if (itemid == vip_buy_extra_item) {
1767 show_buy_menu(id)
1768 return ZP_PLUGIN_HANDLED;
1769 }
1770 return 1;
1771}
1772#endif
1773// Natives
1774
1775public native_zv_get_user_flags(id) {
1776 return p_data[id][FLAGS];
1777}
1778
1779public native_zv_set_user_flags(id, duration, flags) {
1780
1781 new i, num, timestamp = get_systime(duration)
1782
1783 if (id) {
1784 if (!is_user_connected(id))
1785 return false;
1786
1787 goto skip_loop;
1788 }
1789
1790 new players[32]
1791 get_players(players, num, "ch")
1792
1793 for (i=0; i<num; i++) {
1794 id = players[i]
1795
1796 skip_loop:
1797
1798 if (!p_data[id][FLAGS] && duration == ZV_DURATION_IGNORE)
1799 return false;
1800
1801 p_data[id][FLAGS] = flags==0?-1:flags;
1802 p_data[id][TIMESTAMP] = timestamp
1803
1804 VipsDBSet(id)
1805 set_user_atribs(id)
1806 }
1807
1808 return true;
1809}
1810
1811public native_zv_remove_user_flags(id) {
1812
1813 new i, num
1814 if (!VIPCNT(DAT) && !VIPCNT(INI) && !VIPCNT(AMX))
1815 return false;
1816
1817 if (id) {
1818
1819 if (!is_user_connected(id) || !p_data[id][FLAGS])
1820 return false;
1821
1822 p_data[id][FLAGS] = 0
1823 p_data[id][TIMESTAMP] = 0
1824 arrayset(p_attribs[id], 0, player_attributes)
1825
1826 return VipsDBRemove(id);
1827 }
1828
1829 new players[32]
1830 get_players(players, num, "ch")
1831
1832 for (i=0; i<num; i++) {
1833 id = players[i]
1834
1835 p_data[id][FLAGS] = 0
1836 p_data[id][TIMESTAMP] = 0
1837 arrayset(p_attribs[id], 0, player_attributes)
1838
1839 VipsDBRemove(id)
1840 }
1841
1842 return true;
1843}
1844
1845#if MODIFICATION == NEW
1846public native_zv_class_human_register(const name[], const description[], health, Float:speed, Float:gravity) {
1847
1848 param_convert(1)
1849 param_convert(2)
1850 new class_id = zp_class_human_register(name, description, health, speed, gravity)
1851
1852 VipsItemSet(CLASS_HUMAN, class_id)
1853 return class_id
1854}
1855public native_zv_class_zombie_register(const name[], const description[], health, Float:speed, Float:gravity) {
1856
1857 param_convert(1)
1858 param_convert(2)
1859 new class_id = zp_class_zombie_register(name, description, health, speed, gravity)
1860
1861 VipsItemSet(CLASS_ZOMBIE, class_id)
1862 return class_id
1863}
1864#if EXTRA_ITEMS == ON
1865public native_zv_items_register(const name[], cost) {
1866
1867 param_convert(1)
1868 new item_id = zp_items_register(name, cost)
1869
1870 VipsItemSet(EXTRA_ITEM, item_id)
1871 registered_extra_items_num++
1872 return item_id
1873}
1874#endif
1875#endif
1876#if MODIFICATION != NEW
1877public native_zv_register_zombie_class(const name[], const info[], const model[], const clawmodel[], hp, speed, Float:gravity, Float:knockback) {
1878
1879 param_convert(1)
1880 param_convert(2)
1881 param_convert(3)
1882 param_convert(4)
1883 new class_id = zp_register_zombie_class(name, info, model, clawmodel, hp, speed, gravity, knockback)
1884
1885 VipsItemSet(CLASS_ZOMBIE, class_id)
1886 return class_id
1887}
1888#if EXTRA_ITEMS == ON
1889public native_zv_register_extra_item2(const name[], cost, team) {
1890
1891 param_convert(1)
1892
1893 new item_data[item_struct]
1894
1895 if(!array_vip_extra_items)
1896 array_vip_extra_items = ArrayCreate(item_struct)
1897
1898 formatex(item_data[item_name], charsmax(item_data[item_name]), "*VIP* %s", name)
1899 item_data[item_cost] = cost
1900 item_data[item_team] = team
1901
1902 if (chached_show_vip_items) {
1903
1904 item_data[item_plid] = zp_register_extra_item(name, cost, team)
1905
1906 VipsItemSet(EXTRA_ITEM, item_data[item_plid])
1907 }
1908
1909 ArrayPushArray(array_vip_extra_items, item_data)
1910 registered_extra_items_num++
1911
1912 return chached_show_vip_items?item_data[item_plid]:registered_extra_items_num
1913}
1914public native_zv_register_extra_item(const name[], const description[], cost, team) {
1915
1916 param_convert(1)
1917 param_convert(2)
1918
1919 new item_data[item_struct]
1920
1921 if(!array_vip_extra_items)
1922 array_vip_extra_items = ArrayCreate(item_struct)
1923
1924 formatex(item_data[item_name], charsmax(item_data[item_name]), "*VIP* %s \r[%s]", name, description)
1925 item_data[item_cost] = cost
1926 item_data[item_team] = team
1927
1928 if (chached_show_vip_items) {
1929
1930 item_data[item_plid] = zp_register_extra_item(name, cost, team)
1931
1932 VipsItemSet(EXTRA_ITEM, item_data[item_plid])
1933 }
1934
1935 ArrayPushArray(array_vip_extra_items, item_data)
1936 registered_extra_items_num++
1937
1938 return chached_show_vip_items?item_data[item_plid]:registered_extra_items_num
1939}
1940public native_zv_force_buy_extra_item(id, itemid, ignorecost) {
1941
1942 if (chached_show_vip_items) {
1943
1944 zp_force_buy_extra_item(id, itemid, ignorecost)
1945 return;
1946 }
1947
1948 new retval
1949 ExecuteForward(fw_extraitemselected, retval, id, itemid)
1950
1951 if (retval >= ZP_PLUGIN_HANDLED && !ignorecost) {
1952 new item_data[item_struct]
1953 ArrayGetArray(array_vip_extra_items, itemid, item_data)
1954 zv_currency_set(id, zv_currency_get(id)+item_data[item_cost])
1955 }
1956}
1957public native_zv_get_extra_item_id(const name[]) {
1958
1959 param_convert(1)
1960
1961 if (chached_show_vip_items) {
1962
1963 return zp_get_extra_item_id(name)
1964 }
1965
1966 new item_data[item_struct]
1967 for (new i=0; i<registered_extra_items_num; i++) {
1968
1969 ArrayGetArray(array_vip_extra_items, i, item_data)
1970 if (equali(name, item_data[item_name]))
1971 return i;
1972 }
1973
1974 return -1;
1975}
1976#endif
1977#endif
1978new dummy_record_count
1979public plugin_end() {
1980 if (dummy_record_count > 5)
1981 write_datafile()
1982
1983/* if (trie_vip_zombie_classes)
1984 TrieDestroy(trie_vip_zombie_classes)
1985#if MODIFICATION == NEW
1986 if (trie_vip_human_classes)
1987 TrieDestroy(trie_vip_human_classes)
1988#endif
1989#if EXTRA_ITEMS == ON
1990 if (trie_vip_extra_items)
1991 TrieDestroy(trie_vip_extra_items)
1992#if MODIFICATION != NEW
1993 if (array_vip_extra_items)
1994 ArrayDestroy(array_vip_extra_items)
1995#endif
1996#endif
1997 if (trie_vips_database)
1998 TrieDestroy(trie_vips_database)
1999 if (array_vips_database_nick)
2000 ArrayDestroy(array_vips_database_nick)
2001 */
2002}
2003/*encode_date(d[]) { // TOOD: delete
2004
2005 new ret
2006 d[4] = d[7] = EOS
2007 ret += str_to_num(d)
2008 ret = (ret<<8)
2009 ret += str_to_num(d[5])
2010 ret = (ret<<8)
2011 ret += str_to_num(d[8])
2012
2013 return ret
2014}
2015
2016decode_date(d, ds[]) {
2017
2018 num_to_str((d>>16), ds, 4)
2019 num_to_str((d>>8)&0xFF, ds[5], 4)
2020 num_to_str(d&0xFF, ds[8], 4)
2021 ds[4] = ds[7] = ':'
2022 ds[10] = EOS
2023}*/
2024stock zv_get_currency() {
2025#if MODIFICATION == NEW
2026 if (is_module_ammopacks_loaded)
2027 return CURRENCY_AMMO_PACKS;
2028 else
2029 return CURRENCY_MONEY;
2030#endif
2031 return CURRENCY_AMMO_PACKS;
2032}
2033stock zv_currency_give(id, amount) {
2034#if MODIFICATION == NEW
2035 if (is_module_ammopacks_loaded)
2036 zp_ammopacks_set(id, zp_ammopacks_get(id)+amount)
2037 else
2038 cs_set_user_money(id, cs_get_user_money(id)+amount)
2039#else
2040 zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id)+amount)
2041#endif
2042}
2043stock zv_currency_set(id, amount) {
2044#if MODIFICATION == NEW
2045 if (is_module_ammopacks_loaded)
2046 zp_ammopacks_set(id, amount)
2047 else
2048 cs_set_user_money(id, amount)
2049#else
2050 zp_set_user_ammo_packs(id, amount)
2051#endif
2052}
2053stock zv_currency_get(id) {
2054#if MODIFICATION == NEW
2055 if (is_module_ammopacks_loaded)
2056 return zp_ammopacks_get(id)
2057 else
2058 return cs_get_user_money(id)
2059
2060 return 0;
2061#else
2062 return zp_get_user_ammo_packs(id)
2063#endif
2064}
2065#if VIPS_FILE_SYSTEM != OFF
2066load_ini_file() {
2067
2068 new vipsfile[70]
2069 get_configsdir(vipsfile, charsmax(vipsfile))
2070 format(vipsfile, charsmax(vipsfile), "%s/%s", vipsfile, VIPS_FILE)
2071 new handle = fopen(vipsfile, "rt")
2072
2073 new tempfilename[] = "temp.file";
2074 new temph = fopen(tempfilename, "wt")
2075
2076 if(handle) {
2077
2078 new vip_data[vips_database_type]
2079
2080 new str_auth[50], data1[30], data2[30]
2081 new /*ret, */bool:comma_open, bool:line_removed = false
2082 new line[200], line_num, line_len;
2083 new i=0, s=0
2084 new datatype = 0
2085 new timestamp = get_systime()
2086 //new AuthType:authtype
2087
2088 while(!feof(handle)) {
2089
2090 comma_open = false
2091 line_len = fgets(handle, line, charsmax(line))
2092 line_num++
2093
2094 i = 0
2095 datatype = 0
2096
2097 if (line[i] == ';'
2098 || line[i] == '/'
2099 || line[i] == 'X'
2100 || line[i] == EOS) {
2101 fputs(temph, line)
2102 continue;
2103 }
2104
2105 vip_data[AUTH][0] = EOS
2106 vip_data[PASS][0] = EOS
2107 vip_data[SETTINGS] = 0
2108 vip_data[FLAGS] = 0
2109 vip_data[TIMESTAMP] = 0
2110
2111 for(;;) {
2112 switch (line[i]) {
2113 case 'C': vip_data[SETTINGS] |= FLAG_C
2114 case 'N': vip_data[SETTINGS] |= FLAG_N
2115 case 'F': vip_data[SETTINGS] |= FLAG_F
2116 case 'K': vip_data[SETTINGS] |= FLAG_K
2117 default: goto loop_exit;
2118 }
2119 i++
2120 }
2121
2122 loop_exit:
2123
2124 for (;;) {
2125
2126 if (i > charsmax(line)) {
2127 log_amx("ERROR: ^"%s^" Syntax error on line (%d:%d):^n^"%s^".^nLine too long.", VIPS_FILE, line_num, i+1, line)
2128 fputs(temph, line)
2129 goto global_continue;
2130 }
2131 if (line[i] == '"') {
2132
2133 comma_open = !comma_open
2134 i++
2135
2136 if (comma_open) datatype++
2137 else {
2138 switch (datatype) {
2139
2140 case 1: str_auth[s] = EOS
2141 case 2: data1[s] = EOS
2142 case 3: data2[s] = EOS
2143 default: {
2144 log_amx("ERROR: ^"%s^" Syntax error on line (%d:%d):^n^"%s^". Too many parameters.", VIPS_FILE, line_num, i+1, line)
2145 fputs(temph, line)
2146 goto global_continue;
2147 }
2148 }
2149 }
2150 s = 0
2151 continue;
2152 }
2153
2154 if (comma_open) {
2155
2156 switch (datatype) {
2157
2158 case 1: str_auth[s++] = line[i]
2159 case 2: data1[s++] = line[i]
2160 case 3: data2[s++] = line[i]
2161 }
2162 }
2163 else if (line[i] == '|') {
2164
2165 new idx, fidx
2166 static frmt[] = "|//|:|"
2167 idx = i
2168 fidx = 0
2169
2170 while (i < line_len) {
2171
2172 if (frmt[fidx] == line[i]) {
2173 if (++fidx == charsmax(frmt))
2174 break;
2175 }
2176 else if (line[i] > '9' || line[i] < '0')
2177 break;
2178 i++
2179 }
2180
2181 if (fidx == charsmax(frmt) && i < line_len) {
2182 vip_data[TIMESTAMP] = parse_time(line[idx], "|%Y/%m/%d|%H:%M|")
2183 break;
2184 }
2185 else {
2186 log_amx("ERROR: ^"%s^" Syntax error on line (%d:%d):^n^"%s^". Incorrect time.", VIPS_FILE, line_num, i+1, line)
2187 fputs(temph, line)
2188 goto global_continue;
2189 }
2190 }
2191 else if (line[i] == '^r' || line[i] == EOS || line[i] == '^n') {
2192 break;
2193 }
2194 else if (line[i] != ' ') {
2195 log_amx("ERROR: ^"%s^" Syntax error on line (%d:%d):^n^"%s^". Unknown symbol '%c'.", VIPS_FILE, line_num, i+1, line, line[i])
2196 fputs(temph, line)
2197 goto global_continue;
2198 }
2199 i++
2200 }
2201
2202 switch (datatype) {
2203 case 1: {
2204 vip_data[FLAGS] = -1
2205 }
2206 case 2: {
2207 vip_data[FLAGS] = read_flags(data1)
2208 }
2209 case 3: {
2210 copy(vip_data[PASS], charsmax(vip_data[PASS]), data1)
2211 vip_data[FLAGS] = read_flags(data2)
2212 }
2213 }
2214
2215 copy(vip_data[AUTH], charsmax(vip_data[AUTH]), str_auth)
2216
2217 if (!(vip_data[SETTINGS] & (FLAG_C|FLAG_N|FLAG_F)))
2218 strtoupper(vip_data[AUTH])
2219
2220 vip_data[SETTINGS] |= LOAD_FROM_INI
2221 VIPINC(INI)
2222
2223 VipsDBInsert(vip_data)
2224
2225 if (vip_data[TIMESTAMP] > 0 && timestamp > vip_data[TIMESTAMP]) {
2226 line_removed = true
2227 continue;
2228 }
2229
2230 fputs(temph, line)
2231
2232 global_continue:
2233 }
2234
2235
2236 fclose(handle)
2237 fclose(temph)
2238
2239 if(line_removed) {
2240
2241 delete_file(vipsfile)
2242 while (!rename_file(tempfilename, vipsfile, 1)) { }
2243 }
2244 else {
2245 delete_file(tempfilename)
2246 }
2247 }
2248 else log_amx("ERROR: Missing %s file in configs folder. Can't load zm_vip privileges.", VIPS_FILE)
2249}
2250remove_from_ini(data[vips_database_type]) {
2251
2252 if (!VIPCNT(INI))
2253 return;
2254
2255 new vipsfile[70]
2256 get_configsdir(vipsfile, charsmax(vipsfile))
2257 format(vipsfile, charsmax(vipsfile), "%s/%s", vipsfile, VIPS_FILE)
2258 new handle = fopen(vipsfile, "r+")
2259
2260 if (handle) {
2261
2262 new i, line[200], line_len, start
2263
2264 while(!feof(handle)) {
2265
2266 line_len = fgets(handle, line, charsmax(line))
2267 i = 0
2268
2269 if (line[i] == ';'
2270 || line[i] == '/'
2271 || line[i] == 'X'
2272 || line[i] == EOS) {
2273 continue;
2274 }
2275
2276 start = 0
2277 while (start < line_len) {
2278
2279 if (line[start++] == '"')
2280 break;
2281 }
2282
2283 if (start >= line_len) continue;
2284
2285 while (start < line_len) {
2286
2287 if (line[start] == '"') {
2288 line[start] = EOS
2289 break;
2290 }
2291 start++
2292 }
2293
2294 if (start >= line_len) continue;
2295
2296 strtoupper(line[start])
2297 if (equal(line[start], data[AUTH])) {
2298 fseek(handle, -line_len, SEEK_CUR)
2299 fputc(handle, 'X')
2300 VIPDEC(INI)
2301 break;
2302 }
2303 }
2304 fclose(handle)
2305 }
2306 else
2307 log_amx("ERROR: Failed to read '%s' file.", vipsfile)
2308}
2309add_to_ini(data[vips_database_type]) {
2310
2311 new vipsfile[70]
2312 get_configsdir(vipsfile, charsmax(vipsfile))
2313 format(vipsfile, charsmax(vipsfile), "%s/%s", vipsfile, VIPS_FILE)
2314 new handle = fopen(vipsfile, "at")
2315
2316 if (handle) {
2317 new line[120], len
2318 len += formatex(line, charsmax(line),
2319 "%s%s%s%s ^"%s^"",
2320 data[SETTINGS]&FLAG_C?"C":"",
2321 data[SETTINGS]&FLAG_N?"N":"",
2322 data[SETTINGS]&FLAG_F?"F":"",
2323 data[SETTINGS]&FLAG_K?"K":"",
2324 data[AUTH])
2325
2326 if (!EMPTY(data[PASS]))
2327 len += formatex(line[len], charsmax(line)-len, " ^"%s^"", data[PASS])
2328
2329 if (data[FLAGS] != -1) {
2330 new flags_str[30]
2331 get_flags(data[FLAGS], flags_str, charsmax(flags_str))
2332 len += formatex(line[len], charsmax(line)-len, " ^"%s^"", flags_str)
2333 }
2334
2335 if (data[TIMESTAMP])
2336 len += format_time(line[len], charsmax(line)-len, " |%Y/%m/%d|%H:%M|", data[TIMESTAMP])
2337
2338 VIPINC(INI)
2339 fputs(handle, line)
2340 fclose(handle)
2341 }
2342}
2343#endif
2344convert_duration_to_string(id, duration, string[], len) {
2345
2346 if (duration == ZV_DURATION_TILL_MAP) {
2347 LookupLangKey(string, len, "TILL_MAPCHANGE", id)
2348 return;
2349 }
2350 else if (duration == ZV_DURATION_TILL_DISCONNECT) {
2351 LookupLangKey(string, len, "TILL_DISCONNECT", id)
2352 return;
2353 }
2354
2355 new index, time_unit[20] = {' '}, unit
2356 new week_word[][] = {"WEEK", "WEEKS", "WEEKSW"}
2357 new day_word[][] = {"DAY", "DAYS", "DAYSW"}
2358 new hour_word[][] = {"HOUR", "HOURS", "HOURSW"}
2359 new minute_word[][] = {"MINUTE", "MINUTES", "MINUTESW"}
2360 new second_word[][] = {"SECOND", "SECONDS", "SECONDSW"}
2361
2362 if (duration >= 604800) {
2363 unit = duration/604800
2364
2365 index += num_to_str(unit, string[index], len-index)
2366 LookupLangKey(time_unit[1], charsmax(time_unit),
2367 week_word[(unit%10==1)?0:((unit%10==0||10<unit%100<20)?2:1)], id)
2368 index += add(string[index], len-index, time_unit)
2369 duration %= 604800
2370 }
2371 if (duration >= 86400) {
2372 if (index) { string[index] = ' '; string[++index] = EOS; }
2373 unit = duration/86400
2374 index += num_to_str(unit, string[index], len-index)
2375 LookupLangKey(time_unit[1], charsmax(time_unit),
2376 day_word[(unit%10==1)?0:((unit%10==0||10<unit%100<20)?2:1)], id)
2377 index += add(string[index], len-index, time_unit)
2378 duration %= 86400
2379 }
2380 if (duration >= 3600) {
2381 if (index) { string[index] = ' '; string[++index] = EOS; }
2382 unit = duration/3600
2383 index += num_to_str(unit, string[index], len-index)
2384 LookupLangKey(time_unit[1], charsmax(time_unit),
2385 hour_word[(unit%10==1)?0:((unit%10==0||10<unit%100<20)?2:1)], id)
2386 index += add(string[index], len-index, time_unit)
2387 duration %= 3600
2388 }
2389 if (duration >= 60) {
2390 if (index) { string[index] = ' '; string[++index] = EOS; }
2391 unit = duration/60
2392 index += num_to_str(unit, string[index], len-index)
2393 LookupLangKey(time_unit[1], charsmax(time_unit),
2394 minute_word[(unit%10==1)?0:((unit%10==0||10<unit%100<20)?2:1)], id)
2395 index += add(string[index], len-index, time_unit)
2396 duration %= 60
2397 }
2398 if (duration) {
2399 if (index) { string[index] = ' '; string[++index] = EOS; }
2400 index += num_to_str(duration, string[index], len-index)
2401 LookupLangKey(time_unit[1], charsmax(time_unit),
2402 second_word[(duration%10==1)?0:((duration%10==0||10<duration%100<20)?2:1)], id)
2403 index += add(string[index], len-index, time_unit)
2404 }
2405}
2406
2407get_cvar_duration(cvar) {
2408
2409 new dur[20], duration
2410 get_pcvar_string(cvar, dur, charsmax(dur))
2411
2412 new len = strlen(dur)
2413
2414 if (len) {
2415
2416 switch (dur[len-1]) {
2417
2418 case 'w': {
2419 dur[len-1] = EOS
2420 duration = str_to_num(dur)
2421 if (duration) {
2422 duration *= 7*24*3600
2423 }
2424 }
2425 case 'd': {
2426 dur[len-1] = EOS
2427 duration = str_to_num(dur)
2428 if (duration) {
2429 duration *= 24*3600
2430 }
2431 }
2432 case 'h': {
2433 dur[len-1] = EOS
2434 duration = str_to_num(dur)
2435 if (duration) {
2436 duration *= 3600
2437 }
2438 }
2439 case 's': {
2440 dur[len-1] = EOS
2441 duration = str_to_num(dur)
2442 }
2443 case 'm': {
2444 if (len-2 >= 0 && dur[len-2] == 't') {
2445 goto case_t
2446 }
2447 dur[len-1] = EOS
2448 duration = str_to_num(dur)
2449 if (duration) {
2450 duration *= 60
2451 }
2452 }
2453 case 't': {
2454 case_t:
2455
2456 duration = ZV_DURATION_TILL_DISCONNECT
2457 if (dur[len-1] == 'm') {
2458 duration = ZV_DURATION_TILL_MAP
2459 }
2460 }
2461 default: {
2462
2463 duration = str_to_num(dur)
2464 if (duration > 0) {
2465 duration *= 24*3600
2466 }
2467 else {
2468 log_amx("WARNING: Incorrect zm_vip_buy_duration cvar value ^"%s^".", dur)
2469 return -1;
2470 }
2471 }
2472 }
2473 }
2474
2475 return duration
2476}
2477add_to_datafile(data[vips_database_type]) {
2478
2479 new datafile[70]
2480 get_datadir(datafile, charsmax(datafile))
2481 add(datafile, charsmax(datafile), "/zm_vip.dat")
2482
2483 new handle = fopen(datafile, "ab")
2484
2485 if (handle) {
2486
2487 fwrite_blocks(handle, data, 70, BLOCK_CHAR)
2488 fwrite_raw(handle, data[SETTINGS], 4, 3)
2489 fclose(handle)
2490 VIPINC(DAT)
2491 }
2492 else
2493 log_amx("ERROR: Failed to write '%s' file.", datafile)
2494}
2495
2496remove_from_datafile(data[vips_database_type]) {
2497
2498 if (!(data[SETTINGS] & LOAD_FROM_DAT))
2499 return;
2500
2501 new datafile[70], bytes_in_file
2502 get_datadir(datafile, charsmax(datafile))
2503 add(datafile, charsmax(datafile), "/zm_vip.dat")
2504
2505 bytes_in_file = file_size(datafile)
2506
2507 new handle = fopen(datafile, "r+")
2508
2509 if (handle) {
2510
2511 new auth[sizeof(data[AUTH])]
2512 while (ftell(handle) < bytes_in_file) {
2513
2514 fread_blocks(handle, auth, sizeof(data[AUTH]), BLOCK_CHAR)
2515
2516 if (equal(auth, data[AUTH])) {
2517 fseek(handle, -sizeof(data[AUTH]), SEEK_CUR)
2518 fputc(handle, 0)
2519 VIPDEC(DAT)
2520
2521 fseek(handle, sizeof(data[AUTH])+sizeof(data[PASS])+12-1, SEEK_CUR)
2522 }
2523 else {
2524 fseek(handle, sizeof(data[PASS])+12, SEEK_CUR)
2525 }
2526 }
2527 fclose(handle)
2528 }
2529 else
2530 log_amx("ERROR: Failed to read '%s' file.", datafile)
2531}
2532load_datafile() {
2533
2534 new datafile[70]
2535 get_datadir(datafile, charsmax(datafile))
2536 add(datafile, charsmax(datafile), "/zm_vip.dat")
2537
2538 if (!file_exists(datafile))
2539 return;
2540
2541 new handle = fopen(datafile, "rb")
2542
2543 if (handle) {
2544
2545 new data[vips_database_type]
2546 while (!feof(handle)) {
2547
2548 fread_blocks(handle, data, 70, BLOCK_CHAR)
2549 fread_raw(handle, data[SETTINGS], 4, 3)
2550
2551 if (EMPTY(data[AUTH])) {
2552 dummy_record_count++
2553 continue;
2554 }
2555 data[SETTINGS] &= ~LOAD_MASK
2556 data[SETTINGS] |= LOAD_FROM_DAT
2557 VIPINC(DAT)
2558
2559 VipsDBInsert(data)
2560 }
2561 fclose(handle)
2562 }
2563 else
2564 log_amx("ERROR: Failed to read '%s' file.", datafile)
2565}
2566
2567write_datafile() {
2568
2569 new datafile[70]
2570 get_datadir(datafile, charsmax(datafile))
2571 add(datafile, charsmax(datafile), "/zm_vip.dat")
2572
2573 if (!VIPCNT(DAT) && file_exists(datafile)) {
2574 delete_file(datafile)
2575 return;
2576 }
2577
2578 new handle = fopen(datafile, "wb")
2579
2580 if (handle) {
2581
2582 new key[40], i, size = ArraySize(array_vips_database)
2583 new data[vips_database_type]
2584 new timestamp = get_systime()
2585
2586 for (i=0; i<size; i++) {
2587
2588 ArrayGetString(array_vips_database, i, key, sizeof(key))
2589
2590 if (EMPTY(key))
2591 continue;
2592
2593 if (!TrieGetArray(trie_vips_database, key, data, vips_database_type))
2594 continue;
2595
2596 if (!(data[SETTINGS] & LOAD_FROM_DAT))
2597 continue;
2598
2599 if (data[TIMESTAMP] == ZV_DURATION_TILL_MAP)
2600 continue;
2601
2602 if (data[TIMESTAMP] == ZV_DURATION_TILL_DISCONNECT) {
2603
2604 if (data[PASS][charsmax(data[PASS])]+1
2605 < floatround(get_gametime()*100, floatround_floor))
2606 continue;
2607 else
2608 data[PASS][charsmax(data[PASS])] = EOS
2609 }
2610
2611 if (data[TIMESTAMP] <= timestamp)
2612 continue
2613
2614 fwrite_blocks(handle, data, 70, BLOCK_CHAR)
2615 fwrite_raw(handle, data[SETTINGS], 4, 3)
2616 }
2617
2618 if (array_vips_database_nick) {
2619 size = ArraySize(array_vips_database_nick)
2620 for (i=0; i<size; i++) {
2621
2622 ArrayGetArray(array_vips_database_nick, i, data)
2623
2624 if (EMPTY(data[AUTH]))
2625 continue;
2626
2627 if (data[TIMESTAMP] == ZV_DURATION_TILL_MAP)
2628 continue;
2629
2630 if (data[TIMESTAMP] == ZV_DURATION_TILL_DISCONNECT) {
2631
2632 if (data[PASS][charsmax(data[PASS])]+1
2633 < floatround(get_gametime()*100, floatround_floor))
2634 continue;
2635 else
2636 data[PASS][charsmax(data[PASS])] = EOS
2637 }
2638
2639 if (data[TIMESTAMP] <= timestamp)
2640 continue
2641
2642 data[SETTINGS] &= ~LOAD_MASK
2643 fwrite_blocks(handle, data, 70, BLOCK_CHAR)
2644 fwrite_raw(handle, data[SETTINGS], 4, 3)
2645 }
2646 }
2647
2648 fclose(handle)
2649 }
2650 else
2651 log_amx("ERROR: Failed to write '%s' file.", datafile)
2652}
2653
2654print_admin_contacts(id) {
2655
2656 new contact[60]
2657 get_cvar_string("amx_contactinfo", contact, charsmax(contact))
2658 if(!EMPTY(contact)) {
2659 if (is_amxmodx_new_version) client_print_color(id, id, "^4%L: ^1%s.", id, "ADMIN_CONTACTS", contact)
2660 else _client_print_color(id, "^4%L: ^1%s.", id, "ADMIN_CONTACTS", contact)
2661 }
2662}
2663
2664public show_vip_timeleft(id) {
2665
2666 new timeleft[100]
2667 if (!p_data[id][TIMESTAMP])
2668 LookupLangKey(timeleft, charsmax(timeleft), "PERMANENT", id)
2669 else
2670 convert_duration_to_string(id, max(p_data[id][TIMESTAMP]-get_systime(), 0), timeleft, charsmax(timeleft))
2671
2672 if (is_amxmodx_new_version) {
2673 set_dhudmessage(51, 118, 4, 0.02, 0.52, 0, 6.0, 0.9, 0.1, 0.3)
2674 show_dhudmessage(id, "VIP: %s", timeleft)
2675 }
2676 else {
2677 _set_dhudmessage(51, 118, 4, 0.02, 0.52, 0, 6.0, 0.9, 0.1, 0.3)
2678 _show_dhudmessage(id, "VIP: %s", timeleft)
2679 }
2680}
2681stock timestamp_to_date(stamp, date_str[], dchars, time_str[], tchars) {
2682
2683 new y=1970, m=1, d=1, cstamp = stamp
2684 new hours, mins
2685
2686 while(cstamp >= 31536000) {
2687
2688 cstamp -= (!(y%400)||((y%100)&&!(y%4)))?31622400:31536000
2689 y++;
2690 }
2691
2692 while(cstamp >= 2419200) {
2693
2694 switch(m) {
2695 case 2, 4, 6, 9: cstamp -= (!(y%400)||((y%100)&&!(y%4)))?2505600:2419200
2696 case 11: cstamp -= 2592000
2697 case 1, 3, 5, 7, 8, 10, 12: cstamp -= 2678400
2698 }
2699 m++
2700 }
2701
2702 while(cstamp >= 86400) {
2703
2704 cstamp -= 86400
2705 d++
2706 }
2707
2708 hours = cstamp/3600
2709 mins = (cstamp%3600)/60
2710
2711 formatex(date_str, dchars, "%d/%d/%d%", y, m, d)
2712 formatex(time_str, tchars, "%d:%d", hours, mins)
2713}
2714/*stock date_to_timestamp(date_str[], time_str[]) {
2715
2716 new y, m, d, i
2717 new hours, mins
2718 new temp_str[15], num[6]
2719 strtok(date_str, num, charsmax(num), temp_str, charsmax(temp_str), '/')
2720 y = str_to_num(num)
2721 strtok(temp_str, num, charsmax(num), temp_str, charsmax(temp_str), '/')
2722 m = str_to_num(num)
2723 d = str_to_num(temp_str)
2724 strtok(time_str, num, charsmax(num), temp_str, charsmax(temp_str), ':')
2725 hours = str_to_num(num)
2726 mins = str_to_num(temp_str)
2727
2728 new stamp
2729
2730 for (i=1970; y > i; i++)
2731 stamp += (!(i%400)||((i%100)&&!(i%4)))?31622400:31536000
2732
2733 for (i=1; m > i; i++) {
2734
2735 switch(i) {
2736 case 2, 4, 6, 9: stamp += (!(y%400)||((y%100)&&!(y%4)))?2505600:2419200
2737 case 11: stamp += 2592000
2738 case 1, 3, 5, 7, 8, 10, 12: stamp += 2678400
2739 }
2740 }
2741 stamp += d*86400
2742 stamp += hours*3600
2743 stamp += mins*60
2744 return stamp;
2745}*/
2746
2747stock findtag(msg[], tag[]) {
2748
2749 static i, d
2750 i = 0
2751 while (msg[i] != EOS) {
2752 if (msg[i] == tag[0]) {
2753
2754 d = 0
2755 while (tag[d]!=EOS&&msg[i+d]!=EOS) {
2756 if (tag[d]!=msg[i+d] && ((65<=tag[d]<=90) && (tag[d]+32)!=msg[i+d]))
2757 break;
2758 d++
2759 }
2760 if (tag[d] == EOS) {
2761 return i;
2762 }
2763 }
2764 i++
2765 }
2766 return -1;
2767}
2768stock read_config(cvar[], value[], len) {
2769
2770 new directory[40]
2771 get_configsdir(directory, charsmax(directory))
2772 format(directory, charsmax(directory), "%s/%s", directory, CONFIGS_FILE)
2773 value[0] = EOS
2774
2775 new handle = fopen(directory, "rt")
2776 if (handle) {
2777
2778 new line[100], place
2779 while (!feof(handle)) {
2780 fgets(handle, line, charsmax(line))
2781
2782 if ((place = contain(line, cvar)) != -1) {
2783
2784 while (line[place] != '"' && line[place] != EOS) { place++; }
2785
2786 if (line[place] == '"') {
2787
2788 place++
2789 new index
2790 while (line[place] != '"' && line[place] != EOS && index < len) {
2791
2792 value[index++] = line[place++]
2793 }
2794 value[index] = EOS
2795 break;
2796 }
2797 }
2798 }
2799 fclose(handle)
2800 }
2801}
2802#if AMXX_VERSION_NUM < 183
2803native client_print_color(index, sender, const message[], any:...);
2804#endif
2805stock _client_print_color(id, const message[], any:...)
2806{
2807 static buffer[512], argscount
2808 argscount = numargs()
2809
2810 if (!id) {
2811
2812 static players[32], num, player, i, i2
2813 get_players(players, num , "ch")
2814
2815 for (i = 0; i < num; i++) {
2816
2817 player = players[i]
2818
2819 static changed[5], changedcount
2820 changedcount = 0
2821
2822 for (i2 = 2; i2 < argscount; i2++)
2823 {
2824 if (getarg(i2) == LANG_PLAYER)
2825 {
2826 setarg(i2, 0, player)
2827 changed[changedcount] = i2
2828 changedcount++
2829 }
2830 }
2831
2832 vformat(buffer, charsmax(buffer), message, 3)
2833
2834 message_begin(MSG_ONE_UNRELIABLE, msg_saytext, _, player)
2835 write_byte(player)
2836 write_string(buffer)
2837 message_end()
2838
2839 for (i2 = 0; i2 < changedcount; i2++)
2840 setarg(changed[i2], 0, LANG_PLAYER)
2841 }
2842 }
2843 else {
2844
2845 vformat(buffer, charsmax(buffer), message, 3)
2846
2847 message_begin(MSG_ONE_UNRELIABLE, msg_saytext, _, id)
2848 write_byte(id)
2849 write_string(buffer)
2850 message_end()
2851 }
2852}
2853
2854stock __dhud_color;
2855stock __dhud_x;
2856stock __dhud_y;
2857stock __dhud_effect;
2858stock __dhud_fxtime;
2859stock __dhud_holdtime;
2860stock __dhud_fadeintime;
2861stock __dhud_fadeouttime;
2862stock __dhud_reliable;
2863
2864#if AMXX_VERSION_NUM < 183
2865native set_dhudmessage(red=200, green=100, blue=0, Float:x=-1.0, Float:y=0.35, effects=0, Float:fxtime=6.0, Float:holdtime=12.0, Float:fadeintime=0.1, Float:fadeouttime=0.2);
2866#endif
2867stock _set_dhudmessage( red = 0, green = 160, blue = 0, Float:x = -1.0, Float:y = 0.65, effects = 2, Float:fxtime = 6.0, Float:holdtime = 3.0, Float:fadeintime = 0.1, Float:fadeouttime = 1.5, bool:reliable = false )
2868{
2869 #define clamp_byte(%1) ( clamp( %1, 0, 255 ) )
2870 #define pack_color(%1,%2,%3) ( %3 + ( %2 << 8 ) + ( %1 << 16 ) )
2871
2872 __dhud_color = pack_color( clamp_byte( red ), clamp_byte( green ), clamp_byte( blue ) );
2873 __dhud_x = _:x;
2874 __dhud_y = _:y;
2875 __dhud_effect = effects;
2876 __dhud_fxtime = _:fxtime;
2877 __dhud_holdtime = _:holdtime;
2878 __dhud_fadeintime = _:fadeintime;
2879 __dhud_fadeouttime = _:fadeouttime;
2880 __dhud_reliable = _:reliable;
2881
2882 return 1;
2883}
2884#if AMXX_VERSION_NUM < 183
2885native show_dhudmessage(index, const message[], any:...);
2886#endif
2887stock _show_dhudmessage(index, const message[], any:... )
2888{
2889 new buffer[ 128 ];
2890 new numArguments = numargs();
2891
2892 if( numArguments == 2 )
2893 {
2894 send_dhudMessage( index, message );
2895 }
2896 else if( index || numArguments == 3 )
2897 {
2898 vformat( buffer, charsmax( buffer ), message, 3 );
2899 send_dhudMessage( index, buffer );
2900 }
2901 else
2902 {
2903 new playersList[ 32 ], numPlayers;
2904 get_players( playersList, numPlayers, "ch" );
2905
2906 if( !numPlayers )
2907 {
2908 return 0;
2909 }
2910
2911 new Array:handleArrayML = ArrayCreate();
2912
2913 for( new i = 2, j; i < numArguments; i++ )
2914 {
2915 if( getarg( i ) == LANG_PLAYER )
2916 {
2917 while( ( buffer[ j ] = getarg( i + 1, j++ ) ) ) {}
2918 j = 0;
2919
2920 if( GetLangTransKey( buffer ) != TransKey_Bad )
2921 {
2922 ArrayPushCell( handleArrayML, i++ );
2923 }
2924 }
2925 }
2926
2927 new size = ArraySize( handleArrayML );
2928
2929 if( !size )
2930 {
2931 vformat( buffer, charsmax( buffer ), message, 3 );
2932 send_dhudMessage( index, buffer );
2933 }
2934 else
2935 {
2936 for( new i = 0, j; i < numPlayers; i++ )
2937 {
2938 index = playersList[ i ];
2939
2940 for( j = 0; j < size; j++ )
2941 {
2942 setarg( ArrayGetCell( handleArrayML, j ), 0, index );
2943 }
2944
2945 vformat( buffer, charsmax( buffer ), message, 3 );
2946 send_dhudMessage( index, buffer );
2947 }
2948 }
2949
2950 ArrayDestroy( handleArrayML );
2951 }
2952
2953 return 1;
2954}
2955stock send_dhudMessage( const index, const message[] )
2956{
2957 message_begin( __dhud_reliable ? ( index ? MSG_ONE : MSG_ALL ) : ( index ? MSG_ONE_UNRELIABLE : MSG_BROADCAST ), SVC_DIRECTOR, _, index );
2958 {
2959 write_byte( strlen( message ) + 31 );
2960 write_byte( DRC_CMD_MESSAGE );
2961 write_byte( __dhud_effect );
2962 write_long( __dhud_color );
2963 write_long( __dhud_x );
2964 write_long( __dhud_y );
2965 write_long( __dhud_fadeintime );
2966 write_long( __dhud_fadeouttime );
2967 write_long( __dhud_holdtime );
2968 write_long( __dhud_fxtime );
2969 write_string( message );
2970 }
2971 message_end();
2972}
2973
2974VipsItemIs(ClassType:type, itemid) {
2975
2976 static strnum[6]
2977 num_to_str(itemid, strnum[1], charsmax(strnum)-1)
2978 strnum[0] = _:type
2979
2980 return TrieKeyExists(trie_vip_items, strnum)
2981}
2982VipsItemSet(ClassType:type, itemid) {
2983
2984 if (!trie_vip_items)
2985 trie_vip_items = TrieCreate()
2986
2987 new strnum[6]
2988 num_to_str(itemid, strnum[1], charsmax(strnum)-1)
2989 strnum[0] = _:type
2990
2991 return TrieSetCell(trie_vip_items, strnum, 1)
2992}
2993
2994stock VipsDBGet(const id) {
2995
2996 if (!(1 <= id < 33))
2997 return false;
2998
2999 p_data[id][FLAGS] = 0
3000 p_data[id][SETTINGS] = 0
3001
3002 if (!VIPCNT(DAT) && !VIPCNT(INI) && !VIPCNT(AMX))
3003 return false;
3004
3005 static authid[30], ip[30], name[45]
3006 get_user_info(id, "name", name, charsmax(name))
3007 get_user_authid(id, authid, charsmax(authid))
3008 get_user_ip(id, ip, charsmax(ip), 1)
3009
3010 static uppername[45], client_password[30]
3011
3012 copy(uppername, charsmax(uppername), name)
3013 strtoupper(uppername)
3014 get_user_info(id, amx_password_field_string, client_password, charsmax(client_password))
3015
3016 if (VIPCNT(MAIN) && TrieGetArray(trie_vips_database, authid, p_data[id], vips_database_type))
3017 { p_data[id][SETTINGS] |= LOAD_FROM_MAIN; }
3018 else if(VIPCNT(MAIN) && TrieGetArray(trie_vips_database, ip, p_data[id], vips_database_type))
3019 { p_data[id][SETTINGS] |= LOAD_FROM_MAIN; }
3020 else if(VIPCNT(MAIN) && TrieGetArray(trie_vips_database, uppername, p_data[id], vips_database_type))
3021 { p_data[id][SETTINGS] |= LOAD_FROM_MAIN; }
3022 else if (VIPCNT(NAMES) && check_named_privileges(id, name, client_password) > 0)
3023 { p_data[id][SETTINGS] |= LOAD_FROM_NAMES; }
3024
3025 if (!EMPTY(p_data[id][PASS]) && p_data[id][SETTINGS] & FLAG_K && !equal(p_data[id][PASS], client_password)) {
3026 p_data[id][SETTINGS] = 0
3027 p_data[id][FLAGS] = 0
3028 server_cmd("kick #%d ^"[ZMVIP] %L.^"", get_user_userid(id), id, "INVALID_PASS")
3029 return false;
3030 }
3031
3032#if VIPS_FILE_SYSTEM != FORCED
3033 if(get_user_flags(id) & VIP_SYS_FLAG) {
3034
3035 new flags = _get_pcvar_flags(cvar_amx_auth_flags)
3036 if (flags == 0)
3037 p_data[id][FLAGS] = -1
3038 else
3039 p_data[id][FLAGS] |= flags
3040 p_data[id][TIMESTAMP] = 0
3041 p_data[id][SETTINGS] |= LOAD_FROM_AMX
3042 }
3043#endif
3044 if (p_data[id][FLAGS]) {
3045 new flags = _get_pcvar_flags(cvar_amxmodx_flags)
3046 if (flags > 0)
3047 set_user_flags(id, flags)
3048 }
3049
3050 if (!p_data[id][FLAGS]) {
3051 p_data[id][SETTINGS] = 0
3052 p_data[id][TIMESTAMP] = 0
3053 arrayset(p_attribs[id], 0, player_attributes)
3054 return false;
3055 }
3056
3057 console_print(id, "* VIP Privileges set")
3058 return true;
3059}
3060
3061
3062stock VipsDBSet(const id) {
3063
3064 if (!(1 <= id < 33))
3065 return false;
3066
3067 if (p_data[id][SETTINGS]&LOAD_MASK) {
3068
3069 if (p_data[id][SETTINGS]&(LOAD_FROM_MAIN)) {
3070 TrieSetArray(trie_vips_database, p_data[id][AUTH], p_data[id], vips_database_type)
3071 }
3072 else if (p_data[id][SETTINGS]&LOAD_FROM_NAMES) {
3073 ArraySetArray(array_vips_database_nick, p_data[id][INDEX], p_data[id])
3074 }
3075#if VIPS_FILE_SYSTEM != FORCED
3076 else if (p_data[id][SETTINGS]&LOAD_FROM_AMX) {
3077
3078 p_data[id][SETTINGS] = 0
3079 VipsDBSet(id)
3080 }
3081#endif
3082#if VIPS_FILE_SYSTEM != OFF
3083 if (p_data[id][SETTINGS]&LOAD_FROM_INI) {
3084 remove_from_ini(p_data[id])
3085 add_to_ini(p_data[id])
3086 }
3087 else if (p_data[id][SETTINGS]&LOAD_FROM_DAT) {
3088 remove_from_datafile(p_data[id])
3089 add_to_datafile(p_data[id])
3090 }
3091#else
3092 remove_from_datafile(p_data[id])
3093 add_to_datafile(p_data[id])
3094#endif
3095 return true;
3096 }
3097
3098 get_user_authid(id, p_data[id][AUTH], charsmax(p_data[][AUTH]))
3099 if (p_data[id][AUTH][7] != ':')
3100 get_user_ip(id, p_data[id][AUTH], charsmax(p_data[][AUTH]), 1)
3101
3102 p_data[id][PASS] = EOS
3103#if VIPS_FILE_SYSTEM != OFF
3104 if (get_pcvar_num(cvar_vip_store_ini)&&(p_data[id][TIMESTAMP]!=ZV_DURATION_TILL_MAP)){
3105
3106 p_data[id][SETTINGS] = LOAD_FROM_INI
3107 }
3108 else {
3109 p_data[id][SETTINGS] = LOAD_FROM_DAT
3110 }
3111#else
3112 p_data[id][SETTINGS] = LOAD_FROM_DAT
3113#endif
3114 if (p_data[id][SETTINGS] & LOAD_FROM_DAT)
3115 add_to_datafile(p_data[id])
3116#if VIPS_FILE_SYSTEM != OFF
3117 if (p_data[id][SETTINGS] & LOAD_FROM_INI)
3118 add_to_ini(p_data[id])
3119#endif
3120 return VipsDBInsert(p_data[id]);
3121}
3122stock VipsDBInsert(data[vips_database_type]) {
3123
3124 if (data[SETTINGS] & ~(LOAD_MASK|FLAG_K)) {
3125
3126 if(!array_vips_database_nick)
3127 array_vips_database_nick = ArrayCreate(vips_database_type, 10)
3128
3129 data[SETTINGS] |= LOAD_FROM_NAMES
3130 data[INDEX] = ArraySize(array_vips_database_nick)
3131 ArrayPushArray(array_vips_database_nick, data)
3132 VIPINC(NAMES)
3133
3134 return true;
3135 }
3136
3137 data[INDEX] = ArraySize(array_vips_database)
3138 ArrayPushString(array_vips_database, data[AUTH])
3139 TrieSetArray(trie_vips_database, data[AUTH], data, vips_database_type)
3140 VIPINC(MAIN)
3141
3142 return true;
3143}
3144
3145stock VipsDBRemove(const id) {
3146
3147 if (!(1 <= id < 33))
3148 return false;
3149
3150 if (p_data[id][SETTINGS]&LOAD_MASK) {
3151
3152 p_data[id][FLAGS] = 0
3153 p_data[id][TIMESTAMP] = 0
3154 if (p_data[id][SETTINGS]&(LOAD_FROM_MAIN)) {
3155
3156 TrieDeleteKey(trie_vips_database, p_data[id][AUTH])
3157 ArraySetString(array_vips_database, p_data[id][INDEX], "")
3158 VIPDEC(MAIN)
3159
3160 if (p_data[id][SETTINGS]&LOAD_FROM_MAIN)
3161 remove_from_datafile(p_data[id])
3162#if VIPS_FILE_SYSTEM != OFF
3163 if (p_data[id][SETTINGS]&LOAD_FROM_INI)
3164 remove_from_ini(p_data[id])
3165#endif
3166 }
3167 else if (p_data[id][SETTINGS]&LOAD_FROM_NAMES) {
3168
3169 p_data[id][AUTH][0] = EOS
3170 ArraySetArray(array_vips_database_nick, p_data[id][INDEX], p_data[id])
3171 VIPDEC(NAMES)
3172 }
3173#if VIPS_FILE_SYSTEM != FORCED
3174 else if (p_data[id][SETTINGS]&LOAD_FROM_AMX) {
3175
3176 remove_user_flags(id, VIP_SYS_FLAG)
3177 // VIPCNT(AMX) not decremented, because we don't delete from amxmodx dynamic
3178 // admin list. There is no efficient way to do this. Only by flushing all admins
3179 }
3180#endif
3181 new flags = _get_pcvar_flags(cvar_amxmodx_flags)
3182 if (flags > 0)
3183 remove_user_flags(id, flags)
3184
3185 p_data[id][SETTINGS] = 0
3186 return true;
3187 }
3188
3189 return false;
3190}