Made weapon management menu toggle restrictions (easier), and weapon names are now case-insensitive

This commit is contained in:
Greyscale 2009-04-13 20:33:13 +02:00
parent d074b68edf
commit 842e4030b9
11 changed files with 440 additions and 246 deletions

View File

@ -55,4 +55,11 @@
"G2SG1" {} "G2SG1" {}
"AWP" {} "AWP" {}
} }
"Grenades"
{
"hegrenade" {}
"flashbang" {}
"smokegrenade" {}
}
} }

View File

@ -106,7 +106,7 @@
"AK47" "AK47"
{ {
"restrict" "no" "restrict" "no"
"menu" "no" "menu" "yes"
} }
"M4A1" "M4A1"
@ -151,4 +151,33 @@
"menu" "yes" "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"
}
} }

View File

@ -222,6 +222,12 @@
"en" "Weapon group @green\"{1}\" ({2}) @defaulthas been unrestricted." "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" "Weapon invalid"
{ {
"#format" "{1:s}" "#format" "{1:s}"
@ -242,24 +248,14 @@
"en" "Weapons Management" "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" "en" "Toggle Weapon Group Restriction"
}
"Weapons menu main restrict weapon group"
{
"en" "Restrict a Weapon Group"
}
"Weapons menu main unrestrict weapon group"
{
"en" "Unrestrict a Weapon Group"
} }
"Weapons menu main market" // Option disabled if ZMarket isn't installed "Weapons menu main market" // Option disabled if ZMarket isn't installed
@ -269,7 +265,7 @@
"Weapons menu weapons title" "Weapons menu weapons title"
{ {
"en" "Toggle Restrictions:" "en" "Toggle Restrictions:\n * = restricted"
} }
"Suicide text" "Suicide text"

View File

