Skip to content

Commit

Permalink
Weapons: Fixes and add Level property for guns
Browse files Browse the repository at this point in the history
  • Loading branch information
z0h1r-LK committed Mar 6, 2024
1 parent 1dbe473 commit 9fc8d9b
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 37 deletions.
50 changes: 25 additions & 25 deletions configs/zombie_escape.ini
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,31 @@ FLAME = sprites/flame.spr
SMOKE = sprites/black_smoke1.spr

[Weapons Menu]
# <section> <name> <classname> <ammo> <weapon uid>

"p" "Famas" "weapon_famas" "200"
"p" "Galil" "weapon_galil" "280"
"p" "AK-47 Kalashnikov" "weapon_ak47" "240"
"p" "M4A1 Carbine" "weapon_m4a1" "240"
"p" "SG552 Commando" "weapon_sg552" "240"
"p" "Aug Bullpup" "weapon_aug" "240"
"p" "M3 Shotgun" "weapon_m3" "80"
"p" "XM1014 Auto" "weapon_xm1014" "70"
"p" "Steyr TMP" "weapon_tmp" "300"
"p" "Mac-10" "weapon_mac10" "300"
"p" "MP5 Navy" "weapon_mp5navy" "300"
"p" "FN P-90" "weapon_p90" "500"
"p" "Steyr Scout" "weapon_scout" "100"
"p" "SG-550" "weapon_sg550" "200"
"p" "AWP Magnum Sniper" "weapon_awp" "150"
"p" "M249 Machine Gun" "weapon_m249" "500"

"s" "Glock-18" "weapon_glock18" "200"
"s" "USP" "weapon_usp" "240"
"s" "P-228" "weapon_p228" "260"
"s" "Desert Eagle" "weapon_deagle" "140"
"s" "Five-SeveN" "weapon_fiveseven" "200"
"s" "Dual Elite" "weapon_elite" "600"
# <section> <name> <classname> <ammo> <weapon uid> <required level>

"p" "Famas" "weapon_famas" "200" "0" "0"
"p" "Galil" "weapon_galil" "280" "0" "0"
"p" "AK-47 Kalashnikov" "weapon_ak47" "240" "0" "0"
"p" "M4A1 Carbine" "weapon_m4a1" "240" "0" "0"
"p" "SG552 Commando" "weapon_sg552" "240" "0" "0"
"p" "Aug Bullpup" "weapon_aug" "240" "0" "0"
"p" "M3 Shotgun" "weapon_m3" "80" "0" "0"
"p" "XM1014 Auto" "weapon_xm1014" "70" "0" "0"
"p" "Steyr TMP" "weapon_tmp" "300" "0" "0"
"p" "Mac-10" "weapon_mac10" "300" "0" "0"
"p" "MP5 Navy" "weapon_mp5navy" "300" "0" "0"
"p" "FN P-90" "weapon_p90" "500" "0" "0"
"p" "Steyr Scout" "weapon_scout" "100" "0" "0"
"p" "SG-550" "weapon_sg550" "200" "0" "0"
"p" "AWP Magnum Sniper" "weapon_awp" "150" "0" "0"
"p" "M249 Machine Gun" "weapon_m249" "500" "0" "0"

"s" "Glock-18" "weapon_glock18" "200" "0" "0"
"s" "USP" "weapon_usp" "240" "0" "0"
"s" "P-228" "weapon_p228" "260" "0" "0"
"s" "Desert Eagle" "weapon_deagle" "140" "0" "0"
"s" "Five-SeveN" "weapon_fiveseven" "200" "0" "0"
"s" "Dual Elite" "weapon_elite" "600" "0" "0"

[Knockback]
p228 = 2.40
Expand Down
5 changes: 4 additions & 1 deletion data/lang/zombie_escape.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ MSG_ZOMBIE_NAME = "Name: !t%s"
MSG_ZOMBIE_INFO = "HP: !g%.2f!y | Speed: !g%.2f!y | Gravity: !g%.2f!y | Knockback: !g%.2f!y"

