Skip to content

Commit 9fc8d9b

Browse files
committed
Weapons: Fixes and add Level property for guns
1 parent 1dbe473 commit 9fc8d9b

File tree

3 files changed

+118
-37
lines changed

3 files changed

+118
-37
lines changed

configs/zombie_escape.ini

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,31 @@ FLAME = sprites/flame.spr
9595
SMOKE = sprites/black_smoke1.spr
9696

9797
[Weapons Menu]
98-
# <section> <name> <classname> <ammo> <weapon uid>
99-
100-
"p" "Famas" "weapon_famas" "200"
101-
"p" "Galil" "weapon_galil" "280"
102-
"p" "AK-47 Kalashnikov" "weapon_ak47" "240"
103-
"p" "M4A1 Carbine" "weapon_m4a1" "240"
104-
"p" "SG552 Commando" "weapon_sg552" "240"
105-
"p" "Aug Bullpup" "weapon_aug" "240"
106-
"p" "M3 Shotgun" "weapon_m3" "80"
107-
"p" "XM1014 Auto" "weapon_xm1014" "70"
108-
"p" "Steyr TMP" "weapon_tmp" "300"
109-
"p" "Mac-10" "weapon_mac10" "300"
110-
"p" "MP5 Navy" "weapon_mp5navy" "300"
111-
"p" "FN P-90" "weapon_p90" "500"
112-
"p" "Steyr Scout" "weapon_scout" "100"
113-
"p" "SG-550" "weapon_sg550" "200"
114-
"p" "AWP Magnum Sniper" "weapon_awp" "150"
115-
"p" "M249 Machine Gun" "weapon_m249" "500"
116-
117-
"s" "Glock-18" "weapon_glock18" "200"
118-
"s" "USP" "weapon_usp" "240"
119-
"s" "P-228" "weapon_p228" "260"
120-
"s" "Desert Eagle" "weapon_deagle" "140"
121-
"s" "Five-SeveN" "weapon_fiveseven" "200"
122-
"s" "Dual Elite" "weapon_elite" "600"
98+
# <section> <name> <classname> <ammo> <weapon uid> <required level>
99+
100+
"p" "Famas" "weapon_famas" "200" "0" "0"
101+
"p" "Galil" "weapon_galil" "280" "0" "0"
102+
"p" "AK-47 Kalashnikov" "weapon_ak47" "240" "0" "0"
103+
"p" "M4A1 Carbine" "weapon_m4a1" "240" "0" "0"
104+
"p" "SG552 Commando" "weapon_sg552" "240" "0" "0"
105+
"p" "Aug Bullpup" "weapon_aug" "240" "0" "0"
106+
"p" "M3 Shotgun" "weapon_m3" "80" "0" "0"
107+
"p" "XM1014 Auto" "weapon_xm1014" "70" "0" "0"
108+
"p" "Steyr TMP" "weapon_tmp" "300" "0" "0"
109+
"p" "Mac-10" "weapon_mac10" "300" "0" "0"
110+
"p" "MP5 Navy" "weapon_mp5navy" "300" "0" "0"
111+
"p" "FN P-90" "weapon_p90" "500" "0" "0"
112+
"p" "Steyr Scout" "weapon_scout" "100" "0" "0"
113+
"p" "SG-550" "weapon_sg550" "200" "0" "0"
114+
"p" "AWP Magnum Sniper" "weapon_awp" "150" "0" "0"
115+
"p" "M249 Machine Gun" "weapon_m249" "500" "0" "0"
116+
117+
"s" "Glock-18" "weapon_glock18" "200" "0" "0"
118+
"s" "USP" "weapon_usp" "240" "0" "0"
119+
"s" "P-228" "weapon_p228" "260" "0" "0"
120+
"s" "Desert Eagle" "weapon_deagle" "140" "0" "0"
121+
"s" "Five-SeveN" "weapon_fiveseven" "200" "0" "0"
122+
"s" "Dual Elite" "weapon_elite" "600" "0" "0"
123123

124124
[Knockback]
125125
p228 = 2.40

data/lang/zombie_escape.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@ MSG_ZOMBIE_NAME = "Name: !t%s"
9090
MSG_ZOMBIE_INFO = "HP: !g%.2f!y | Speed: !g%.2f!y | Gravity: !g%.2f!y | Knockback: !g%.2f!y"
9191

9292
STATIC = "Static"
93-
DYNAMIC = "Dynamic"
93+
DYNAMIC = "Dynamic"
94+
95+
MENU_LEVEL = "Level"
96+
MSG_LVL_NOT_ENOUGH = "You don't have enough level!"

scripting/ze_weapons_menu.sma

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <reapi>
44

