diff --git a/cstrike/addons/sourcemod/configs/zr/weapons/weapongroups.txt b/cstrike/addons/sourcemod/configs/zr/weapons/weapongroups.txt index 9b41133..12c2ddb 100644 --- a/cstrike/addons/sourcemod/configs/zr/weapons/weapongroups.txt +++ b/cstrike/addons/sourcemod/configs/zr/weapons/weapongroups.txt @@ -55,4 +55,11 @@ "G2SG1" {} "AWP" {} } + + "Grenades" + { + "hegrenade" {} + "flashbang" {} + "smokegrenade" {} + } } \ No newline at end of file diff --git a/cstrike/addons/sourcemod/configs/zr/weapons/weapons.txt b/cstrike/addons/sourcemod/configs/zr/weapons/weapons.txt index 4bc8718..e190957 100644 --- a/cstrike/addons/sourcemod/configs/zr/weapons/weapons.txt +++ b/cstrike/addons/sourcemod/configs/zr/weapons/weapons.txt @@ -106,7 +106,7 @@ "AK47" { "restrict" "no" - "menu" "no" + "menu" "yes" } "M4A1" @@ -151,4 +151,33 @@ "menu" "yes" } + "M249" + { + "restrict" "yes" + "menu" "yes" + } + + "hegrenade" + { + "restrict" "no" + "menu" "yes" + } + + "flashbang" + { + "restrict" "no" + "menu" "yes" + } + + "smokegrenade" + { + "restrict" "no" + "menu" "yes" + } + + "NVGs" + { + "restrict" "yes" + "menu" "no" + } } \ No newline at end of file diff --git a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt index dcca35d..02bf4b6 100644 --- a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt +++ b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt @@ -222,6 +222,12 @@ "en" "Weapon group @green\"{1}\" ({2}) @defaulthas been unrestricted." } + "Restrict custom weapon group failed" + { + "#format" "{1:s},{2:s}" + "en" "Weapon group @green\"{1}\" ({2}) @defaultis already restricted." + } + "Weapon invalid" { "#format" "{1:s}" @@ -242,24 +248,14 @@ "en" "Weapons Management" } - "Weapons menu main restrict weapon" + "Weapons menu main toggle weapon restrict" { - "en" "Restrict a Weapon" + "en" "Toggle Weapon Restriction" } - "Weapons menu main unrestrict weapon" + "Weapons menu main toggle weapon group restrict" { - "en" "Unrestrict a Weapon" - } - - "Weapons menu main restrict weapon group" - { - "en" "Restrict a Weapon Group" - } - - "Weapons menu main unrestrict weapon group" - { - "en" "Unrestrict a Weapon Group" + "en" "Toggle Weapon Group Restriction" } "Weapons menu main market" // Option disabled if ZMarket isn't installed @@ -269,7 +265,7 @@ "Weapons menu weapons title" { - "en" "Toggle Restrictions:" + "en" "Toggle Restrictions:\n * = restricted" } "Suicide text" diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index b830d06..da1cbf7 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -77,7 +77,10 @@ public OnPluginStart() HookCommands(); FindOffsets(); SetupGameData(); - WeaponRestrictInit(); + + // Weapons + WeaponsInit(); + InitDmgControl(); // ====================================================================== @@ -139,8 +142,6 @@ public OnMapEnd() public OnConfigsExecuted() { - - decl String:mapconfig[PLATFORM_MAX_PATH]; GetCurrentMap(mapconfig, sizeof(mapconfig)); @@ -177,7 +178,7 @@ public OnClientPutInServer(client) dispHP[client] = zhp; // Forward event to modules. - WeaponRestrictClientInit(client); + WeaponsClientInit(client); ClassClientInit(client); if (!IsFakeClient(client)) AmbienceStart(client); @@ -199,7 +200,7 @@ public OnClientDisconnect(client) PlayerLeft(client); // Forward event to modules. - WeaponRestrictClientDisconnect(client); + WeaponsOnClientDisconnect(client); ClassOnClientDisconnect(client); ZTeleResetClient(client); AmbienceStop(client); diff --git a/src/zr/commands.inc b/src/zr/commands.inc index b2b5f5c..502243b 100644 --- a/src/zr/commands.inc +++ b/src/zr/commands.inc @@ -154,30 +154,41 @@ public Action:Command_Restrict(client, argc) // Strip "weapon_" from entity name ReplaceString(arg1, sizeof(arg1), "weapon_", ""); - new WpnRestrictQuery:output = WeaponRestrictRestrict(arg1); + decl String:display[WEAPONS_MAX_LENGTH]; + + new WpnRestrictQuery:output = RestrictRestrict(arg1, display); switch(output) { case Successful_Weapon: { - ZR_PrintToChat(0, "Restrict weapon", arg1); + ZR_PrintToChat(0, "Restrict weapon", display); } case Successful_Group: { decl String:weaponlist[128]; - WeaponRestrictGetWeaponList(arg1, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(0, "Restrict custom weapon group", arg1, weaponlist); + ZR_PrintToChat(0, "Restrict custom weapon group", display, weaponlist); } case Failed_Weapon: { - ZR_ReplyToCommand(client, "Restrict weapon failed", arg1); + ZR_ReplyToCommand(client, "Restrict weapon failed", display); + + return Plugin_Handled; + } + case Failed_Group: + { + decl String:weaponlist[128]; + RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); + + ZR_ReplyToCommand(client, "Restrict custom weapon group failed", display, weaponlist); return Plugin_Handled; } case Invalid: { - ZR_ReplyToCommand(client, "Weapon invalid", arg1); + ZR_ReplyToCommand(client, "Weapon invalid", display); return Plugin_Handled; } @@ -217,30 +228,32 @@ public Action:Command_Unrestrict(client, argc) // Strip "weapon_" from entity name ReplaceString(arg1, sizeof(arg1), "weapon_", ""); - new WpnRestrictQuery:output = WeaponRestrictUnrestrict(arg1); + decl String:display[WEAPONS_MAX_LENGTH]; + + new WpnRestrictQuery:output = RestrictUnrestrict(arg1, display); switch(output) { case Successful_Weapon: { - ZR_PrintToChat(0, "Unrestrict weapon", arg1); + ZR_PrintToChat(0, "Unrestrict weapon", display); } case Successful_Group: { decl String:weaponlist[128]; - WeaponRestrictGetWeaponList(arg1, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(0, "Unrestrict custom weapon group", arg1, weaponlist); + ZR_PrintToChat(0, "Unrestrict custom weapon group", display, weaponlist); } case Failed_Weapon: { - ZR_ReplyToCommand(client, "Unrestrict weapon failed", arg1); + ZR_ReplyToCommand(client, "Unrestrict weapon failed", display); return Plugin_Handled; } case Invalid: { - ZR_ReplyToCommand(client, "Weapon invalid", arg1); + ZR_ReplyToCommand(client, "Weapon invalid", display); return Plugin_Handled; } diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 3dfbeea..f8160b0 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -250,13 +250,20 @@ LogHasFlag(flag) } } -// Check if a log message should be written depending on log flags. Also -// takes care of module log overrides. -LogFlagCheck(flag, module = 0) +/** + * Check if a log message should be written depending on log flags. If module + * overrides are enalbed only logs with it's module flag set will be logged. + * + * @param logtype Log type flag. + * @param module Specifies what module the log event belongs to. + * + * @return True if the event should be logged, false otherwise. + */ +LogFlagCheck(logtype, modulefilter = 0) { - if (module && (flag & LOG_MODULES_ENABLED)) + if (modulefilter && (logtype & LOG_MODULES_ENABLED)) { - if (flag & module) + if (type & modulefilter) { return 1; } @@ -267,6 +274,6 @@ LogFlagCheck(flag, module = 0) } else { - return LogHasFlag(flag); + return LogHasFlag(logtype); } } \ No newline at end of file diff --git a/src/zr/weapons/markethandler.inc b/src/zr/weapons/markethandler.inc index 712f57c..5245783 100644 --- a/src/zr/weapons/markethandler.inc +++ b/src/zr/weapons/markethandler.inc @@ -49,7 +49,7 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[]) ReplaceString(weapon, sizeof(weapon), "weapon_", ""); // If the weapon is restricted, then stop - if (WeaponRestrictIsRestricted(weapon)) + if (RestrictIsWeaponRestricted(weapon)) { ZR_PrintToChat(client, "Weapon is restricted", weapon); diff --git a/src/zr/weapons/menu_weapons.inc b/src/zr/weapons/menu_weapons.inc index 6891acc..0465645 100644 --- a/src/zr/weapons/menu_weapons.inc +++ b/src/zr/weapons/menu_weapons.inc @@ -11,10 +11,8 @@ */ enum WeaponsMenu { - Restrict_Weapon, - Unrestrict_Weapon, - Restrict_Group, - Unrestrict_Group, + Weapon, + WeaponGroup, } /** @@ -35,22 +33,17 @@ WeaponsMenuMain(client) SetMenuTitle(menu_weapons_main, "%t\n ", "Weapons menu main title"); - decl String:restrictweapon[64]; - decl String:unrestrictweapon[64]; - decl String:restrictwgroup[64]; - decl String:unrestrictwgroup[64]; + decl String:toggleweaponrestriction[64]; + decl String:togglewgrouprestriction[64]; + decl String:zmarket[64]; - Format(restrictweapon, sizeof(restrictweapon), "%t", "Weapons menu main restrict weapon"); - Format(unrestrictweapon, sizeof(unrestrictweapon), "%t", "Weapons menu main unrestrict weapon"); - Format(restrictwgroup, sizeof(restrictwgroup), "%t", "Weapons menu main restrict weapon group"); - Format(unrestrictwgroup, sizeof(unrestrictwgroup), "%t", "Weapons menu main unrestrict weapon group"); + Format(toggleweaponrestriction, sizeof(toggleweaponrestriction), "%t", "Weapons menu main toggle weapon restrict"); + Format(togglewgrouprestriction, sizeof(togglewgrouprestriction), "%t", "Weapons menu main toggle weapon group restrict"); Format(zmarket, sizeof(zmarket), "%t", "Weapons menu main market"); - AddMenuItem(menu_weapons_main, "restrictweapon", restrictweapon); - AddMenuItem(menu_weapons_main, "unrestrictweapon", unrestrictweapon); - AddMenuItem(menu_weapons_main, "restrictwgroup", restrictwgroup); - AddMenuItem(menu_weapons_main, "unrestrictwgroup", unrestrictwgroup); + AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction); + AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction); // Disable market option if market isn't installed if (market) @@ -85,21 +78,13 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client { case 0: { - WeaponsMenuWeapons(client, Restrict_Weapon); + WeaponsMenuWeapons(client, Weapon); } case 1: { - WeaponsMenuWeapons(client, Unrestrict_Weapon); + WeaponsMenuWeapons(client, WeaponGroup); } case 2: - { - WeaponsMenuWeapons(client, Restrict_Group); - } - case 3: - { - WeaponsMenuWeapons(client, Unrestrict_Group); - } - case 4: { // WeaponsMenuMarket(client); } @@ -138,7 +123,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type) SetMenuTitle(menu_weapons_weapons, "%t\n ", "Weapons menu weapons title"); // If client wants to perform an action on a single weapon, show weapon list - if (curMenuWeapons[client] == Restrict_Weapon || curMenuWeapons[client] == Unrestrict_Weapon) + if (curMenuWeapons[client] == Weapon) { decl String:weapon[WEAPONS_MAX_LENGTH]; new Handle:arrayWeapons = INVALID_HANDLE; @@ -151,6 +136,11 @@ WeaponsMenuWeapons(client, WeaponsMenu:type) new bool:menu = WeaponsIsWeaponMenu(weapon); + if (RestrictIsWeaponRestricted(weapon)) + { + Format(weapon, sizeof(weapon), "%s*", weapon); + } + // If weapon restriction is blocked for the menu, disable option if (menu) { @@ -166,17 +156,22 @@ WeaponsMenuWeapons(client, WeaponsMenu:type) CloseHandle(arrayWeapons); } // If client wants to perform an action on a weapon group, show custom group list - else if (curMenuWeapons[client] == Restrict_Group || curMenuWeapons[client] == Unrestrict_Group) + else if (curMenuWeapons[client] == WeaponGroup) { decl String:weapongroup[WEAPONS_MAX_LENGTH]; new Handle:arrayWeaponGroups = INVALID_HANDLE; - new size = WeaponsCreateWeaponGroupArray(arrayWeaponGroups); + new size = RestrictCreateGroupArray(arrayWeaponGroups); // x = Array index for (new x = 0; x < size; x++) { GetArrayString(arrayWeaponGroups, x, weapongroup, sizeof(weapongroup)); + if (RestrictIsWeaponRestricted(weapongroup)) + { + Format(weapongroup, sizeof(weapongroup), "%s*", weapongroup); + } + AddMenuItem(menu_weapons_weapons, weapongroup, weapongroup); } @@ -206,59 +201,79 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, new WpnRestrictQuery:output; - // If client is restricting a weapon or group, then call the restrict function - if (curMenuWeapons[client] == Restrict_Weapon || curMenuWeapons[client] == Restrict_Group) + // Set restrict to true if were restricting a weapon/group, false if not + new bool:restrict; + if (RestrictIsWeaponGroup(weapon)) { - output = WeaponRestrictRestrict(weapon); + restrict = RestrictIsGroupRestricted(weapon); + } + else + { + restrict = RestrictIsWeaponRestricted(weapon); + } + + if (restrict) + { + decl String:display[WEAPONS_MAX_LENGTH]; + + output = RestrictRestrict(weapon, display); switch(output) { case Successful_Weapon: { - ZR_PrintToChat(0, "Restrict weapon", weapon); + ZR_PrintToChat(0, "Restrict weapon", display); } case Successful_Group: { decl String:weaponlist[128]; - WeaponRestrictGetWeaponList(weapon, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(0, "Restrict custom weapon group", weapon, weaponlist); + ZR_PrintToChat(0, "Restrict custom weapon group", display, weaponlist); } case Failed_Weapon: { - ZR_PrintToChat(client, "Restrict weapon failed", weapon); + ZR_PrintToChat(client, "Restrict weapon failed", display); + } + case Failed_Group: + { + decl String:weaponlist[128]; + RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); + + ZR_PrintToChat(client, "Restrict custom weapon group failed", display, weaponlist); } case Invalid: { - ZR_PrintToChat(client, "Weapon invalid", weapon); + ZR_PrintToChat(client, "Weapon invalid", display); } } } - // If client is unrestricting a weapon or group, then call the unrestrict function - else if (curMenuWeapons[client] == Unrestrict_Weapon || curMenuWeapons[client] == Unrestrict_Group) + else { - output = WeaponRestrictUnrestrict(weapon); + decl String:display[WEAPONS_MAX_LENGTH]; + + output = RestrictUnrestrict(weapon, display); switch(output) { case Successful_Weapon: { - ZR_PrintToChat(0, "Unrestrict weapon", weapon); + ZR_PrintToChat(0, "Unrestrict weapon", display); } case Successful_Group: { decl String:weaponlist[128]; - WeaponRestrictGetWeaponList(weapon, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(0, "Unrestrict custom weapon group", weapon, weaponlist); + ZR_PrintToChat(0, "Unrestrict custom weapon group", display, weaponlist); } case Failed_Weapon: { - ZR_PrintToChat(client, "Unrestrict weapon failed", weapon); + ZR_PrintToChat(client, "Unrestrict weapon failed", display); } case Invalid: { - ZR_PrintToChat(client, "Weapon invalid", weapon); + ZR_PrintToChat(client, "Weapon invalid", display); } } } diff --git a/src/zr/weapons/restrict.inc b/src/zr/weapons/restrict.inc index 807ebf6..6498993 100644 --- a/src/zr/weapons/restrict.inc +++ b/src/zr/weapons/restrict.inc @@ -36,19 +36,19 @@ enum WpnRestrictQuery /** * Initialize data and hook commands. */ -WeaponRestrictInit() +RestrictInit() { // Initialize weapon restrict array gRestrictedWeapons = CreateArray(32, 0); // Hook buy command - RegConsoleCmd("buy", WeaponRestrictBuyHook); + RegConsoleCmd("buy", RestrictBuyHook); } /** * Loads weapon data from file. */ -WeaponRestrictOnMapStart() +RestrictOnMapStart() { // Clear restricted weapons RestrictWeaponUnrestrictAll(); @@ -70,6 +70,11 @@ WeaponRestrictOnMapStart() SetFailState("\"%s\" missing from server", path); } + RestrictValidateWeaponGroups(); +} + +RestrictValidateWeaponGroups() +{ KvRewind(kvWeaponGroups); if (KvGotoFirstSubKey(kvWeaponGroups)) @@ -78,7 +83,7 @@ WeaponRestrictOnMapStart() { if (KvGotoFirstSubKey(kvWeaponGroups)) { - decl String:groupweapon[32]; + decl String:groupweapon[WEAPONS_MAX_LENGTH]; do { @@ -87,7 +92,7 @@ WeaponRestrictOnMapStart() if (!WeaponsIsValidWeapon(groupweapon)) { - // TODO: LOG INVALID WEAPON + // VALIDATE } } while (KvGotoNextKey(kvWeaponGroups)); @@ -110,9 +115,9 @@ RestrictWeaponUnrestrictAll() * * @param client The client index. */ -WeaponRestrictClientInit(client) +RestrictClientInit(client) { - gCanUseHookID[client] = Hacks_Hook(client, HACKS_HTYPE_WEAPON_CANUSE, WeaponRestrictCanUse, false); + gCanUseHookID[client] = Hacks_Hook(client, HACKS_HTYPE_WEAPON_CANUSE, RestrictCanUse, false); } /** @@ -120,7 +125,7 @@ WeaponRestrictClientInit(client) * * @param client The client index. */ -WeaponRestrictClientDisconnect(client) +RestrictOnClientDisconnect(client) { Hacks_Unhook(gCanUseHookID[client]); } @@ -132,7 +137,7 @@ WeaponRestrictClientDisconnect(client) * @param client The client index. * @param argc Argument count. */ -public Action:WeaponRestrictBuyHook(client, argc) +public Action:RestrictBuyHook(client, argc) { // If plugin is disabled then stop new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); @@ -157,7 +162,7 @@ public Action:WeaponRestrictBuyHook(client, argc) ReplaceString(weapon, sizeof(weapon), "weapon_", ""); // Check if the weapon is restricted, if so then block command - if (WeaponRestrictIsRestricted(weapon)) + if (RestrictIsWeaponRestricted(weapon)) { ZR_PrintToChat(client, "Weapon is restricted", weapon); @@ -179,70 +184,20 @@ public Action:WeaponRestrictBuyHook(client, argc) * Failed_Group: The call failed to restrict a weapon group. * Invalid: The call was unsuccessful due to invalid weapon. */ -WpnRestrictQuery:WeaponRestrictRestrict(const String:weapon[]) +WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[]) { - if (WeaponRestrictIsCustomGroup(weapon)) + if (RestrictIsWeaponGroup(weapon)) { - KvRewind(kvWeaponGroups); - KvJumpToKey(kvWeaponGroups, weapon); - - if (KvGotoFirstSubKey(kvWeaponGroups)) + if (RestrictIsGroupRestricted(weapon)) { - decl String:groupweapon[32]; - - do - { - - KvGetSectionName(kvWeaponGroups, groupweapon, sizeof(groupweapon)); - - // If weapon is invalid, then skip - if (!WeaponsIsValidWeapon(groupweapon)) - { - continue; - } - - if (!WeaponRestrictIsRestricted(groupweapon)) - { - PushArrayString(gRestrictedWeapons, groupweapon); - } - } while (KvGotoNextKey(kvWeaponGroups)); + return Failed_Group; } - return Successful_Group; - } - - if (!WeaponsIsValidWeapon(weapon)) - { - return Invalid; - } - - if (WeaponRestrictIsRestricted(weapon)) - { - return Failed_Weapon; - } - - PushArrayString(gRestrictedWeapons, weapon); - - return Successful_Weapon; -} - -/** - * Unrestricts 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. - * Failed_Weapon: The call failed to restrict a weapon. - * Failed_Group: The call failed to restrict a weapon group. - * Invalid: The call was unsuccessful due to invalid weapon. - */ -WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[]) -{ - if (WeaponRestrictIsCustomGroup(weapon)) - { KvRewind(kvWeaponGroups); KvJumpToKey(kvWeaponGroups, weapon); + KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH); + if (KvGotoFirstSubKey(kvWeaponGroups)) { decl String:groupweapon[WEAPONS_MAX_LENGTH]; @@ -257,9 +212,69 @@ WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[]) continue; } - if (WeaponRestrictIsRestricted(groupweapon)) + if (!RestrictIsWeaponRestricted(groupweapon)) { - new weaponindex = WeaponRestrictGetIndex(groupweapon); + PushArrayString(gRestrictedWeapons, groupweapon); + } + } while (KvGotoNextKey(kvWeaponGroups)); + } + + return Successful_Group; + } + + if (!WeaponsIsValidWeapon(weapon)) + { + return Invalid; + } + + if (RestrictIsWeaponRestricted(weapon)) + { + return Failed_Weapon; + } + + WeaponGetDisplayName(weapon, display); + + PushArrayString(gRestrictedWeapons, display); + + return Successful_Weapon; +} + +/** + * Unrestricts 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. + * Failed_Weapon: The call failed to restrict a weapon. + * Failed_Group: The call failed to restrict a weapon group. + * Invalid: The call was unsuccessful due to invalid weapon. + */ +WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[]) +{ + if (RestrictIsWeaponGroup(weapon)) + { + KvRewind(kvWeaponGroups); + KvJumpToKey(kvWeaponGroups, weapon); + + KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH); + + if (KvGotoFirstSubKey(kvWeaponGroups)) + { + decl String:groupweapon[WEAPONS_MAX_LENGTH]; + + do + { + KvGetSectionName(kvWeaponGroups, groupweapon, sizeof(groupweapon)); + + // If weapon is invalid, then skip + if (!WeaponsIsValidWeapon(groupweapon)) + { + continue; + } + + if (RestrictIsWeaponRestricted(groupweapon)) + { + new weaponindex = RestrictGetIndex(groupweapon); if (weaponindex > -1) { RemoveFromArray(gRestrictedWeapons, weaponindex); @@ -276,12 +291,14 @@ WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[]) return Invalid; } - if (!WeaponRestrictIsRestricted(weapon)) + if (!RestrictIsWeaponRestricted(weapon)) { return Failed_Weapon; } - new weaponindex = WeaponRestrictGetIndex(weapon); + WeaponGetDisplayName(weapon, display); + + new weaponindex = RestrictGetIndex(display); if (weaponindex > -1) { RemoveFromArray(gRestrictedWeapons, weaponindex); @@ -295,7 +312,7 @@ WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[]) * * @param weapon The weapon name. */ -bool:WeaponRestrictIsRestricted(const String:weapon[]) +bool:RestrictIsWeaponRestricted(const String:weapon[]) { new size = GetArraySize(gRestrictedWeapons); for (new x = 0; x < size; x++) @@ -312,12 +329,40 @@ bool:WeaponRestrictIsRestricted(const String:weapon[]) return false; } +/** + * Checks if a weapon group is restricted. + * + * @param weapongroup The weapon group name. + */ +bool:RestrictIsGroupRestricted(const String:weapongroup[]) +{ + KvRewind(kvWeaponGroups); + if (KvJumpToKey(kvWeaponGroups, weapongroup)) + { + decl String:groupweapon[WEAPONS_MAX_LENGTH]; + + do + { + KvGetSectionName(kvWeaponGroups, groupweapon, WEAPONS_MAX_LENGTH); + + if (!RestrictIsWeaponRestricted(groupweapon)) + { + return false; + } + } while (KvGotoNextKey(kvWeaponGroups)); + + return true; + } + + return false; +} + /** * Returns the array index of the restricted weapon. * * @param weapon The weapon name. */ -WeaponRestrictGetIndex(const String:weapon[]) +RestrictGetIndex(const String:weapon[]) { new size = GetArraySize(gRestrictedWeapons); for (new x = 0; x < size; x++) @@ -340,7 +385,7 @@ WeaponRestrictGetIndex(const String:weapon[]) * @param groupname Name of the group to check. * @return True if it's a group, false if not. */ -bool:WeaponRestrictIsCustomGroup(const String:groupname[]) +bool:RestrictIsWeaponGroup(const String:groupname[]) { // Reset the traversal stack KvRewind(kvWeaponGroups); @@ -349,6 +394,34 @@ bool:WeaponRestrictIsCustomGroup(const String:groupname[]) return KvJumpToKey(kvWeaponGroups, groupname); } +/** + * Creates an array of all listed weapon groups in weapongroups.txt. + * @param arrayWeaponGroups The handle of the array, don't forget to call CloseHandle + * on it when finished! + * @return The size of the array. + */ +RestrictCreateGroupArray(&Handle:arrayWeaponGroups, maxlen = WEAPONS_MAX_LENGTH) +{ + arrayWeaponGroups = CreateArray(maxlen); + new count = 0; + + KvRewind(kvWeaponGroups); + if (KvGotoFirstSubKey(kvWeaponGroups)) + { + decl String:weapongroup[maxlen]; + + do + { + KvGetSectionName(kvWeaponGroups, weapongroup, maxlen); + + PushArrayString(arrayWeaponGroups, weapongroup); + count++; + } while (KvGotoNextKey(kvWeaponGroups)); + } + + return count; +} + /** * Returns a string of all weapons in a custom weapon group separated * by the provided character. @@ -358,7 +431,7 @@ bool:WeaponRestrictIsCustomGroup(const String:groupname[]) * @param maxlen Maximum length of the weapon list, the rest is truncated. * @param separator Separator character between weapon names. */ -WeaponRestrictGetWeaponList(const String:groupname[], String:weaponlist[], maxlen, const String:separator[]) +RestrictGetGroupWeapons(const String:groupname[], String:weaponlist[], maxlen, const String:separator[]) { KvRewind(kvWeaponGroups); KvJumpToKey(kvWeaponGroups, groupname); @@ -397,7 +470,7 @@ WeaponRestrictGetWeaponList(const String:groupname[], String:weaponlist[], maxle * @param weapon The weapon index. * @return 0 to block weapon pickup, Hacks_Continue to allow. */ -public WeaponRestrictCanUse(client, weapon, dummy1, dummy2, dummy3, dummy4) +public RestrictCanUse(client, weapon, dummy1, dummy2, dummy3, dummy4) { // If plugin is disabled then stop new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); @@ -413,7 +486,7 @@ public WeaponRestrictCanUse(client, weapon, dummy1, dummy2, dummy3, dummy4) ReplaceString(weaponname, sizeof(weaponname), "weapon_", ""); // If the weapon is restricted then prevent pickup - if (WeaponRestrictIsRestricted(weaponname)) + if (RestrictIsWeaponRestricted(weaponname)) { return 0; } diff --git a/src/zr/weapons/weapons.inc b/src/zr/weapons/weapons.inc index 39afb52..014d3f0 100644 --- a/src/zr/weapons/weapons.inc +++ b/src/zr/weapons/weapons.inc @@ -6,21 +6,11 @@ * ==================== */ -/** - * Handle to store trie weapon data - */ -new Handle:trieWeapons = INVALID_HANDLE; - /** * Maximum length of a weapon name string */ #define WEAPONS_MAX_LENGTH 32 -/** - * @section Config array indexes. - */ -#define WEAPON_RESTRICT 0 -#define WEAPON_MENU 1 /** * @endsection */ @@ -34,20 +24,17 @@ new Handle:kvWeapons = INVALID_HANDLE; #include "zr/weapons/markethandler" #include "zr/weapons/menu_weapons" +WeaponsInit() +{ + // Forward event to sub-module + RestrictInit(); +} + /** * Loads weapon data from file. */ WeaponsOnMapStart() { - // Destroy trie data if populated - if (trieWeapons != INVALID_HANDLE) - { - CloseHandle(trieWeapons); - } - - // Create trie to store weapon data - trieWeapons = CreateTrie(); - // Load weapon data if (kvWeapons != INVALID_HANDLE) { @@ -65,6 +52,15 @@ WeaponsOnMapStart() SetFailState("\"%s\" missing from server", path); } + // Validate weapons config + WeaponsValidateWeaponsConfig(); + + // Forward event to sub-module + RestrictOnMapStart(); +} + +WeaponsValidateWeaponsConfig() +{ KvRewind(kvWeapons); if (KvGotoFirstSubKey(kvWeapons)) { @@ -78,17 +74,22 @@ WeaponsOnMapStart() KvGetString(kvWeapons, "restrict", restrict, sizeof(restrict), "no"); KvGetString(kvWeapons, "menu", menu, sizeof(menu), "yes"); - new bool:config[2]; - config[WEAPON_RESTRICT] = ConfigOptionToBool(restrict); - config[WEAPON_MENU] = ConfigOptionToBool(menu); - - SetTrieArray(trieWeapons, weapon, config, sizeof(config), false); + // VALIDATE } while (KvGotoNextKey(kvWeapons)); } - - // Weapon restrict - WeaponRestrictOnMapStart(); +} + +WeaponsClientInit(client) +{ + // Forward event to sub-module + RestrictClientInit(client); +} + +WeaponsOnClientDisconnect(client) +{ + // Forward event to sub-module + RestrictOnClientDisconnect(client); } /** @@ -119,34 +120,6 @@ WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH) return count; } -/** - * Creates an array of all listed weapon groups in weapongroups.txt. - * @param arrayWeaponGroups The handle of the array, don't forget to call CloseHandle - * on it when finished! - * @return The size of the array. - */ -WeaponsCreateWeaponGroupArray(&Handle:arrayWeaponGroups, maxlen = WEAPONS_MAX_LENGTH) -{ - arrayWeaponGroups = CreateArray(maxlen); - new count = 0; - - KvRewind(kvWeaponGroups); - if (KvGotoFirstSubKey(kvWeaponGroups)) - { - decl String:weapongroup[maxlen]; - - do - { - KvGetSectionName(kvWeaponGroups, weapongroup, maxlen); - - PushArrayString(arrayWeaponGroups, weapongroup); - count++; - } while (KvGotoNextKey(kvWeaponGroups)); - } - - return count; -} - /** * Checks if a weapon is valid (aka listed in weapons.txt) * @param weapon The weapon name. @@ -154,9 +127,49 @@ WeaponsCreateWeaponGroupArray(&Handle:arrayWeaponGroups, maxlen = WEAPONS_MAX_LE */ bool:WeaponsIsValidWeapon(const String:weapon[]) { - new bool:config[2]; + KvRewind(kvWeapons); + if (KvGotoFirstSubKey(kvWeapons)) + { + decl String:validweapon[WEAPONS_MAX_LENGTH]; + + do + { + KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon)); + + if (StrEqual(validweapon, weapon, false)) + { + return true; + } + + } while (KvGotoNextKey(kvWeapons)); + } - return GetTrieArray(trieWeapons, weapon, config, sizeof(config)); + return false; +} + +/** + * Looks up a weapon in weapons.txt and returns exact display name + * @param weapon The weapon name. + * @param display Returns with the display name, is not changed if weapon is invalid. + */ +WeaponGetDisplayName(const String:weapon[], String:display[]) +{ + KvRewind(kvWeapons); + if (KvGotoFirstSubKey(kvWeapons)) + { + decl String:validweapon[WEAPONS_MAX_LENGTH]; + + do + { + KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon)); + + if (StrEqual(validweapon, weapon, false)) + { + strcopy(display, WEAPONS_MAX_LENGTH, validweapon); + } + + } while (KvGotoNextKey(kvWeapons)); + } } /** @@ -164,12 +177,28 @@ bool:WeaponsIsValidWeapon(const String:weapon[]) * @param weapon The weapon name. * @return Returns true if restricted, false it not. */ -bool:WeaponsIsWeaponRestrict(const String:weapon[]) +bool:WeaponsIsRestrict(const String:weapon[]) { - new bool:config[2]; - GetTrieArray(trieWeapons, weapon, config, sizeof(config)); + KvRewind(kvWeapons); + if (KvGotoFirstSubKey(kvWeapons)) + { + decl String:validweapon[WEAPONS_MAX_LENGTH]; + decl String:restrict[8]; + + do + { + KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon)); + + if (StrEqual(validweapon, weapon, false)) + { + KvGetString(kvWeapons, validweapon, restrict, sizeof(restrict), "no"); + + return ConfigOptionToBool(restrict); + } + } while (KvGotoNextKey(kvWeapons)); + } - return config[WEAPON_RESTRICT]; + return false; } /** @@ -179,8 +208,24 @@ bool:WeaponsIsWeaponRestrict(const String:weapon[]) */ bool:WeaponsIsWeaponMenu(const String:weapon[]) { - new bool:config[2]; - GetTrieArray(trieWeapons, weapon, config, sizeof(config)); + KvRewind(kvWeapons); + if (KvGotoFirstSubKey(kvWeapons)) + { + decl String:validweapon[WEAPONS_MAX_LENGTH]; + decl String:menu[8]; + + do + { + KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon)); + + if (StrEqual(validweapon, weapon, false)) + { + KvGetString(kvWeapons, validweapon, menu, sizeof(menu), "yes"); + + return ConfigOptionToBool(menu); + } + } while (KvGotoNextKey(kvWeapons)); + } - return config[WEAPON_MENU]; + return false; } \ No newline at end of file diff --git a/src/zr/zombiereloaded.inc b/src/zr/zombiereloaded.inc index 553dc7a..e199c54 100644 --- a/src/zr/zombiereloaded.inc +++ b/src/zr/zombiereloaded.inc @@ -33,27 +33,35 @@ enum ZTeam #define DXLEVEL_MIN 90 #define DEFAULT_FOV 90 -#define LOG_CORE_EVENTS 1 // Executing config files, error messages, etc. -#define LOG_GAME_EVENTS 2 // Admin commands, suicide prevention, anticamp kills. -#define LOG_PLAYER_COMMANDS 4 // Commands executed by non-admins: zspawn, teleport, class change. -#define LOG_DEBUG 8 // Debug messages. -#define LOG_DEBUG_DETAIL 16 // Debug messages with more detail. May cause spam. -#define LOG_DEBUG_MAX_DETAIL 32 // Low level debug messages. Causes spam! Only enable for a limited period right before and after testing. -#define LOG_TO_ADMINS 64 // Write all kinds of log messages to admin chat. -#define LOG_TO_CLIENT 128 // Write all log messages related to a player, to the players console. -#define LOG_IGNORE_CONSOLE 256 // Don't log messages from client 0 (console). -#define LOG_MODULES_ENABLED 512 // Enable detailed log control for developers. Module logs overrides previous flags. -#define LOG_MODULE_ZOMBIE 1024 // zombie.inc -#define LOG_MODULE_AMBIENCE 2048 // ambience.inc -#define LOG_MODULE_OVERLAYS 4096 // overlays.inc -#define LOG_MODULE_SAYTRIGGERS 8192 // sayhooks.inc -#define LOG_MODULE_TELEPORT 16384 // teleport.inc -#define LOG_MODULE_CLASSES 32768 // playerclasses/* -#define LOG_MODULE_WEAPONRESTICT 65536 // weaponrestrict.inc -#define LOG_MODULE_COMMANDS 131072 // commands.inc -#define LOG_MODULE_ANTICAMP 262144 // anticamp.inc -#define LOG_MODULE_DAMAGECONTROL 524288 // damagecontrol.inc -#define LOG_MODULE_OFFSETS 1048576 // offsets.inc +/** + * @section Logging flags. + */ +#define LOG_CORE_EVENTS 1 /** Executing config files, error messages, etc. */ +#define LOG_GAME_EVENTS 2 /** Admin commands, suicide prevention, anticamp kills. */ +#define LOG_PLAYER_COMMANDS 4 /** Commands executed by non-admins: zspawn, teleport, class change. */ +#define LOG_DEBUG 8 /** Debug messages. */ +#define LOG_DEBUG_DETAIL 16 /** Debug messages with more detail. May cause spam. */ +#define LOG_DEBUG_MAX_DETAIL 32 /** Low level debug messages. Causes spam! Only enable for a limited period right before and after testing. */ +#define LOG_TO_ADMINS 64 /** Copy kinds of log events to admin chat. */ +#define LOG_TO_CLIENT 128 /** Copy all log events related to a player, to the players console. */ +#define LOG_IGNORE_CONSOLE 256 /** Don't log messages from the console (client 0). */ +#define LOG_MODULES_ENABLED 512 /** Enable module based log control. Module logs overrides previous flags, including debug flags. */ +#define LOG_MODULE_CORE 1024 /** The core of the plugin (startup, loading configs, etc.). Not really a module. */ +#define LOG_MODULE_COMMANDS 2048 /** commands.inc */ +#define LOG_MODULE_CLASSES 4096 /** Class system - playerclasses/*.inc */ +#define LOG_MODULE_ZOMBIE 8192 /** zombie.inc */ +#define LOG_MODULE_SAYTRIGGERS 16384 /** sayhooks.inc */ +#define LOG_MODULE_AMBIENCE 32768 /** ambience.inc */ +#define LOG_MODULE_OVERLAYS 65536 /** overlays.inc */ +#define LOG_MODULE_TELEPORT 131072 /** teleport.inc */ +#define LOG_MODULE_WEAPONS 262144 /** Weapons module - weapons/*.inc */ +#define LOG_MODULE_COMMANDS 524288 /** commands.inc */ +#define LOG_MODULE_ANTICAMP 1048576 /** anticamp.inc */ +#define LOG_MODULE_DAMAGECONTROL 2097152 /** damagecontrol.inc */ +#define LOG_MODULE_OFFSETS 4194304 /** offsets.inc */ +/* + * @endsection + */ new bool:market; new dxLevel[MAXPLAYERS + 1];