@ -77,7 +77,10 @@ public OnPluginStart()
HookCommands(); HookCommands();
FindOffsets(); FindOffsets();
SetupGameData(); SetupGameData();
WeaponRestrictInit();
// Weapons
WeaponsInit();
InitDmgControl(); InitDmgControl();
// ====================================================================== // ======================================================================
@ -139,8 +142,6 @@ public OnMapEnd()
public OnConfigsExecuted() public OnConfigsExecuted()
{ {
decl String:mapconfig[PLATFORM_MAX_PATH]; decl String:mapconfig[PLATFORM_MAX_PATH];
GetCurrentMap(mapconfig, sizeof(mapconfig)); GetCurrentMap(mapconfig, sizeof(mapconfig));
@ -177,7 +178,7 @@ public OnClientPutInServer(client)
dispHP[client] = zhp; dispHP[client] = zhp;
// Forward event to modules. // Forward event to modules.
WeaponRestrictClientInit(client); WeaponsClientInit(client);
ClassClientInit(client); ClassClientInit(client);
if (!IsFakeClient(client)) AmbienceStart(client); if (!IsFakeClient(client)) AmbienceStart(client);
@ -199,7 +200,7 @@ public OnClientDisconnect(client)
PlayerLeft(client); PlayerLeft(client);
// Forward event to modules. // Forward event to modules.
WeaponRestrictClientDisconnect(client); WeaponsOnClientDisconnect(client);
ClassOnClientDisconnect(client); ClassOnClientDisconnect(client);
ZTeleResetClient(client); ZTeleResetClient(client);
AmbienceStop(client); AmbienceStop(client);

View File

@ -154,30 +154,41 @@ public Action:Command_Restrict(client, argc)
// Strip "weapon_" from entity name // Strip "weapon_" from entity name
ReplaceString(arg1, sizeof(arg1), "weapon_", ""); ReplaceString(arg1, sizeof(arg1), "weapon_", "");
new WpnRestrictQuery:output = WeaponRestrictRestrict(arg1); decl String:display[WEAPONS_MAX_LENGTH];
new WpnRestrictQuery:output = RestrictRestrict(arg1, display);
switch(output) switch(output)
{ {
case Successful_Weapon: case Successful_Weapon:
{ {
ZR_PrintToChat(0, "Restrict weapon", arg1); ZR_PrintToChat(0, "Restrict weapon", display);
} }
case Successful_Group: case Successful_Group:
{ {
decl String:weaponlist[128]; 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: 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; return Plugin_Handled;
} }
case Invalid: case Invalid:
{ {
ZR_ReplyToCommand(client, "Weapon invalid", arg1); ZR_ReplyToCommand(client, "Weapon invalid", display);
return Plugin_Handled; return Plugin_Handled;
} }
@ -217,30 +228,32 @@ public Action:Command_Unrestrict(client, argc)
// Strip "weapon_" from entity name // Strip "weapon_" from entity name
ReplaceString(arg1, sizeof(arg1), "weapon_", ""); ReplaceString(arg1, sizeof(arg1), "weapon_", "");
new WpnRestrictQuery:output = WeaponRestrictUnrestrict(arg1); decl String:display[WEAPONS_MAX_LENGTH];
new WpnRestrictQuery:output = RestrictUnrestrict(arg1, display);
switch(output) switch(output)
{ {
case Successful_Weapon: case Successful_Weapon:
{ {
ZR_PrintToChat(0, "Unrestrict weapon", arg1); ZR_PrintToChat(0, "Unrestrict weapon", display);
} }
case Successful_Group: case Successful_Group:
{ {
decl String:weaponlist[128]; 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: case Failed_Weapon:
{ {
ZR_ReplyToCommand(client, "Unrestrict weapon failed", arg1); ZR_ReplyToCommand(client, "Unrestrict weapon failed", display);
return Plugin_Handled; return Plugin_Handled;
} }
case Invalid: case Invalid:
{ {
ZR_ReplyToCommand(client, "Weapon invalid", arg1); ZR_ReplyToCommand(client, "Weapon invalid", display);
return Plugin_Handled; return Plugin_Handled;
} }

View File

@ -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. * Check if a log message should be written depending on log flags. If module
LogFlagCheck(flag, module = 0) * 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; return 1;
} }
@ -267,6 +274,6 @@ LogFlagCheck(flag, module = 0)
} }
else else
{ {
return LogHasFlag(flag); return LogHasFlag(logtype);
} }
} }

View File

@ -49,7 +49,7 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
ReplaceString(weapon, sizeof(weapon), "weapon_", ""); ReplaceString(weapon, sizeof(weapon), "weapon_", "");
// If the weapon is restricted, then stop // If the weapon is restricted, then stop
if (WeaponRestrictIsRestricted(weapon)) if (RestrictIsWeaponRestricted(weapon))
{ {
ZR_PrintToChat(client, "Weapon is restricted", weapon); ZR_PrintToChat(client, "Weapon is restricted", weapon);

View File

@ -11,10 +11,8 @@
*/ */
enum WeaponsMenu enum WeaponsMenu
{ {
Restrict_Weapon, Weapon,
Unrestrict_Weapon, WeaponGroup,
Restrict_Group,
Unrestrict_Group,
} }
/** /**
@ -35,22 +33,17 @@ WeaponsMenuMain(client)
SetMenuTitle(menu_weapons_main, "%t\n ", "Weapons menu main title"); SetMenuTitle(menu_weapons_main, "%t\n ", "Weapons menu main title");
decl String:restrictweapon[64]; decl String:toggleweaponrestriction[64];
decl String:unrestrictweapon[64]; decl String:togglewgrouprestriction[64];
decl String:restrictwgroup[64];
decl String:unrestrictwgroup[64];
decl String:zmarket[64]; decl String:zmarket[64];
Format(restrictweapon, sizeof(restrictweapon), "%t", "Weapons menu main restrict weapon"); Format(toggleweaponrestriction, sizeof(toggleweaponrestriction), "%t", "Weapons menu main toggle weapon restrict");
Format(unrestrictweapon, sizeof(unrestrictweapon), "%t", "Weapons menu main unrestrict weapon"); Format(togglewgrouprestriction, sizeof(togglewgrouprestriction), "%t", "Weapons menu main toggle weapon group restrict");
Format(restrictwgroup, sizeof(restrictwgroup), "%t", "Weapons menu main restrict weapon group");
Format(unrestrictwgroup, sizeof(unrestrictwgroup), "%t", "Weapons menu main unrestrict weapon group");
Format(zmarket, sizeof(zmarket), "%t", "Weapons menu main market"); Format(zmarket, sizeof(zmarket), "%t", "Weapons menu main market");
AddMenuItem(menu_weapons_main, "restrictweapon", restrictweapon); AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction);
AddMenuItem(menu_weapons_main, "unrestrictweapon", unrestrictweapon); AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction);
AddMenuItem(menu_weapons_main, "restrictwgroup", restrictwgroup);
AddMenuItem(menu_weapons_main, "unrestrictwgroup", unrestrictwgroup);
// Disable market option if market isn't installed // Disable market option if market isn't installed
if (market) if (market)
@ -85,21 +78,13 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
{ {
case 0: case 0:
{ {
WeaponsMenuWeapons(client, Restrict_Weapon); WeaponsMenuWeapons(client, Weapon);
} }
case 1: case 1:
{ {
WeaponsMenuWeapons(client, Unrestrict_Weapon); WeaponsMenuWeapons(client, WeaponGroup);
} }
case 2: case 2:
{
WeaponsMenuWeapons(client, Restrict_Group);
}
case 3:
{
WeaponsMenuWeapons(client, Unrestrict_Group);
}
case 4:
{ {
// WeaponsMenuMarket(client); // WeaponsMenuMarket(client);
} }
@ -138,7 +123,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
SetMenuTitle(menu_weapons_weapons, "%t\n ", "Weapons menu weapons title"); 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 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]; decl String:weapon[WEAPONS_MAX_LENGTH];
new Handle:arrayWeapons = INVALID_HANDLE; new Handle:arrayWeapons = INVALID_HANDLE;
@ -151,6 +136,11 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
new bool:menu = WeaponsIsWeaponMenu(weapon); 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 weapon restriction is blocked for the menu, disable option
if (menu) if (menu)
{ {
@ -166,17 +156,22 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
CloseHandle(arrayWeapons); CloseHandle(arrayWeapons);
} }
// If client wants to perform an action on a weapon group, show custom group list // 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]; decl String:weapongroup[WEAPONS_MAX_LENGTH];
new Handle:arrayWeaponGroups = INVALID_HANDLE; new Handle:arrayWeaponGroups = INVALID_HANDLE;
new size = WeaponsCreateWeaponGroupArray(arrayWeaponGroups); new size = RestrictCreateGroupArray(arrayWeaponGroups);
// x = Array index // x = Array index
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
{ {
GetArrayString(arrayWeaponGroups, x, weapongroup, sizeof(weapongroup)); GetArrayString(arrayWeaponGroups, x, weapongroup, sizeof(weapongroup));
if (RestrictIsWeaponRestricted(weapongroup))
{
Format(weapongroup, sizeof(weapongroup), "%s*", weapongroup);
}
AddMenuItem(menu_weapons_weapons, weapongroup, weapongroup); AddMenuItem(menu_weapons_weapons, weapongroup, weapongroup);
} }
@ -206,59 +201,79 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
new WpnRestrictQuery:output; new WpnRestrictQuery:output;
// If client is restricting a weapon or group, then call the restrict function // Set restrict to true if were restricting a weapon/group, false if not
if (curMenuWeapons[client] == Restrict_Weapon || curMenuWeapons[client] == Restrict_Group) 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) switch(output)
{ {
case Successful_Weapon: case Successful_Weapon:
{ {
ZR_PrintToChat(0, "Restrict weapon", weapon); ZR_PrintToChat(0, "Restrict weapon", display);
} }
case Successful_Group: case Successful_Group:
{ {
decl String:weaponlist[128]; 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: 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: 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
else if (curMenuWeapons[client] == Unrestrict_Weapon || curMenuWeapons[client] == Unrestrict_Group)
{ {
output = WeaponRestrictUnrestrict(weapon); decl String:display[WEAPONS_MAX_LENGTH];
output = RestrictUnrestrict(weapon, display);
switch(output) switch(output)
{ {
case Successful_Weapon: case Successful_Weapon:
{ {
ZR_PrintToChat(0, "Unrestrict weapon", weapon); ZR_PrintToChat(0, "Unrestrict weapon", display);
} }
case Successful_Group: case Successful_Group:
{ {
decl String:weaponlist[128]; 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: case Failed_Weapon:
{ {
ZR_PrintToChat(client, "Unrestrict weapon failed", weapon); ZR_PrintToChat(client, "Unrestrict weapon failed", display);
} }
case Invalid: case Invalid:
{ {
ZR_PrintToChat(client, "Weapon invalid", weapon); ZR_PrintToChat(client, "Weapon invalid", display);
} }
} }
} }

View File

@ -36,19 +36,19 @@ enum WpnRestrictQuery
/** /**
* Initialize data and hook commands. * Initialize data and hook commands.
*/ */
WeaponRestrictInit() RestrictInit()
{ {
// Initialize weapon restrict array // Initialize weapon restrict array
gRestrictedWeapons = CreateArray(32, 0); gRestrictedWeapons = CreateArray(32, 0);
// Hook buy command // Hook buy command
RegConsoleCmd("buy", WeaponRestrictBuyHook); RegConsoleCmd("buy", RestrictBuyHook);
} }
/** /**
* Loads weapon data from file. * Loads weapon data from file.
*/ */
WeaponRestrictOnMapStart() RestrictOnMapStart()
{ {
// Clear restricted weapons // Clear restricted weapons
RestrictWeaponUnrestrictAll(); RestrictWeaponUnrestrictAll();
@ -70,6 +70,11 @@ WeaponRestrictOnMapStart()
SetFailState("\"%s\" missing from server", path); SetFailState("\"%s\" missing from server", path);
} }
RestrictValidateWeaponGroups();
}
RestrictValidateWeaponGroups()
{
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
@ -78,7 +83,7 @@ WeaponRestrictOnMapStart()
{ {
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
decl String:groupweapon[32]; decl String:groupweapon[WEAPONS_MAX_LENGTH];
do do
{ {
@ -87,7 +92,7 @@ WeaponRestrictOnMapStart()
if (!WeaponsIsValidWeapon(groupweapon)) if (!WeaponsIsValidWeapon(groupweapon))
{ {
// TODO: LOG INVALID WEAPON // VALIDATE
} }
} while (KvGotoNextKey(kvWeaponGroups)); } while (KvGotoNextKey(kvWeaponGroups));
@ -110,9 +115,9 @@ RestrictWeaponUnrestrictAll()
* *
* @param client The client index. * @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. * @param client The client index.
*/ */
WeaponRestrictClientDisconnect(client) RestrictOnClientDisconnect(client)
{ {
Hacks_Unhook(gCanUseHookID[client]); Hacks_Unhook(gCanUseHookID[client]);
} }
@ -132,7 +137,7 @@ WeaponRestrictClientDisconnect(client)
* @param client The client index. * @param client The client index.
* @param argc Argument count. * @param argc Argument count.
*/ */
public Action:WeaponRestrictBuyHook(client, argc) public Action:RestrictBuyHook(client, argc)
{ {
// If plugin is disabled then stop // If plugin is disabled then stop
new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]);
@ -157,7 +162,7 @@ public Action:WeaponRestrictBuyHook(client, argc)
ReplaceString(weapon, sizeof(weapon), "weapon_", ""); ReplaceString(weapon, sizeof(weapon), "weapon_", "");
// Check if the weapon is restricted, if so then block command // Check if the weapon is restricted, if so then block command
if (WeaponRestrictIsRestricted(weapon)) if (RestrictIsWeaponRestricted(weapon))
{ {
ZR_PrintToChat(client, "Weapon is restricted", 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. * Failed_Group: The call failed to restrict 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[]) WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[])
{ {
if (WeaponRestrictIsCustomGroup(weapon)) if (RestrictIsWeaponGroup(weapon))
{ {
KvRewind(kvWeaponGroups); if (RestrictIsGroupRestricted(weapon))
KvJumpToKey(kvWeaponGroups, weapon);
if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
decl String:groupweapon[32]; return Failed_Group;
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 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); KvRewind(kvWeaponGroups);
KvJumpToKey(kvWeaponGroups, weapon); KvJumpToKey(kvWeaponGroups, weapon);
KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH);
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
decl String:groupweapon[WEAPONS_MAX_LENGTH]; decl String:groupweapon[WEAPONS_MAX_LENGTH];
@ -257,9 +212,69 @@ WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[])
continue; 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) if (weaponindex > -1)
{ {
RemoveFromArray(gRestrictedWeapons, weaponindex); RemoveFromArray(gRestrictedWeapons, weaponindex);
@ -276,12 +291,14 @@ WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[])
return Invalid; return Invalid;
} }
if (!WeaponRestrictIsRestricted(weapon)) if (!RestrictIsWeaponRestricted(weapon))
{ {
return Failed_Weapon; return Failed_Weapon;
} }
new weaponindex = WeaponRestrictGetIndex(weapon); WeaponGetDisplayName(weapon, display);
new weaponindex = RestrictGetIndex(display);
if (weaponindex > -1) if (weaponindex > -1)
{ {
RemoveFromArray(gRestrictedWeapons, weaponindex); RemoveFromArray(gRestrictedWeapons, weaponindex);
@ -295,7 +312,7 @@ WpnRestrictQuery:WeaponRestrictUnrestrict(const String:weapon[])
* *
* @param weapon The weapon name. * @param weapon The weapon name.
*/ */
bool:WeaponRestrictIsRestricted(const String:weapon[]) bool:RestrictIsWeaponRestricted(const String:weapon[])
{ {
new size = GetArraySize(gRestrictedWeapons); new size = GetArraySize(gRestrictedWeapons);
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
@ -312,12 +329,40 @@ bool:WeaponRestrictIsRestricted(const String:weapon[])
return false; 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. * Returns the array index of the restricted weapon.
* *
* @param weapon The weapon name. * @param weapon The weapon name.
*/ */
WeaponRestrictGetIndex(const String:weapon[]) RestrictGetIndex(const String:weapon[])
{ {
new size = GetArraySize(gRestrictedWeapons); new size = GetArraySize(gRestrictedWeapons);
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
@ -340,7 +385,7 @@ WeaponRestrictGetIndex(const String:weapon[])
* @param groupname Name of the group to check. * @param groupname Name of the group to check.
* @return True if it's a group, false if not. * @return True if it's a group, false if not.
*/ */
bool:WeaponRestrictIsCustomGroup(const String:groupname[]) bool:RestrictIsWeaponGroup(const String:groupname[])
{ {
// Reset the traversal stack // Reset the traversal stack
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
@ -349,6 +394,34 @@ bool:WeaponRestrictIsCustomGroup(const String:groupname[])
return KvJumpToKey(kvWeaponGroups, 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 * Returns a string of all weapons in a custom weapon group separated
* by the provided character. * 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 maxlen Maximum length of the weapon list, the rest is truncated.
* @param separator Separator character between weapon names. * @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); KvRewind(kvWeaponGroups);
KvJumpToKey(kvWeaponGroups, groupname); KvJumpToKey(kvWeaponGroups, groupname);
@ -397,7 +470,7 @@ WeaponRestrictGetWeaponList(const String:groupname[], String:weaponlist[], maxle
* @param weapon The weapon index. * @param weapon The weapon index.
* @return 0 to block weapon pickup, Hacks_Continue to allow. * @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 // If plugin is disabled then stop
new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]);
@ -413,7 +486,7 @@ public WeaponRestrictCanUse(client, weapon, dummy1, dummy2, dummy3, dummy4)
ReplaceString(weaponname, sizeof(weaponname), "weapon_", ""); ReplaceString(weaponname, sizeof(weaponname), "weapon_", "");
// If the weapon is restricted then prevent pickup // If the weapon is restricted then prevent pickup
if (WeaponRestrictIsRestricted(weaponname)) if (RestrictIsWeaponRestricted(weaponname))
{ {
return 0; return 0;
} }

View File

@ -6,21 +6,11 @@
* ==================== * ====================
*/ */
/**
* Handle to store trie weapon data
*/
new Handle:trieWeapons = INVALID_HANDLE;
/** /**
* Maximum length of a weapon name string * Maximum length of a weapon name string
*/ */
#define WEAPONS_MAX_LENGTH 32 #define WEAPONS_MAX_LENGTH 32
/**
* @section Config array indexes.
*/
#define WEAPON_RESTRICT 0
#define WEAPON_MENU 1
/** /**
* @endsection * @endsection
*/ */
@ -34,20 +24,17 @@ new Handle:kvWeapons = INVALID_HANDLE;
#include "zr/weapons/markethandler" #include "zr/weapons/markethandler"
#include "zr/weapons/menu_weapons" #include "zr/weapons/menu_weapons"
WeaponsInit()
{
// Forward event to sub-module
RestrictInit();
}
/** /**
* Loads weapon data from file. * Loads weapon data from file.
*/ */
WeaponsOnMapStart() WeaponsOnMapStart()
{ {
// Destroy trie data if populated
if (trieWeapons != INVALID_HANDLE)
{
CloseHandle(trieWeapons);
}
// Create trie to store weapon data
trieWeapons = CreateTrie();
// Load weapon data // Load weapon data
if (kvWeapons != INVALID_HANDLE) if (kvWeapons != INVALID_HANDLE)
{ {
@ -65,6 +52,15 @@ WeaponsOnMapStart()
SetFailState("\"%s\" missing from server", path); SetFailState("\"%s\" missing from server", path);
} }
// Validate weapons config
WeaponsValidateWeaponsConfig();
// Forward event to sub-module
RestrictOnMapStart();
}
WeaponsValidateWeaponsConfig()
{
KvRewind(kvWeapons); KvRewind(kvWeapons);
if (KvGotoFirstSubKey(kvWeapons)) if (KvGotoFirstSubKey(kvWeapons))
{ {
@ -78,17 +74,22 @@ WeaponsOnMapStart()
KvGetString(kvWeapons, "restrict", restrict, sizeof(restrict), "no"); KvGetString(kvWeapons, "restrict", restrict, sizeof(restrict), "no");
KvGetString(kvWeapons, "menu", menu, sizeof(menu), "yes"); KvGetString(kvWeapons, "menu", menu, sizeof(menu), "yes");
new bool:config[2]; // VALIDATE
config[WEAPON_RESTRICT] = ConfigOptionToBool(restrict);
config[WEAPON_MENU] = ConfigOptionToBool(menu);
SetTrieArray(trieWeapons, weapon, config, sizeof(config), false);
} while (KvGotoNextKey(kvWeapons)); } while (KvGotoNextKey(kvWeapons));
} }
}
// Weapon restrict WeaponsClientInit(client)
WeaponRestrictOnMapStart(); {
// 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; 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) * Checks if a weapon is valid (aka listed in weapons.txt)
* @param weapon The weapon name. * @param weapon The weapon name.
@ -154,9 +127,49 @@ WeaponsCreateWeaponGroupArray(&Handle:arrayWeaponGroups, maxlen = WEAPONS_MAX_LE
*/ */
bool:WeaponsIsValidWeapon(const String:weapon[]) bool:WeaponsIsValidWeapon(const String:weapon[])
{ {
new bool:config[2]; KvRewind(kvWeapons);
if (KvGotoFirstSubKey(kvWeapons))
{
decl String:validweapon[WEAPONS_MAX_LENGTH];
return GetTrieArray(trieWeapons, weapon, config, sizeof(config)); do
{
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
if (StrEqual(validweapon, weapon, false))
{
return true;
}
} while (KvGotoNextKey(kvWeapons));
}
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. * @param weapon The weapon name.
* @return Returns true if restricted, false it not. * @return Returns true if restricted, false it not.
*/ */
bool:WeaponsIsWeaponRestrict(const String:weapon[]) bool:WeaponsIsRestrict(const String:weapon[])
{ {
new bool:config[2]; KvRewind(kvWeapons);
GetTrieArray(trieWeapons, weapon, config, sizeof(config)); if (KvGotoFirstSubKey(kvWeapons))
{
decl String:validweapon[WEAPONS_MAX_LENGTH];
decl String:restrict[8];
return config[WEAPON_RESTRICT]; 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 false;
} }
/** /**
@ -179,8 +208,24 @@ bool:WeaponsIsWeaponRestrict(const String:weapon[])
*/ */
bool:WeaponsIsWeaponMenu(const String:weapon[]) bool:WeaponsIsWeaponMenu(const String:weapon[])
{ {
new bool:config[2]; KvRewind(kvWeapons);
GetTrieArray(trieWeapons, weapon, config, sizeof(config)); if (KvGotoFirstSubKey(kvWeapons))
{
decl String:validweapon[WEAPONS_MAX_LENGTH];
decl String:menu[8];
return config[WEAPON_MENU]; 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 false;
} }

View File

@ -33,27 +33,35 @@ enum ZTeam
#define DXLEVEL_MIN 90 #define DXLEVEL_MIN 90
#define DEFAULT_FOV 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. * @section Logging flags.
#define LOG_PLAYER_COMMANDS 4 // Commands executed by non-admins: zspawn, teleport, class change. */
#define LOG_DEBUG 8 // Debug messages. #define LOG_CORE_EVENTS 1 /** Executing config files, error messages, etc. */
#define LOG_DEBUG_DETAIL 16 // Debug messages with more detail. May cause spam. #define LOG_GAME_EVENTS 2 /** Admin commands, suicide prevention, anticamp kills. */
#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_PLAYER_COMMANDS 4 /** Commands executed by non-admins: zspawn, teleport, class change. */
#define LOG_TO_ADMINS 64 // Write all kinds of log messages to admin chat. #define LOG_DEBUG 8 /** Debug messages. */
#define LOG_TO_CLIENT 128 // Write all log messages related to a player, to the players console. #define LOG_DEBUG_DETAIL 16 /** Debug messages with more detail. May cause spam. */
#define LOG_IGNORE_CONSOLE 256 // Don't log messages from client 0 (console). #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_MODULES_ENABLED 512 // Enable detailed log control for developers. Module logs overrides previous flags. #define LOG_TO_ADMINS 64 /** Copy kinds of log events to admin chat. */
#define LOG_MODULE_ZOMBIE 1024 // zombie.inc #define LOG_TO_CLIENT 128 /** Copy all log events related to a player, to the players console. */
#define LOG_MODULE_AMBIENCE 2048 // ambience.inc #define LOG_IGNORE_CONSOLE 256 /** Don't log messages from the console (client 0). */
#define LOG_MODULE_OVERLAYS 4096 // overlays.inc #define LOG_MODULES_ENABLED 512 /** Enable module based log control. Module logs overrides previous flags, including debug flags. */
#define LOG_MODULE_SAYTRIGGERS 8192 // sayhooks.inc #define LOG_MODULE_CORE 1024 /** The core of the plugin (startup, loading configs, etc.). Not really a module. */
#define LOG_MODULE_TELEPORT 16384 // teleport.inc #define LOG_MODULE_COMMANDS 2048 /** commands.inc */
#define LOG_MODULE_CLASSES 32768 // playerclasses/* #define LOG_MODULE_CLASSES 4096 /** Class system - playerclasses/*.inc */
#define LOG_MODULE_WEAPONRESTICT 65536 // weaponrestrict.inc #define LOG_MODULE_ZOMBIE 8192 /** zombie.inc */
#define LOG_MODULE_COMMANDS 131072 // commands.inc #define LOG_MODULE_SAYTRIGGERS 16384 /** sayhooks.inc */
#define LOG_MODULE_ANTICAMP 262144 // anticamp.inc #define LOG_MODULE_AMBIENCE 32768 /** ambience.inc */
#define LOG_MODULE_DAMAGECONTROL 524288 // damagecontrol.inc #define LOG_MODULE_OVERLAYS 65536 /** overlays.inc */
#define LOG_MODULE_OFFSETS 1048576 // offsets.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 bool:market;
new dxLevel[MAXPLAYERS + 1]; new dxLevel[MAXPLAYERS + 1];