55
#include <ze_core>
6+
#include <ze_levels>
7+
#define LIBRARY_LEVEL "ze_levels"
68

79
// Defines.
810
#define MN_AUTO_SELECT 7
@@ -18,7 +20,8 @@ enum _:WPN_DATA
1820
WPN_CUSTOM = 0,
1921
WPN_NAME[MAX_NAME_LENGTH],
2022
WPN_CLASS[MAX_NAME_LENGTH],
21-
WPN_AMMO
23+
WPN_AMMO,
24+
WPN_LEVEL
2225
}
2326

2427
// Weapon Section.
@@ -105,6 +108,23 @@ public plugin_natives()
105108
register_native("ze_auto_buy_enabled", "__native_auto_buy_enabled")
106109
register_native("ze_set_auto_buy", "__native_set_auto_buy")
107110
register_native("ze_show_weapons_menu", "__native_show_weapons_menu")
111+
112+
set_module_filter("fw_module_filter")
113+
set_native_filter("fw_native_filter")
114+
}
115+
116+
public fw_module_filter(const module[], LibType:type)
117+
{
118+
if (equal(module, LIBRARY_LEVEL))
119+
return PLUGIN_HANDLED
120+
return PLUGIN_CONTINUE
121+
}
122+
123+
public fw_native_filter(const name[], index, trap)
124+
{
125+
if (!trap)
126+
return PLUGIN_HANDLED
127+
return PLUGIN_CONTINUE
108128
}
109129

110130
public plugin_init()
@@ -289,23 +309,40 @@ public show_Available_Menu(id)
289309

