From 34d357a2c3eaec2c5c1f81d2173930b218839440 Mon Sep 17 00:00:00 2001 From: Greyscale Date: Mon, 13 Apr 2009 22:00:37 +0200 Subject: [PATCH] Fixed menu toggle restrictions, disabled group menu restrictions, next commit will have it done, fixed a bunch of compiler errors :P --- src/zr/cvars.inc | 2 +- src/zr/weapons/menu_weapons.inc | 124 +++++++++++++++++--------------- src/zr/weapons/restrict.inc | 48 +++++++++++-- src/zr/zadmin.inc | 46 ++++++------ src/zr/zombiereloaded.inc | 11 ++- 5 files changed, 139 insertions(+), 92 deletions(-) diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index f8160b0..37d9fe7 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -263,7 +263,7 @@ LogFlagCheck(logtype, modulefilter = 0) { if (modulefilter && (logtype & LOG_MODULES_ENABLED)) { - if (type & modulefilter) + if (logtype & modulefilter) { return 1; } diff --git a/src/zr/weapons/menu_weapons.inc b/src/zr/weapons/menu_weapons.inc index 0465645..f5c6167 100644 --- a/src/zr/weapons/menu_weapons.inc +++ b/src/zr/weapons/menu_weapons.inc @@ -43,7 +43,7 @@ WeaponsMenuMain(client) Format(zmarket, sizeof(zmarket), "%t", "Weapons menu main market"); AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction); - AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction); + AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction, ITEMDRAW_DISABLED); // Disable market option if market isn't installed if (market) @@ -120,65 +120,75 @@ WeaponsMenuWeapons(client, WeaponsMenu:type) SetGlobalTransTarget(client); - 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] == Weapon) + switch(curMenuWeapons[client]) { - decl String:weapon[WEAPONS_MAX_LENGTH]; - new Handle:arrayWeapons = INVALID_HANDLE; - new size = WeaponsCreateWeaponArray(arrayWeapons); - - // x = Array index - for (new x = 0; x < size; x++) + case Weapon: { - GetArrayString(arrayWeapons, x, weapon, sizeof(weapon)); + SetMenuTitle(menu_weapons_weapons, "%t\n ", "Weapons menu weapons weapon title"); - new bool:menu = WeaponsIsWeaponMenu(weapon); + decl String:weapon[WEAPONS_MAX_LENGTH]; + decl String:display[WEAPONS_MAX_LENGTH + 1]; + new Handle:arrayWeapons = INVALID_HANDLE; + new size = WeaponsCreateWeaponArray(arrayWeapons); - if (RestrictIsWeaponRestricted(weapon)) + // x = Array index + for (new x = 0; x < size; x++) { - Format(weapon, sizeof(weapon), "%s*", weapon); + GetArrayString(arrayWeapons, x, weapon, sizeof(weapon)); + + new bool:menu = WeaponsIsWeaponMenu(weapon); + + strcopy(display, sizeof(display), weapon); + + if (RestrictIsWeaponRestricted(weapon)) + { + Format(display, sizeof(display), "%s*", weapon); + } + + // If weapon restriction is blocked for the menu, disable option + if (menu) + { + AddMenuItem(menu_weapons_weapons, weapon, display); + } + else + { + AddMenuItem(menu_weapons_weapons, weapon, display, ITEMDRAW_DISABLED); + } } - // If weapon restriction is blocked for the menu, disable option - if (menu) - { - AddMenuItem(menu_weapons_weapons, weapon, weapon); - } - else - { - AddMenuItem(menu_weapons_weapons, weapon, weapon, ITEMDRAW_DISABLED); - } + // Kill the array handle + CloseHandle(arrayWeapons); } - - // Kill the array handle - CloseHandle(arrayWeapons); - } - // If client wants to perform an action on a weapon group, show custom group list - else if (curMenuWeapons[client] == WeaponGroup) - { - decl String:weapongroup[WEAPONS_MAX_LENGTH]; - new Handle:arrayWeaponGroups = INVALID_HANDLE; - new size = RestrictCreateGroupArray(arrayWeaponGroups); - - // x = Array index - for (new x = 0; x < size; x++) + // If client wants to perform an action on a weapon group, show custom group list + case WeaponGroup: { - GetArrayString(arrayWeaponGroups, x, weapongroup, sizeof(weapongroup)); + SetMenuTitle(menu_weapons_weapons, "%t\n ", "Weapons menu weapons group title"); - if (RestrictIsWeaponRestricted(weapongroup)) + decl String:weapongroup[WEAPONS_MAX_LENGTH]; + decl String:display[WEAPONS_MAX_LENGTH + 1]; + new Handle:arrayWeaponGroups = INVALID_HANDLE; + new size = RestrictCreateGroupArray(arrayWeaponGroups); + + // x = Array index + for (new x = 0; x < size; x++) { - Format(weapongroup, sizeof(weapongroup), "%s*", weapongroup); + GetArrayString(arrayWeaponGroups, x, weapongroup, sizeof(weapongroup)); + + strcopy(display, sizeof(display), weapongroup); + + if (RestrictIsGroupRestricted(weapongroup)) + { + Format(display, sizeof(display), "%s*", weapongroup); + } + + AddMenuItem(menu_weapons_weapons, weapongroup, display); } - AddMenuItem(menu_weapons_weapons, weapongroup, weapongroup); + // Kill the array handle + CloseHandle(arrayWeaponGroups); } - - // Kill the array handle - CloseHandle(arrayWeaponGroups); } - SetMenuExitBackButton(menu_weapons_weapons, true); DisplayMenu(menu_weapons_weapons, client, MENU_TIME_FOREVER); @@ -212,7 +222,7 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, restrict = RestrictIsWeaponRestricted(weapon); } - if (restrict) + if (!restrict) { decl String:display[WEAPONS_MAX_LENGTH]; @@ -222,29 +232,29 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, { case Successful_Weapon: { - ZR_PrintToChat(0, "Restrict weapon", display); + ZR_PrintToChat(0, "Restrict weapon", weapon); } case Successful_Group: { decl String:weaponlist[128]; - RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(0, "Restrict custom weapon group", display, weaponlist); + ZR_PrintToChat(0, "Restrict custom weapon group", weapon, weaponlist); } case Failed_Weapon: { - ZR_PrintToChat(client, "Restrict weapon failed", display); + ZR_PrintToChat(client, "Restrict weapon failed", weapon); } case Failed_Group: { decl String:weaponlist[128]; - RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(client, "Restrict custom weapon group failed", display, weaponlist); + ZR_PrintToChat(client, "Restrict custom weapon group failed", weapon, weaponlist); } case Invalid: { - ZR_PrintToChat(client, "Weapon invalid", display); + ZR_PrintToChat(client, "Weapon invalid", weapon); } } } @@ -258,22 +268,22 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, { case Successful_Weapon: { - ZR_PrintToChat(0, "Unrestrict weapon", display); + ZR_PrintToChat(0, "Unrestrict weapon", weapon); } case Successful_Group: { decl String:weaponlist[128]; - RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", "); + RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", "); - ZR_PrintToChat(0, "Unrestrict custom weapon group", display, weaponlist); + ZR_PrintToChat(0, "Unrestrict custom weapon group", weapon, weaponlist); } case Failed_Weapon: { - ZR_PrintToChat(client, "Unrestrict weapon failed", display); + ZR_PrintToChat(client, "Unrestrict weapon failed", weapon); } case Invalid: { - ZR_PrintToChat(client, "Weapon invalid", display); + ZR_PrintToChat(client, "Weapon invalid", weapon); } } } diff --git a/src/zr/weapons/restrict.inc b/src/zr/weapons/restrict.inc index 6498993..1b8a7a8 100644 --- a/src/zr/weapons/restrict.inc +++ b/src/zr/weapons/restrict.inc @@ -222,6 +222,8 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[]) return Successful_Group; } + WeaponGetDisplayName(weapon, display); + if (!WeaponsIsValidWeapon(weapon)) { return Invalid; @@ -232,8 +234,6 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[]) return Failed_Weapon; } - WeaponGetDisplayName(weapon, display); - PushArrayString(gRestrictedWeapons, display); return Successful_Weapon; @@ -286,6 +286,8 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[]) return Successful_Group; } + WeaponGetDisplayName(weapon, display); + if (!WeaponsIsValidWeapon(weapon)) { return Invalid; @@ -296,8 +298,6 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[]) return Failed_Weapon; } - WeaponGetDisplayName(weapon, display); - new weaponindex = RestrictGetIndex(display); if (weaponindex > -1) { @@ -330,7 +330,7 @@ bool:RestrictIsWeaponRestricted(const String:weapon[]) } /** - * Checks if a weapon group is restricted. + * Checks if a weapon group is completely restricted. * * @param weapongroup The weapon group name. */ @@ -357,6 +357,44 @@ bool:RestrictIsGroupRestricted(const String:weapongroup[]) return false; } +/** + * Checks if a weapon group is completely unrestricted. + * + * @param weapongroup The weapon group name. + */ +bool:RestrictIsGroupUnrestricted(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; +} + +/** + * Checks if a weapon group is partially restricted. + * + * @param weapongroup The weapon group name. + */ +bool:RestrictIsPartialRestricted(const String:weapongroup[]) +{ + return (!RestrictIsGroupRestricted(weapongroup) && !RestrictIsGroupUnrestricted(weapongroup)); +} + /** * Returns the array index of the restricted weapon. * diff --git a/src/zr/zadmin.inc b/src/zr/zadmin.inc index 1e072de..26a92c7 100644 --- a/src/zr/zadmin.inc +++ b/src/zr/zadmin.inc @@ -498,7 +498,7 @@ ZRLogFlagsMenu(client) SetMenuTitle(menu_log_flags, "%t\n ", "!zadmin log flags title"); new client_flags = GetUserFlagBits(client); - new item_disabled = (client_flags & ADMFLAG_ROOT) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; + new item_state = (client_flags & ADMFLAG_ROOT) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; decl String:z_log_core[64]; decl String:z_log_game[64]; @@ -516,7 +516,7 @@ ZRLogFlagsMenu(client) decl String:z_log_module_saytriggers[64]; decl String:z_log_module_teleport[64]; decl String:z_log_module_classes[64]; - decl String:z_log_module_weaponrestrict[64]; + decl String:z_log_module_weapons[64]; decl String:z_log_module_commands[64]; decl String:z_log_module_anticamp[64]; decl String:z_log_module_damagecontrol[64]; @@ -538,33 +538,33 @@ ZRLogFlagsMenu(client) Format(z_log_module_saytriggers, sizeof(z_log_module_saytriggers), "Chat commands (%d)", LogHasFlag(LOG_MODULE_SAYTRIGGERS)); Format(z_log_module_teleport, sizeof(z_log_module_teleport), "Teleporter (%d)", LogHasFlag(LOG_MODULE_TELEPORT)); Format(z_log_module_classes, sizeof(z_log_module_classes), "Classes (%d)", LogHasFlag(LOG_MODULE_CLASSES)); - Format(z_log_module_weaponrestrict, sizeof(z_log_module_weaponrestrict), "Weapon restrictions (%d)", LogHasFlag(LOG_MODULE_WEAPONRESTICT)); + Format(z_log_module_weapons, sizeof(z_log_module_weapons), "Weapons (%d)", LogHasFlag(LOG_MODULE_WEAPONS)); Format(z_log_module_commands, sizeof(z_log_module_commands), "Admin commands (%d)", LogHasFlag(LOG_MODULE_COMMANDS)); Format(z_log_module_anticamp, sizeof(z_log_module_anticamp), "Anticamp (%d)", LogHasFlag(LOG_MODULE_ANTICAMP)); Format(z_log_module_damagecontrol, sizeof(z_log_module_damagecontrol), "Damage control (suicides) (%d)", LogHasFlag(LOG_MODULE_DAMAGECONTROL)); Format(z_log_module_offsets, sizeof(z_log_module_offsets), "Offsets (properties) (%d)", LogHasFlag(LOG_MODULE_OFFSETS)); - AddMenuItem(menu_log_flags, z_log_core, z_log_core, item_disabled); - AddMenuItem(menu_log_flags, z_log_game, z_log_game, item_disabled); - AddMenuItem(menu_log_flags, z_log_player, z_log_player, item_disabled); - AddMenuItem(menu_log_flags, z_log_debug, z_log_debug, item_disabled); - AddMenuItem(menu_log_flags, z_log_debug_detail, z_log_debug_detail, item_disabled); - AddMenuItem(menu_log_flags, z_log_debug_max, z_log_debug_max, item_disabled); + AddMenuItem(menu_log_flags, z_log_core, z_log_core, item_state); + AddMenuItem(menu_log_flags, z_log_game, z_log_game, item_state); + AddMenuItem(menu_log_flags, z_log_player, z_log_player, item_state); + AddMenuItem(menu_log_flags, z_log_debug, z_log_debug, item_state); + AddMenuItem(menu_log_flags, z_log_debug_detail, z_log_debug_detail, item_state); + AddMenuItem(menu_log_flags, z_log_debug_max, z_log_debug_max, item_state); AddMenuItem(menu_log_flags, z_log_admins, z_log_admins); AddMenuItem(menu_log_flags, z_log_client, z_log_client); - AddMenuItem(menu_log_flags, z_log_ignore_console, z_log_ignore_console, item_disabled); - AddMenuItem(menu_log_flags, z_log_modules_enabled, z_log_modules_enabled, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_zombie, z_log_module_zombie, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_ambience, z_log_module_ambience, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_overlays, z_log_module_overlays, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_saytriggers, z_log_module_saytriggers, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_teleport, z_log_module_teleport, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_classes, z_log_module_classes, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_weaponrestrict, z_log_module_weaponrestrict, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_commands, z_log_module_commands, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_anticamp, z_log_module_anticamp, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_damagecontrol, z_log_module_damagecontrol, item_disabled); - AddMenuItem(menu_log_flags, z_log_module_offsets, z_log_module_offsets, item_disabled); + AddMenuItem(menu_log_flags, z_log_ignore_console, z_log_ignore_console, item_state); + AddMenuItem(menu_log_flags, z_log_modules_enabled, z_log_modules_enabled, item_state); + AddMenuItem(menu_log_flags, z_log_module_zombie, z_log_module_zombie, item_state); + AddMenuItem(menu_log_flags, z_log_module_ambience, z_log_module_ambience, item_state); + AddMenuItem(menu_log_flags, z_log_module_overlays, z_log_module_overlays, item_state); + AddMenuItem(menu_log_flags, z_log_module_saytriggers, z_log_module_saytriggers, item_state); + AddMenuItem(menu_log_flags, z_log_module_teleport, z_log_module_teleport, item_state); + AddMenuItem(menu_log_flags, z_log_module_classes, z_log_module_classes, item_state); + AddMenuItem(menu_log_flags, z_log_module_weapons, z_log_module_weapons, item_state); + AddMenuItem(menu_log_flags, z_log_module_commands, z_log_module_commands, item_state); + AddMenuItem(menu_log_flags, z_log_module_anticamp, z_log_module_anticamp, item_state); + AddMenuItem(menu_log_flags, z_log_module_damagecontrol, z_log_module_damagecontrol, item_state); + AddMenuItem(menu_log_flags, z_log_module_offsets, z_log_module_offsets, item_state); SetMenuExitBackButton(menu_log_flags, true); DisplayMenu(menu_log_flags, client, MENU_TIME_FOREVER); @@ -658,7 +658,7 @@ public ZRLogFlagsMenuHandle(Handle:menu_log_flags , MenuAction:action, client, s } case 16: { - ToggleLogFlag(LOG_MODULE_WEAPONRESTICT); + ToggleLogFlag(LOG_MODULE_WEAPONS); ZRLogFlagsMenu(client); } case 17: diff --git a/src/zr/zombiereloaded.inc b/src/zr/zombiereloaded.inc index e199c54..d4fd152 100644 --- a/src/zr/zombiereloaded.inc +++ b/src/zr/zombiereloaded.inc @@ -48,17 +48,16 @@ enum ZTeam #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_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 */ +#define LOG_MODULE_WEAPONS 262144 /** Weapons module - weapons/ *.inc */ +#define LOG_MODULE_ANTICAMP 524288 /** anticamp.inc */ +#define LOG_MODULE_DAMAGECONTROL 1048576 /** damagecontrol.inc */ +#define LOG_MODULE_OFFSETS 2097152 /** offsets.inc */ /* * @endsection */