From d220eeee776d376230026e58e35d6bb759a5bc20 Mon Sep 17 00:00:00 2001 From: Greyscale Date: Fri, 10 Apr 2009 01:08:51 +0200 Subject: [PATCH] Added periods after function comments, moved market handler code to markethandler.inc, made restrictions announced to the server --- .../translations/zombiereloaded.phrases.txt | 48 ++-- src/zombiereloaded.sp | 4 + src/zr/commands.inc | 8 +- src/zr/sayhooks.inc | 68 ----- src/zr/weaponrestrict.inc | 261 ------------------ src/zr/weapons/markethandler.inc | 87 ++++++ src/zr/weapons/restrict.inc | 34 +-- 7 files changed, 132 insertions(+), 378 deletions(-) delete mode 100644 src/zr/weaponrestrict.inc create mode 100644 src/zr/weapons/markethandler.inc diff --git a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt index 4674b0a..c7cf987 100644 --- a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt +++ b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt @@ -170,32 +170,36 @@ "ru" "Отображение здоровья включено." } - "Weapon has been restricted" + // =========================== + // Weapon Restrict + // =========================== + + "Restrict weapon" { "#format" "{1:s}" "en" "Weapon @green\"{1}\" @defaulthas been restricted." "ru" "Оружие @green\"{1}\" было запрещено." } - "Weapon group has been restricted" - { - "#format" "{1:s}" - "en" "Weapon group @green\"{1}\" @defaulthas been restricted." - "ru" "Группа оружия @green\"{1}\" была запрещена." - } - - "Weapon has been unrestricted" + "Unrestrict weapon" { "#format" "{1:s}" "en" "Weapon @green\"{1}\" @defaulthas been unrestricted." "ru" "Оружие @green\"{1}\" было разрешено." } - "Weapon group has been unrestricted" + "Restrict custom weapon group" { - "#format" "{1:s}" - "en" "Weapon group @green\"{1}\" @defaulthas been restricted." - "ru" "Группа оружия @green\"{1}\" была разрешена." + "#format" "{1:s},{2:s}" + "en" "Weapon group @green\"{1}\" ({2}) @defaulthas been restricted." + "ru" "Группа оружия @green\"{1}\" ({2}) была запрещена." + } + + "Unrestrict custom weapon group" + { + "#format" "{1:s},{2:s}" + "en" "Weapon group @green\"{1}\" ({2}) @defaulthas been unrestricted." + "ru" "Группа оружия @green\"{1}\" ({2}) была разрешена." } "Weapon is restricted" @@ -205,18 +209,10 @@ "ru" "Оружие @green{1} @default запрещено." } - "Weapon already restricted" - { - "#format" "{1:s}" - "en" "Weapon @green\"{1}\" @defaultis already restricted." - "ru" "Оружие @green\"{1}\" @default уже запрещено. " - } - "Weapon invalid" { "#format" "{1:s}" - "en" "Weapon @green\"{1}\" @defaultis invalid or not currently restricted." - "ru" "Оружие @green\"{1}\" @default указано неверно или в данный момент не запрещено." + "en" "Weapon @green\"{1}\" @defaultis not currently restricted." } "Zombie cant use weapon" @@ -225,6 +221,8 @@ "ru" "Зомби не могут использовать оружие!" } + + "Suicide text" { "en" "Nice try n00b!" @@ -294,12 +292,6 @@ "ru" "ZTele (!ztele) - Телепорт на место появления" } - "!zmenu stuck" - { - "en" "ZStuck (!zstuck) - Unsticks you from another player" - "ru" "ZStuck (!zstuck) - Разлепляет вас с другим игроком" - } - "!zmenu hp" { "en" "ZHP (!zhp) - Toggle persistent display of HP as zombie" diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 1009db5..7051fe3 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -34,7 +34,11 @@ #include "zr/menu" #include "zr/sayhooks" #include "zr/zadmin" + +// Weapons #include "zr/weapons/restrict" +#include "zr/weapons/markethandler" + #include "zr/damagecontrol" #include "zr/commands" #include "zr/event" diff --git a/src/zr/commands.inc b/src/zr/commands.inc index 8feec2e..8380f34 100644 --- a/src/zr/commands.inc +++ b/src/zr/commands.inc @@ -160,14 +160,14 @@ public Action:Command_Restrict(client, argc) { case Successful_Weapon: { - ZR_ReplyToCommand(client, "Restrict weapon", arg1); + ZR_PrintToChat(0, "Restrict weapon", arg1); } case Successful_Group: { decl String:weaponlist[128]; WeaponRestrictGetWeaponList(arg1, weaponlist, sizeof(weaponlist), ", "); - ZR_ReplyToCommand(client, "Restrict custom weapon group", arg1, weaponlist); + ZR_PrintToChat(0, "Restrict custom weapon group", arg1, weaponlist); } case Invalid: { @@ -217,14 +217,14 @@ public Action:Command_Unrestrict(client, argc) { case Successful_Weapon: { - ZR_ReplyToCommand(client, "Unrestrict weapon", arg1); + ZR_PrintToChat(0, "Unrestrict weapon", arg1); } case Successful_Group: { decl String:weaponlist[128]; WeaponRestrictGetWeaponList(arg1, weaponlist, sizeof(weaponlist), ", "); - ZR_ReplyToCommand(client, "Unrestrict custom weapon group", arg1, weaponlist); + ZR_PrintToChat(0, "Unrestrict custom weapon group", arg1, weaponlist); } case Invalid: { diff --git a/src/zr/sayhooks.inc b/src/zr/sayhooks.inc index c83e620..feb3801 100644 --- a/src/zr/sayhooks.inc +++ b/src/zr/sayhooks.inc @@ -137,64 +137,6 @@ bool:ZMarket(client) return true; } -public bool:Market_OnWeaponSelected(client, String:weaponid[]) -{ - if (!weaponid[0] || !IsPlayerAlive(client)) - { - return false; - } - - if (IsPlayerZombie(client)) - { - ZR_PrintToChat(client, "Zombie cant use weapon"); - - return false; - } - - if (StrEqual(weaponid, "rebuy")) - { - return true; - } - - decl String:display[64]; - decl String:weapon[32]; - new price; - - if (!Market_GetWeaponIDInfo(weaponid, display, weapon, price)) - { - return false; - } - - ReplaceString(weapon, sizeof(weapon), "weapon_", ""); - - if (WeaponRestrictIsRestricted(weapon)) - { - ZR_PrintToChat(client, "Weapon is restricted", weapon); - - return false; - } - - new bool:buyzone = GetConVarBool(gCvars[CVAR_ZMARKET_BUYZONE]); - if (!IsClientInBuyZone(client) && buyzone) - { - ZR_PrintCenterText(client, "Market out of buyzone"); - - return false; - } - - return true; -} - -public Market_PostOnWeaponSelected(client, &bool:allowed) -{ - if (!allowed) - { - return; - } - - ZMarket(client); -} - ZSpawn(client) { new bool:spawn = GetConVarBool(gCvars[CVAR_ZSPAWN]); @@ -225,16 +167,6 @@ ZSpawn(client) AddPlayerToList(client); } -public Action:CollisionOn(Handle:timer, any:index) -{ - if (!IsClientInGame(index)) - { - return; - } - - NoCollide(index, false); -} - ZHP(client) { new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); diff --git a/src/zr/weaponrestrict.inc b/src/zr/weaponrestrict.inc deleted file mode 100644 index f406464..0000000 --- a/src/zr/weaponrestrict.inc +++ /dev/null @@ -1,261 +0,0 @@ -/** - * ==================== - * Zombie:Reloaded - * File: weaponrestrict.inc - * Author: Greyscale - * ==================== - */ - -new Handle:restrictedWeapons = INVALID_HANDLE; - -new gRestrict[MAXPLAYERS+1]; - -enum WepRestrictQuery -{ - Successful, /** Weapon (un)restrict query was successful */ - Invalid, /** Weapon invalid */ - Existing, /** Already restricted */ -} - -InitWeaponRestrict() -{ - RegConsoleCmd("buy", BuyHook); - - restrictedWeapons = CreateArray(32, 0); -} - -ClientHookUse(client) -{ - gRestrict[client] = Hacks_Hook(client, HACKS_HTYPE_WEAPON_CANUSE, Weapon_CanUse, false); -} - -ClientUnHookUse(client) -{ - Hacks_Unhook(gRestrict[client]); -} - -public Action:BuyHook(client, argc) -{ - new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); - if (!enabled) - { - return Plugin_Continue; - } - - if (IsPlayerHuman(client)) - { - decl String:weapon[64]; - GetCmdArg(1, weapon, sizeof(weapon)); - - ReplaceString(weapon, sizeof(weapon), "weapon_", ""); - - if (IsWeaponRestricted(weapon)) - { - ZR_PrintToChat(client, "Weapon is restricted", weapon); - return Plugin_Handled; - } - } - else - { - ZR_PrintToChat(client, "Zombie cant use weapon"); - return Plugin_Handled; - } - - return Plugin_Continue; -} - -WepRestrictQuery:RestrictWeapon(const String:weapon[]) -{ - if (IsWeaponGroup(weapon)) - { - RestrictWeaponGroup(weapon); - - ZR_PrintToChat(0, "Weapon group has been restricted", weapon); - - return Successful; - } - - if (!IsWeaponRestricted(weapon)) - { - PushArrayString(restrictedWeapons, weapon); - - ZR_PrintToChat(0, "Weapon has been restricted", weapon); - - return Successful; - } - - return Existing; -} - -RestrictWeaponGroup(const String:group[]) -{ - if (StrEqual(group, "pistols", false)) - { - PushArrayString(restrictedWeapons, "glock"); - PushArrayString(restrictedWeapons, "usp"); - PushArrayString(restrictedWeapons, "p228"); - PushArrayString(restrictedWeapons, "deagle"); - PushArrayString(restrictedWeapons, "elite"); - PushArrayString(restrictedWeapons, "fiveseven"); - } - else if (StrEqual(group, "shotguns", false)) - { - PushArrayString(restrictedWeapons, "m3"); - PushArrayString(restrictedWeapons, "xm1014"); - } - else if (StrEqual(group, "smgs", false)) - { - PushArrayString(restrictedWeapons, "tmp"); - PushArrayString(restrictedWeapons, "mac10"); - PushArrayString(restrictedWeapons, "mp5navy"); - PushArrayString(restrictedWeapons, "ump45"); - PushArrayString(restrictedWeapons, "p90"); - } - else if (StrEqual(group, "rifles", false)) - { - PushArrayString(restrictedWeapons, "galil"); - PushArrayString(restrictedWeapons, "famas"); - PushArrayString(restrictedWeapons, "ak47"); - PushArrayString(restrictedWeapons, "m4a1"); - PushArrayString(restrictedWeapons, "sg552"); - PushArrayString(restrictedWeapons, "aug"); - } - else if (StrEqual(group, "snipers", false)) - { - PushArrayString(restrictedWeapons, "scout"); - PushArrayString(restrictedWeapons, "sg550"); - PushArrayString(restrictedWeapons, "g3sg1"); - PushArrayString(restrictedWeapons, "awp"); - } -} - -WepRestrictQuery:UnRestrictWeapon(const String:weapon[]) -{ - if (IsWeaponGroup(weapon)) - { - UnRestrictWeaponGroup(weapon); - - ZR_PrintToChat(0, "Weapon group has been unrestricted", weapon); - - return Successful; - } - - new index = GetRestrictedWeaponIndex(weapon); - - if (index > -1) - { - RemoveFromArray(restrictedWeapons, index); - - ZR_PrintToChat(0, "Weapon has been unrestricted", weapon); - - return Successful; - } - - return Invalid; -} - -UnRestrictWeaponGroup(const String:group[]) -{ - if (StrEqual(group, "pistols", false)) - { - UnRestrictWeapon("glock"); - UnRestrictWeapon("usp"); - UnRestrictWeapon("p228"); - UnRestrictWeapon("deagle"); - UnRestrictWeapon("elite"); - UnRestrictWeapon("fiveseven"); - } - else if (StrEqual(group, "shotguns", false)) - { - UnRestrictWeapon("m3"); - UnRestrictWeapon("xm1014"); - } - else if (StrEqual(group, "smgs", false)) - { - UnRestrictWeapon("tmp"); - UnRestrictWeapon("mac10"); - UnRestrictWeapon("mp5navy"); - UnRestrictWeapon("ump45"); - UnRestrictWeapon("p90"); - } - else if (StrEqual(group, "rifles", false)) - { - UnRestrictWeapon("galil"); - UnRestrictWeapon("famas"); - UnRestrictWeapon("ak47"); - UnRestrictWeapon("m4a1"); - UnRestrictWeapon("sg552"); - UnRestrictWeapon("aug"); - } - else if (StrEqual(group, "snipers", false)) - { - UnRestrictWeapon("scout"); - UnRestrictWeapon("sg550"); - UnRestrictWeapon("g3sg1"); - UnRestrictWeapon("awp"); - } -} - -bool:IsWeaponRestricted(const String:weapon[]) -{ - for (new x = 0; x < GetArraySize(restrictedWeapons); x++) - { - decl String:restrictedweapon[32]; - GetArrayString(restrictedWeapons, x, restrictedweapon, sizeof(restrictedweapon)); - - if (StrEqual(weapon, restrictedweapon, false)) - { - return true; - } - } - - return false; -} - -GetRestrictedWeaponIndex(const String:weapon[]) -{ - for (new x = 0; x < GetArraySize(restrictedWeapons); x++) - { - decl String:restrictedweapon[32]; - GetArrayString(restrictedWeapons, x, restrictedweapon, sizeof(restrictedweapon)); - ReplaceString(restrictedweapon, sizeof(restrictedweapon), "weapon_", ""); - - if (StrEqual(weapon, restrictedweapon, false)) - { - return x; - } - } - - return -1; -} - -bool:IsWeaponGroup(const String:weapon[]) -{ - return (StrEqual(weapon, "pistols", false) || StrEqual(weapon, "shotguns", false) || StrEqual(weapon, "smgs", false) || StrEqual(weapon, "rifles", false) || StrEqual(weapon, "snipers", false)); -} - -public Weapon_CanUse(client, weapon, dummy1, dummy2, dummy3, dummy4) -{ - new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); - if (!enabled) - { - return Hacks_Continue; - } - - new String:weaponname[32]; - GetEdictClassname(weapon, weaponname, sizeof(weaponname)); - - ReplaceString(weaponname, sizeof(weaponname), "weapon_", ""); - - if (IsWeaponRestricted(weaponname)) - { - return 0; - } - - if (IsPlayerZombie(client) && !StrEqual(weaponname, "knife")) - { - return 0; - } - - return Hacks_Continue; -} \ No newline at end of file diff --git a/src/zr/weapons/markethandler.inc b/src/zr/weapons/markethandler.inc new file mode 100644 index 0000000..544883c --- /dev/null +++ b/src/zr/weapons/markethandler.inc @@ -0,0 +1,87 @@ +/** + * ==================== + * Zombie:Reloaded + * File: markethandler.inc + * Author: Greyscale + * ==================== + */ + +/** + * (Market) Forward called when a client selects a weapon from the market. + * + * @param client The client index. + * @param weaponid The unique weapon ID used for market natives. + * @return True to allow market to take over, false to block purchase. +*/ +public bool:Market_OnWeaponSelected(client, String:weaponid[]) +{ + // If player is dead or weaponid is invalid, then stop + if (!weaponid[0] || !IsPlayerAlive(client)) + { + return false; + } + + // If player is a zombie, then stop + if (IsPlayerZombie(client)) + { + ZR_PrintToChat(client, "Zombie cant use weapon"); + + return false; + } + + // If player is using the rebuy option then allow + if (StrEqual(weaponid, "rebuy")) + { + return true; + } + + decl String:display[64]; + decl String:weapon[32]; + new price; + + // If the market plugin can't find info about the weapon, then stop + if (!Market_GetWeaponIDInfo(weaponid, display, weapon, price)) + { + return false; + } + + // Strip "weapon_" from entity name + ReplaceString(weapon, sizeof(weapon), "weapon_", ""); + + // If the weapon is restricted, then stop + if (WeaponRestrictIsRestricted(weapon)) + { + ZR_PrintToChat(client, "Weapon is restricted", weapon); + + return false; + } + + // Check if buyzone cvar is enabled, and if the client is in a buyzone + new bool:buyzone = GetConVarBool(gCvars[CVAR_ZMARKET_BUYZONE]); + if (!IsClientInBuyZone(client) && buyzone) + { + ZR_PrintCenterText(client, "Market out of buyzone"); + + return false; + } + + return true; +} + +/** + * (Market) Forward called one frame after a client selects a weapon from the market. + * + * @param client The client index. + * @param allowed True when the weapon was purchased successfully, false otherwise. +*/ +public Market_PostOnWeaponSelected(client, &bool:allowed) +{ + // If the purchase wasn't allowed, then stop + if (!allowed) + { + return; + } + + // Resend market menu + ZMarket(client); +} \ No newline at end of file diff --git a/src/zr/weapons/restrict.inc b/src/zr/weapons/restrict.inc index befb233..c8e53b9 100644 --- a/src/zr/weapons/restrict.inc +++ b/src/zr/weapons/restrict.inc @@ -7,12 +7,12 @@ */ /** - * Array to store restricted weapon names + * Array to store restricted weapon names. */ new Handle:gRestrictedWeapons = INVALID_HANDLE; /** - * Array to store keyvalue data + * Array to store keyvalue data. */ new Handle:kvWeaponGroups = INVALID_HANDLE; @@ -22,17 +22,17 @@ new Handle:kvWeaponGroups = INVALID_HANDLE; new gCanUseHookID[MAXPLAYERS+1]; /** - * Query results returned when (un)restricting a weapon + * Query results returned when (un)restricting a weapon. */ enum WpnRestrictQuery { - Successful_Weapon, /** Weapon (un)restrict query was successful */ - Successful_Group, /** Group (un)restrict query was successful */ + Successful_Weapon, /** Weapon (un)restrict query was successful. */ + Successful_Group, /** Group (un)restrict query was successful. */ Invalid, /** Weapon/Group invalid */ } /** - * Initialize data and hook commands + * Initialize data and hook commands. */ WeaponRestrictInit() { @@ -44,7 +44,7 @@ WeaponRestrictInit() } /** - * Loads weapon data from file + * Loads weapon data from file. */ WeaponRestrictMapStart() { @@ -69,7 +69,7 @@ WeaponRestrictMapStart() } /** - * Clears restricted weapon array + * Clears restricted weapon array. */ RestrictWeaponUnrestrictAll() { @@ -77,9 +77,9 @@ RestrictWeaponUnrestrictAll() } /** - * Hook Weapon_CanUse function on a client + * Hook Weapon_CanUse function on a client. * - * @param client The client index + * @param client The client index. */ WeaponRestrictClientInit(client) { @@ -87,9 +87,9 @@ WeaponRestrictClientInit(client) } /** - * Unhook Weapon_CanUse function on a client + * Unhook Weapon_CanUse function on a client. * - * @param client The client index + * @param client The client index. */ WeaponRestrictClientDisconnect(client) { @@ -98,10 +98,10 @@ WeaponRestrictClientDisconnect(client) /** * Command callback function for the "buy" command - * Used to block use of this command under certain conditions + * Used to block use of this command under certain conditions. * * @param client The client index. - * @param argc Argument count + * @param argc Argument count. */ public Action:WeaponRestrictBuyHook(client, argc) { @@ -141,12 +141,12 @@ public Action:WeaponRestrictBuyHook(client, argc) } /** - * Restricts a weapon + * Restricts a weapon. * * @param weapon The weapon/group name. * @return Successful_Weapon: The call successfully restricted a weapon. * Successful_Group: The call successfully restricted a weapon group. - * Invalid: The call was unsuccessful due to invalid weapon. + * Invalid: The call was unsuccessful due to invalid weapon. */ WpnRestrictQuery:WeaponRestrictRestrict(const String:weapon[]) { @@ -183,7 +183,7 @@ WpnRestrictQuery:WeaponRestrictRestrict(const String:weapon[]) } /** - * Unrestricts a weapon + * Unrestricts a weapon. * * @param weapon The weapon/group name. * @return Successful_Weapon: The call successfully restricted a weapon.