290310
public show_Primary_Weapons(id)
291311
{
292-
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLen
312+
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLevel, iLen
293313

294314
// Menu Title.
295315
iLen = formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%L\d:^n^n", LANG_PLAYER, "MENU_PRIMARY_TITLE")
296316

297317
// Get number of weapons on page.
298318
new iWpn = g_iMenuData[id][MD_PRI_PAGE]
299319
new iMaxLoops = min(iWpn + 7, g_iPrimaryNum)
320+
new fLevels = module_exists(LIBRARY_LEVEL)
321+
322+
if (fLevels)
323+
iLevel = ze_get_user_level(id)
300324

301325
// Add guns name to Menu.
302326
new iNum = 1
303327
for (new i = iWpn; i < iMaxLoops; i++)
304328
{
305329
ArrayGetArray(g_aPrimaryWeapons, i, pArray)
306330

307-
// #. Weapon Name
308-
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
331+
if (fLevels)
332+
{
333+
if (iLevel < pArray[WPN_LEVEL])
334+
{
335+
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \d%s \r[%L\d: \y%i\r]^n", iNum++, pArray[WPN_NAME], LANG_PLAYER, "MENU_LEVEL", pArray[WPN_LEVEL])
336+
}
337+
else
338+
{
339+
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
340+
}
341+
}
342+
else // #. Weapon Name
343+
{
344+
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
345+
}
309346
}
310347

311348
szMenu[iLen++] = '^n'
@@ -382,8 +419,10 @@ public handler_Primary_Weapons(id, iKey)
382419
{
383420
show_Primary_Weapons(id)
384421
}
385-
386-
show_Secondary_Weapons(id)
422+
else
423+
{
424+
show_Secondary_Weapons(id)
425+
}
387426
}
388427
else
389428
{
@@ -397,23 +436,40 @@ public handler_Primary_Weapons(id, iKey)
397436

398437
public show_Secondary_Weapons(id)
399438
{
400-
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLen
439+
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLevel, iLen
401440

402441
// Menu Title.
403442
iLen = formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%L\d:^n^n", LANG_PLAYER, "MENU_SECONDARY_TITLE")
404443

405444
// Get number of weapons on page.
406445
new iWpn = g_iMenuData[id][MD_SEC_PAGE]
407446
new iMaxLoops = min(iWpn + 7, g_iSecondaryNum)
447+
new fLevels = module_exists(LIBRARY_LEVEL)
448+
449+
if (fLevels)
450+
iLevel = ze_get_user_level(id)
408451

409452
// Add guns name to Menu.
410453
new iNum = 1
411454
for (new i = iWpn; i < iMaxLoops; i++)
412455
{
413456
ArrayGetArray(g_aSecondaryWeapons, i, pArray)
414457

415-
// #. Weapon Name
416-
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
458+
if (fLevels)
459+
{
460+
if (iLevel < pArray[WPN_LEVEL])
461+
{
462+
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \d%s \r[%L\d: \y%i\r]^n", iNum++, pArray[WPN_NAME], LANG_PLAYER, "MENU_LEVEL", pArray[WPN_LEVEL])
463+
}
464+
else
465+
{
466+
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
467+
}
468+
}
469+
else // #. Weapon Name
470+
{
471+
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
472+
}
417473
}
418474

419475
szMenu[iLen++] = '^n'
@@ -511,6 +567,15 @@ public choose_Weapon(id, iIndex, iSection)
511567
{
512568
ArrayGetArray(g_aPrimaryWeapons, iIndex, pArray)
513569

570+
if (module_exists(LIBRARY_LEVEL))
571+
{
572+
if (ze_get_user_level(id) < pArray[WPN_LEVEL])
573+
{
574+
ze_colored_print(id, "%L", LANG_PLAYER, "MSG_LVL_NOT_ENOUGH")
575+
return 0
576+
}
577+
}
578+
514579
if (pArray[WPN_CUSTOM])
515580
{
516581
if ((rg_give_custom_item(id, pArray[WPN_CLASS], GT_REPLACE, pArray[WPN_CUSTOM])) == NULLENT)
@@ -539,6 +604,15 @@ public choose_Weapon(id, iIndex, iSection)
539604
new pItem
540605
ArrayGetArray(g_aSecondaryWeapons, iIndex, pArray)
541606

607+
if (module_exists(LIBRARY_LEVEL))
608+
{
609+
if (ze_get_user_level(id) < pArray[WPN_LEVEL])
610+
{
611+
ze_colored_print(id, "%L", LANG_PLAYER, "MSG_LVL_NOT_ENOUGH")
612+
return 0
613+
}
614+
}
615+
542616
if (pArray[WPN_CUSTOM])
543617
{
544618
pItem = rg_give_custom_item(id, pArray[WPN_CLASS], GT_REPLACE, pArray[WPN_CUSTOM])
@@ -634,7 +708,7 @@ read_Weapons(const szFile[])
634708
return 0
635709
}
636710

637-
new pArray[WPN_DATA], szWpnName[64], szWpnClass[64], szWpnCustom[64], szWpnAmmo[32]
711+
new pArray[WPN_DATA], szWpnName[64], szWpnClass[64], szWpnCustom[64], szWpnAmmo[32], szWpnLevel[32]
638712

639713
while (!feof(hFile))
640714
{
@@ -664,9 +738,10 @@ read_Weapons(const szFile[])
664738
szWpnName = NULL_STRING
665739
szWpnClass = NULL_STRING
666740
szWpnAmmo = NULL_STRING
741+
szWpnLevel = NULL_STRING
667742

668743
// Parse the text.
669-
if (parse(szRead, szSection, charsmax(szSection), szWpnName, charsmax(szWpnName), szWpnClass, charsmax(szWpnClass), szWpnAmmo, charsmax(szWpnAmmo), szWpnCustom, charsmax(szWpnCustom)) < 4)
744+
if (parse(szRead, szSection, charsmax(szSection), szWpnName, charsmax(szWpnName), szWpnClass, charsmax(szWpnClass), szWpnAmmo, charsmax(szWpnAmmo), szWpnCustom, charsmax(szWpnCustom), szWpnLevel, charsmax(szWpnLevel)) < 4)
670745
{
671746
server_print("[ZE] Line #%i: Some arguments are not found !", iLine)
672747
continue
@@ -678,6 +753,7 @@ read_Weapons(const szFile[])
678753
remove_quotes(szWpnClass)
679754
remove_quotes(szWpnCustom)
680755
remove_quotes(szWpnAmmo)
756+
remove_quotes(szWpnLevel)
681757

682758
switch (szSection[0])
683759
{
@@ -687,6 +763,7 @@ read_Weapons(const szFile[])
687763
copy(pArray[WPN_NAME], charsmax(pArray) - WPN_NAME, szWpnName)
688764
copy(pArray[WPN_CLASS], charsmax(pArray) - WPN_CLASS, szWpnClass)
689765
pArray[WPN_AMMO] = str_to_num(szWpnAmmo)
766+
pArray[WPN_LEVEL] = str_to_num(szWpnLevel)
690767

691768
ArrayPushArray(g_aPrimaryWeapons, pArray)
692769
g_iPrimaryNum++
@@ -697,6 +774,7 @@ read_Weapons(const szFile[])
697774
copy(pArray[WPN_NAME], charsmax(pArray) - WPN_NAME, szWpnName)
698775
copy(pArray[WPN_CLASS], charsmax(pArray) - WPN_CLASS, szWpnClass)
699776
pArray[WPN_AMMO] = str_to_num(szWpnAmmo)
777+
pArray[WPN_LEVEL] = str_to_num(szWpnLevel)
700778

701779
ArrayPushArray(g_aSecondaryWeapons, pArray)
702780
g_iSecondaryNum++

0 commit comments

Comments
 (0)