STATIC = "Static"
DYNAMIC = "Dynamic"
DYNAMIC = "Dynamic"

MENU_LEVEL = "Level"
MSG_LVL_NOT_ENOUGH = "You don't have enough level!"
100 changes: 89 additions & 11 deletions scripting/ze_weapons_menu.sma
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <reapi>

#include <ze_core>
#include <ze_levels>
#define LIBRARY_LEVEL "ze_levels"

// Defines.
#define MN_AUTO_SELECT 7
Expand All @@ -18,7 +20,8 @@ enum _:WPN_DATA
WPN_CUSTOM = 0,
WPN_NAME[MAX_NAME_LENGTH],
WPN_CLASS[MAX_NAME_LENGTH],
WPN_AMMO
WPN_AMMO,
WPN_LEVEL
}

// Weapon Section.
Expand Down Expand Up @@ -105,6 +108,23 @@ public plugin_natives()
register_native("ze_auto_buy_enabled", "__native_auto_buy_enabled")
register_native("ze_set_auto_buy", "__native_set_auto_buy")
register_native("ze_show_weapons_menu", "__native_show_weapons_menu")

set_module_filter("fw_module_filter")
set_native_filter("fw_native_filter")
}

public fw_module_filter(const module[], LibType:type)
{
if (equal(module, LIBRARY_LEVEL))
return PLUGIN_HANDLED
return PLUGIN_CONTINUE
}

public fw_native_filter(const name[], index, trap)
{
if (!trap)
return PLUGIN_HANDLED
return PLUGIN_CONTINUE
}

public plugin_init()
Expand Down Expand Up @@ -289,23 +309,40 @@ public show_Available_Menu(id)

public show_Primary_Weapons(id)
{
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLen
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLevel, iLen

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

// Get number of weapons on page.
new iWpn = g_iMenuData[id][MD_PRI_PAGE]
new iMaxLoops = min(iWpn + 7, g_iPrimaryNum)
new fLevels = module_exists(LIBRARY_LEVEL)

if (fLevels)
iLevel = ze_get_user_level(id)

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

// #. Weapon Name
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
if (fLevels)
{
if (iLevel < pArray[WPN_LEVEL])
{
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])
}
else
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
}
}
else // #. Weapon Name
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
}
}

szMenu[iLen++] = '^n'
Expand Down Expand Up @@ -382,8 +419,10 @@ public handler_Primary_Weapons(id, iKey)
{
show_Primary_Weapons(id)
}

show_Secondary_Weapons(id)
else
{
show_Secondary_Weapons(id)
}
}
else
{
Expand All @@ -397,23 +436,40 @@ public handler_Primary_Weapons(id, iKey)

public show_Secondary_Weapons(id)
{
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLen
new szMenu[MAX_MENU_LENGTH], pArray[WPN_DATA], iLevel, iLen

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

// Get number of weapons on page.
new iWpn = g_iMenuData[id][MD_SEC_PAGE]
new iMaxLoops = min(iWpn + 7, g_iSecondaryNum)
new fLevels = module_exists(LIBRARY_LEVEL)

if (fLevels)
iLevel = ze_get_user_level(id)

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

// #. Weapon Name
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
if (fLevels)
{
if (iLevel < pArray[WPN_LEVEL])
{
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])
}
else
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
}
}
else // #. Weapon Name
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\r%d. \w%s^n", iNum++, pArray[WPN_NAME])
}
}

szMenu[iLen++] = '^n'
Expand Down Expand Up @@ -511,6 +567,15 @@ public choose_Weapon(id, iIndex, iSection)
{
ArrayGetArray(g_aPrimaryWeapons, iIndex, pArray)

if (module_exists(LIBRARY_LEVEL))
{
if (ze_get_user_level(id) < pArray[WPN_LEVEL])
{
ze_colored_print(id, "%L", LANG_PLAYER, "MSG_LVL_NOT_ENOUGH")
return 0
}
}

if (pArray[WPN_CUSTOM])
{
if ((rg_give_custom_item(id, pArray[WPN_CLASS], GT_REPLACE, pArray[WPN_CUSTOM])) == NULLENT)
Expand Down Expand Up @@ -539,6 +604,15 @@ public choose_Weapon(id, iIndex, iSection)
new pItem
ArrayGetArray(g_aSecondaryWeapons, iIndex, pArray)

if (module_exists(LIBRARY_LEVEL))
{
if (ze_get_user_level(id) < pArray[WPN_LEVEL])
{
ze_colored_print(id, "%L", LANG_PLAYER, "MSG_LVL_NOT_ENOUGH")
return 0
}
}

if (pArray[WPN_CUSTOM])
{
pItem = rg_give_custom_item(id, pArray[WPN_CLASS], GT_REPLACE, pArray[WPN_CUSTOM])
Expand Down Expand Up @@ -634,7 +708,7 @@ read_Weapons(const szFile[])
return 0
}

new pArray[WPN_DATA], szWpnName[64], szWpnClass[64], szWpnCustom[64], szWpnAmmo[32]
new pArray[WPN_DATA], szWpnName[64], szWpnClass[64], szWpnCustom[64], szWpnAmmo[32], szWpnLevel[32]

while (!feof(hFile))
{
Expand Down Expand Up @@ -664,9 +738,10 @@ read_Weapons(const szFile[])
szWpnName = NULL_STRING
szWpnClass = NULL_STRING
szWpnAmmo = NULL_STRING
szWpnLevel = NULL_STRING

// Parse the text.
if (parse(szRead, szSection, charsmax(szSection), szWpnName, charsmax(szWpnName), szWpnClass, charsmax(szWpnClass), szWpnAmmo, charsmax(szWpnAmmo), szWpnCustom, charsmax(szWpnCustom)) < 4)
if (parse(szRead, szSection, charsmax(szSection), szWpnName, charsmax(szWpnName), szWpnClass, charsmax(szWpnClass), szWpnAmmo, charsmax(szWpnAmmo), szWpnCustom, charsmax(szWpnCustom), szWpnLevel, charsmax(szWpnLevel)) < 4)
{
server_print("[ZE] Line #%i: Some arguments are not found !", iLine)
continue
Expand All @@ -678,6 +753,7 @@ read_Weapons(const szFile[])
remove_quotes(szWpnClass)
remove_quotes(szWpnCustom)
remove_quotes(szWpnAmmo)
remove_quotes(szWpnLevel)

switch (szSection[0])
{
Expand All @@ -687,6 +763,7 @@ read_Weapons(const szFile[])
copy(pArray[WPN_NAME], charsmax(pArray) - WPN_NAME, szWpnName)
copy(pArray[WPN_CLASS], charsmax(pArray) - WPN_CLASS, szWpnClass)
pArray[WPN_AMMO] = str_to_num(szWpnAmmo)
pArray[WPN_LEVEL] = str_to_num(szWpnLevel)

ArrayPushArray(g_aPrimaryWeapons, pArray)
g_iPrimaryNum++
Expand All @@ -697,6 +774,7 @@ read_Weapons(const szFile[])
copy(pArray[WPN_NAME], charsmax(pArray) - WPN_NAME, szWpnName)
copy(pArray[WPN_CLASS], charsmax(pArray) - WPN_CLASS, szWpnClass)
pArray[WPN_AMMO] = str_to_num(szWpnAmmo)
pArray[WPN_LEVEL] = str_to_num(szWpnLevel)

ArrayPushArray(g_aSecondaryWeapons, pArray)
g_iSecondaryNum++
Expand Down

0 comments on commit 9fc8d9b

Please sign in to comment.