Cleaned comments up, added more comments.

This commit is contained in:
Greyscale 2009-04-15 09:42:12 +02:00
parent acf5dd4ecd
commit 8d9d45790b
7 changed files with 201 additions and 110 deletions

View File

@ -17,7 +17,7 @@
*/ */
/** /**
* Handle to keep track of AntiStickTimer * Handle to keep track of AntiStickTimer.
*/ */
new Handle:tAntiStick = INVALID_HANDLE; new Handle:tAntiStick = INVALID_HANDLE;
@ -48,7 +48,7 @@ AntiStickReset()
} }
/** /**
* Checks if a player is currently stuck within another player * Checks if a player is currently stuck within another player.
* *
* @param client The client index. * @param client The client index.
* @return The client index of the other stuck player, -1 when * @return The client index of the other stuck player, -1 when
@ -61,11 +61,11 @@ AntiStickIsStuck(client)
GetClientAbsOrigin(client, clientloc); GetClientAbsOrigin(client, clientloc);
// x = client index // x = client index.
new maxplayers = GetMaxClients(); new maxplayers = GetMaxClients();
for (new x = 1; x <= maxplayers; x++) for (new x = 1; x <= maxplayers; x++)
{ {
// Validate player is in-game, alive, and isn't the player being checked ('client') // Validate player is in-game, alive, and isn't the player being checked. ('client')
if (!IsClientInGame(x) || !IsPlayerAlive(x) || x == client) if (!IsClientInGame(x) || !IsPlayerAlive(x) || x == client)
{ {
continue; continue;
@ -82,7 +82,7 @@ AntiStickIsStuck(client)
new Float:eyeloc[3]; new Float:eyeloc[3];
GetPlayerEyePosition(client, eyeloc); GetPlayerEyePosition(client, eyeloc);
// Get the distance between the eyes and feet and subtract the stack "view crush" // Get the distance between the eyes and feet and subtract the stack "view crush."
new Float:eyedistance = FloatAbs(eyeloc[2] - clientloc[2]) - PLAYER_HULL_STACK_OFFSET; new Float:eyedistance = FloatAbs(eyeloc[2] - clientloc[2]) - PLAYER_HULL_STACK_OFFSET;
new Float:zdistance = FloatAbs(stuckloc[2] - clientloc[2]); new Float:zdistance = FloatAbs(stuckloc[2] - clientloc[2]);
@ -107,13 +107,13 @@ public Action:AntiStickTimer(Handle:timer)
new maxplayers = GetMaxClients(); new maxplayers = GetMaxClients();
for (new x = 1; x <= maxplayers; x++) for (new x = 1; x <= maxplayers; x++)
{ {
// Validate player is in-game and alive // Validate player is in-game and alive.
if (!IsClientInGame(x) || !IsPlayerAlive(x)) if (!IsClientInGame(x) || !IsPlayerAlive(x))
{ {
continue; continue;
} }
// Stop if the player isn't stuck // Stop if the player isn't stuck.
new stuckindex = AntiStickIsStuck(x); new stuckindex = AntiStickIsStuck(x);
if (stuckindex == -1) if (stuckindex == -1)
{ {
@ -138,17 +138,18 @@ public Action:AntiStickTimer(Handle:timer)
* Repeated timer function. * Repeated timer function.
* Re-solidifies a player being unstuck. * Re-solidifies a player being unstuck.
* *
* @param timer The timer handle.
* @param index The client index. * @param index The client index.
*/ */
public Action:AntiStickSolidify(Handle:timer, any:index) public Action:AntiStickSolidify(Handle:timer, any:index)
{ {
// Validate player is in-game, alive, and is being unstuck // Validate player is in-game, alive, and is being unstuck.
if (!IsClientInGame(index) || !IsPlayerAlive(index) || CanCollide(index)) if (!IsClientInGame(index) || !IsPlayerAlive(index) || CanCollide(index))
{ {
return Plugin_Stop; return Plugin_Stop;
} }
// Stop if the player is still stuck // Stop if the player is still stuck.
if (AntiStickIsStuck(index) > -1) if (AntiStickIsStuck(index) > -1)
{ {
return Plugin_Continue; return Plugin_Continue;

View File

@ -31,9 +31,12 @@ new Handle:kvHitgroups = INVALID_HANDLE;
* @endsection * @endsection
*/ */
/**
* Clears hitgroup data.
*/
HitgroupsClearData() HitgroupsClearData()
{ {
// Load hitgroup data // Load hitgroup data.
if (kvHitgroups != INVALID_HANDLE) if (kvHitgroups != INVALID_HANDLE)
{ {
CloseHandle(kvHitgroups); CloseHandle(kvHitgroups);
@ -42,6 +45,9 @@ HitgroupsClearData()
kvHitgroups = CreateKeyValues("hitgroups"); kvHitgroups = CreateKeyValues("hitgroups");
} }
/**
* Loads hitgroup data from file.
*/
HitgroupsLoad() HitgroupsLoad()
{ {
// Clear hitgroup data // Clear hitgroup data
@ -50,7 +56,7 @@ HitgroupsLoad()
decl String:path[PLATFORM_MAX_PATH]; decl String:path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "configs/zr/hitgroups.txt"); BuildPath(Path_SM, path, sizeof(path), "configs/zr/hitgroups.txt");
// If file isn't found, stop plugin // If file isn't found, stop plugin.
if (!FileToKeyValues(kvHitgroups, path)) if (!FileToKeyValues(kvHitgroups, path))
{ {
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS)) if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS))
@ -61,13 +67,16 @@ HitgroupsLoad()
return; return;
} }
// Validate hitgroups config // Validate hitgroups config.
HitgroupsValidateConfig(); HitgroupsValidateConfig();
} }
/**
* Validate hitgroup config file and settings.
*/
HitgroupsValidateConfig() HitgroupsValidateConfig()
{ {
// If log flag check fails, don't log // If log flag check fails, don't log.
if (!LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS)) if (!LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS))
{ {
return; return;
@ -80,6 +89,11 @@ HitgroupsValidateConfig()
} }
} }
/**
* Retrieve hitgroup knockback value.
*
* @param hitgroup The hitgroup index.
*/
Float:HitgroupsGetHitgroupKnockback(hitgroup) Float:HitgroupsGetHitgroupKnockback(hitgroup)
{ {
// Reset keyvalue's traversal stack. // Reset keyvalue's traversal stack.

View File

@ -6,7 +6,8 @@
* ==================== * ====================
*/ */
/** Player hurt event /** Player hurt event.
*
* @param client The victim index. (zombie) * @param client The victim index. (zombie)
* @param attacker The attacker index. (human) * @param attacker The attacker index. (human)
* @param weapon The weapon used. * @param weapon The weapon used.
@ -59,7 +60,7 @@ KnockbackPlayerHurt(client, attacker, const String:weapon[], hitgroup, dmg_healt
// Retrieve hitgroup knockback boost. // Retrieve hitgroup knockback boost.
new Float:boostHitgroup = HitgroupsGetHitgroupKnockback(hitgroup); new Float:boostHitgroup = HitgroupsGetHitgroupKnockback(hitgroup);
// Apply all knockback multipliers // Apply all knockback multipliers.
knockback *= float(dmg_health) * boostWeapon * boostHitgroup; knockback *= float(dmg_health) * boostWeapon * boostHitgroup;
// Apply knockback. // Apply knockback.
@ -70,6 +71,7 @@ KnockbackPlayerHurt(client, attacker, const String:weapon[], hitgroup, dmg_healt
/** /**
* Sets velocity on a player. * Sets velocity on a player.
*
* @param client The client index. * @param client The client index.
* @param startpoint The starting coordinate to push from. * @param startpoint The starting coordinate to push from.
* @param endpoint The ending coordinate to push towards. * @param endpoint The ending coordinate to push towards.
@ -93,6 +95,7 @@ KnockbackSetVelocity(client, const Float:startpoint[3], const Float:endpoint[3],
/** /**
* Trace Ray forward, used as a filter to continue tracing if told so. (See sdktools_trace.inc) * Trace Ray forward, used as a filter to continue tracing if told so. (See sdktools_trace.inc)
*
* @param entity The entity index. * @param entity The entity index.
* @param contentsMask The contents mask. * @param contentsMask The contents mask.
* @return True to allow hit, false to continue tracing. * @return True to allow hit, false to continue tracing.
@ -111,6 +114,7 @@ public bool:KnockbackTRFilter(entity, contentsMask)
/** /**
* Find the location of an exploding grenade (currently inflicting damage in player_hurt). * Find the location of an exploding grenade (currently inflicting damage in player_hurt).
*
* @param heLoc The location of the exploding grenade. * @param heLoc The location of the exploding grenade.
* @return The entity index of the grenade. * @return The entity index of the grenade.
*/ */

View File

@ -15,13 +15,13 @@
*/ */
public bool:Market_OnWeaponSelected(client, String:weaponid[]) public bool:Market_OnWeaponSelected(client, String:weaponid[])
{ {
// If player is dead or weaponid is invalid, then stop // If player is dead or weaponid is invalid, then stop.
if (!weaponid[0] || !IsPlayerAlive(client)) if (!weaponid[0] || !IsPlayerAlive(client))
{ {
return false; return false;
} }
// If player is a zombie, then stop // If player is a zombie, then stop.
if (IsPlayerZombie(client)) if (IsPlayerZombie(client))
{ {
ZR_PrintToChat(client, "Zombie cant use weapon"); ZR_PrintToChat(client, "Zombie cant use weapon");
@ -29,7 +29,7 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
return false; return false;
} }
// If player is using the rebuy option then allow // If player is using the rebuy option then allow.
if (StrEqual(weaponid, "rebuy")) if (StrEqual(weaponid, "rebuy"))
{ {
return true; return true;
@ -39,16 +39,16 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
decl String:weapon[WEAPONS_MAX_LENGTH]; decl String:weapon[WEAPONS_MAX_LENGTH];
new price; new price;
// If the market plugin can't find info about the weapon, then stop // If the market plugin can't find info about the weapon, then stop.
if (!Market_GetWeaponIDInfo(weaponid, display, weapon, price)) if (!Market_GetWeaponIDInfo(weaponid, display, weapon, price))
{ {
return false; return false;
} }
// Strip "weapon_" from entity name // Strip "weapon_" from entity name.
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 (RestrictIsWeaponRestricted(weapon)) if (RestrictIsWeaponRestricted(weapon))
{ {
ZR_PrintToChat(client, "Weapon is restricted", weapon); ZR_PrintToChat(client, "Weapon is restricted", weapon);
@ -56,7 +56,7 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
return false; return false;
} }
// Check if buyzone cvar is enabled, and if the client is in a buyzone // Check if buyzone cvar is enabled, and if the client is in a buyzone.
new bool:buyzone = GetConVarBool(gCvars[CVAR_ZMARKET_BUYZONE]); new bool:buyzone = GetConVarBool(gCvars[CVAR_ZMARKET_BUYZONE]);
if (!IsClientInBuyZone(client) && buyzone) if (!IsClientInBuyZone(client) && buyzone)
{ {
@ -76,12 +76,12 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
*/ */
public Market_PostOnWeaponSelected(client, &bool:allowed) public Market_PostOnWeaponSelected(client, &bool:allowed)
{ {
// If the purchase wasn't allowed, then stop // If the purchase wasn't allowed, then stop.
if (!allowed) if (!allowed)
{ {
return; return;
} }
// Resend market menu // Resend market menu.
ZMarket(client); ZMarket(client);
} }

View File

@ -16,12 +16,12 @@ enum WeaponsMenu
} }
/** /**
* Array to store the client's current weapon menu * Array to store the client's current weapon menu.
*/ */
new WeaponsMenu:curMenuWeapons[MAXPLAYERS + 1]; new WeaponsMenu:curMenuWeapons[MAXPLAYERS + 1];
/** /**
* Array to store the client's current weapon group menu * Array to store the client's current weapon group menu.
*/ */
new String:curMenuGroup[WEAPONS_MAX_LENGTH][MAXPLAYERS + 1]; new String:curMenuGroup[WEAPONS_MAX_LENGTH][MAXPLAYERS + 1];
@ -31,7 +31,7 @@ new String:curMenuGroup[WEAPONS_MAX_LENGTH][MAXPLAYERS + 1];
*/ */
WeaponsMenuMain(client) WeaponsMenuMain(client)
{ {
// Create menu handle // Create menu handle.
new Handle:menu_weapons_main = CreateMenu(WeaponsMenuMainHandle); new Handle:menu_weapons_main = CreateMenu(WeaponsMenuMainHandle);
SetGlobalTransTarget(client); SetGlobalTransTarget(client);
@ -49,7 +49,7 @@ WeaponsMenuMain(client)
AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction); AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction);
AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction); AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction);
// Disable market option if market isn't installed // Disable market option if market isn't installed.
if (market) if (market)
{ {
AddMenuItem(menu_weapons_main, "zmarket", zmarket); AddMenuItem(menu_weapons_main, "zmarket", zmarket);
@ -59,10 +59,10 @@ WeaponsMenuMain(client)
AddMenuItem(menu_weapons_main, "zmarket", zmarket, ITEMDRAW_DISABLED); AddMenuItem(menu_weapons_main, "zmarket", zmarket, ITEMDRAW_DISABLED);
} }
// Create a "Back" button to the weapons main menu // Create a "Back" button to the weapons main menu.
SetMenuExitBackButton(menu_weapons_main, true); SetMenuExitBackButton(menu_weapons_main, true);
// Send menu // Send menu.
DisplayMenu(menu_weapons_main, client, MENU_TIME_FOREVER); DisplayMenu(menu_weapons_main, client, MENU_TIME_FOREVER);
} }
@ -75,7 +75,7 @@ WeaponsMenuMain(client)
*/ */
public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client, slot) public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client, slot)
{ {
// Client selected an option // Client selected an option.
if (action == MenuAction_Select) if (action == MenuAction_Select)
{ {
switch(slot) switch(slot)
@ -94,16 +94,16 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
} }
} }
} }
// Client closed the menu // Client closed the menu.
if (action == MenuAction_Cancel) if (action == MenuAction_Cancel)
{ {
// Client hit "Back" button // Client hit "Back" button.
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
ZRAdminMenu(client); ZRAdminMenu(client);
} }
} }
// Client hit "Exit" button // Client hit "Exit" button.
else if (action == MenuAction_End) else if (action == MenuAction_End)
{ {
CloseHandle(menu_weapons_main); CloseHandle(menu_weapons_main);
@ -116,15 +116,15 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
*/ */
WeaponsMenuWeapons(client, WeaponsMenu:type) WeaponsMenuWeapons(client, WeaponsMenu:type)
{ {
// Set the current action client is performing on a weapon (see enum WeaponsMenu) // Set the current action client is performing on a weapon. (see enum WeaponsMenu)
curMenuWeapons[client] = type; curMenuWeapons[client] = type;
// Create menu handle // Create menu handle.
new Handle:menu_weapons_weapons = CreateMenu(WeaponsMenuWeaponsHandle); new Handle:menu_weapons_weapons = CreateMenu(WeaponsMenuWeaponsHandle);
SetGlobalTransTarget(client); SetGlobalTransTarget(client);
// 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.
switch(curMenuWeapons[client]) switch(curMenuWeapons[client])
{ {
case Weapon: case Weapon:
@ -136,7 +136,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
new Handle:arrayWeapons = INVALID_HANDLE; new Handle:arrayWeapons = INVALID_HANDLE;
new size = WeaponsCreateWeaponArray(arrayWeapons); new size = WeaponsCreateWeaponArray(arrayWeapons);
// x = Array index // x = Array index.
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
{ {
GetArrayString(arrayWeapons, x, weapon, sizeof(weapon)); GetArrayString(arrayWeapons, x, weapon, sizeof(weapon));
@ -148,7 +148,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
Format(display, sizeof(display), "%s*", weapon); Format(display, sizeof(display), "%s*", weapon);
} }
// If weapon restriction is blocked for the menu, disable option // If weapon restriction is blocked for the menu, disable option.
new bool:menu = WeaponsIsWeaponMenu(weapon); new bool:menu = WeaponsIsWeaponMenu(weapon);
if (menu) if (menu)
@ -161,7 +161,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
} }
} }
// If there are no weapons, add an "(Empty)" line // If there are no weapons, add an "(Empty)" line.
if (size == 0) if (size == 0)
{ {
decl String:empty[64]; decl String:empty[64];
@ -170,10 +170,10 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
AddMenuItem(menu_weapons_weapons, "empty", empty, ITEMDRAW_DISABLED); AddMenuItem(menu_weapons_weapons, "empty", empty, ITEMDRAW_DISABLED);
} }
// Kill the array handle // Kill the array handle.
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.
case WeaponGroup: case WeaponGroup:
{ {
SetMenuTitle(menu_weapons_weapons, "%t\n ", "Weapons menu weapons group title"); SetMenuTitle(menu_weapons_weapons, "%t\n ", "Weapons menu weapons group title");
@ -183,7 +183,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
new Handle:arrayWeaponGroups = INVALID_HANDLE; new Handle:arrayWeaponGroups = INVALID_HANDLE;
new size = RestrictCreateGroupArray(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));
@ -202,7 +202,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
AddMenuItem(menu_weapons_weapons, weapongroup, display); AddMenuItem(menu_weapons_weapons, weapongroup, display);
} }
// If there are no weapons, add an "(Empty)" line // If there are no weapons, add an "(Empty)" line.
if (size == 0) if (size == 0)
{ {
decl String:empty[64]; decl String:empty[64];
@ -230,7 +230,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
*/ */
public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, client, slot) public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, client, slot)
{ {
// Client selected an option // Client selected an option.
if (action == MenuAction_Select) if (action == MenuAction_Select)
{ {
decl String:weapon[WEAPONS_MAX_LENGTH]; decl String:weapon[WEAPONS_MAX_LENGTH];
@ -238,7 +238,7 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
switch(curMenuWeapons[client]) switch(curMenuWeapons[client])
{ {
// Client is restricting a single weapon // Client is restricting a single weapon.
case Weapon: case Weapon:
{ {
new WpnRestrictQuery:output; new WpnRestrictQuery:output;
@ -254,27 +254,27 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
RestrictPrintUnrestrictOutput(client, output, weapon, false); RestrictPrintUnrestrictOutput(client, output, weapon, false);
} }
// Resend menu // Resend menu.
WeaponsMenuWeapons(client, curMenuWeapons[client]); WeaponsMenuWeapons(client, curMenuWeapons[client]);
} }
// Client is accessing a weapon group // Client is accessing a weapon group.
case WeaponGroup: case WeaponGroup:
{ {
// Send weapon group menu // Send weapon group menu.
WeaponsMenuWeaponGroup(client, weapon); WeaponsMenuWeaponGroup(client, weapon);
} }
} }
} }
// Client closed the menu // Client closed the menu.
if (action == MenuAction_Cancel) if (action == MenuAction_Cancel)
{ {
// Client hit "Back" button // Client hit "Back" button.
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
WeaponsMenuMain(client); WeaponsMenuMain(client);
} }
} }
// Client hit "Exit" button // Client hit "Exit" button.
else if (action == MenuAction_End) else if (action == MenuAction_End)
{ {
CloseHandle(menu_weapons_weapons); CloseHandle(menu_weapons_weapons);
@ -285,7 +285,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
{ {
strcopy(curMenuGroup[client], WEAPONS_MAX_LENGTH, weapongroup); strcopy(curMenuGroup[client], WEAPONS_MAX_LENGTH, weapongroup);
// Create menu handle // Create menu handle.
new Handle:menu_weapons_groupweapon = CreateMenu(WeaponsMenuWeaponGroupHandle); new Handle:menu_weapons_groupweapon = CreateMenu(WeaponsMenuWeaponGroupHandle);
SetMenuTitle(menu_weapons_groupweapon, "%t\n ", "Weapons menu weapon group title", weapongroup); SetMenuTitle(menu_weapons_groupweapon, "%t\n ", "Weapons menu weapon group title", weapongroup);
@ -319,7 +319,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
new Handle:arrayGroupWeapons = INVALID_HANDLE; new Handle:arrayGroupWeapons = INVALID_HANDLE;
new size = RestrictCreateGroupWeaponsArray(arrayGroupWeapons, weapongroup); new size = RestrictCreateGroupWeaponsArray(arrayGroupWeapons, weapongroup);
// x = Array index // x = Array index.
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
{ {
GetArrayString(arrayGroupWeapons, x, groupweapon, sizeof(groupweapon)); GetArrayString(arrayGroupWeapons, x, groupweapon, sizeof(groupweapon));
@ -334,7 +334,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
AddMenuItem(menu_weapons_groupweapon, groupweapon, display); AddMenuItem(menu_weapons_groupweapon, groupweapon, display);
} }
// Kill the array handle // Kill the array handle.
CloseHandle(arrayGroupWeapons); CloseHandle(arrayGroupWeapons);
SetMenuExitBackButton(menu_weapons_groupweapon, true); SetMenuExitBackButton(menu_weapons_groupweapon, true);
@ -351,7 +351,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
*/ */
public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:action, client, slot) public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:action, client, slot)
{ {
// Client selected an option // Client selected an option.
if (action == MenuAction_Select) if (action == MenuAction_Select)
{ {
switch(slot) switch(slot)
@ -387,19 +387,19 @@ public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:
} }
} }
// Resend menu // Resend menu.
WeaponsMenuWeaponGroup(client, curMenuGroup[client]); WeaponsMenuWeaponGroup(client, curMenuGroup[client]);
} }
// Client closed the menu // Client closed the menu.
if (action == MenuAction_Cancel) if (action == MenuAction_Cancel)
{ {
// Client hit "Back" button // Client hit "Back" button.
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
WeaponsMenuWeapons(client, curMenuWeapons[client]); WeaponsMenuWeapons(client, curMenuWeapons[client]);
} }
} }
// Client hit "Exit" button // Client hit "Exit" button.
else if (action == MenuAction_End) else if (action == MenuAction_End)
{ {
CloseHandle(menu_weapons_groupweapon); CloseHandle(menu_weapons_groupweapon);
@ -412,7 +412,7 @@ public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:
*/ */
WeaponsMenuMarket(client) WeaponsMenuMarket(client)
{ {
// Create menu handle // Create menu handle.
new Handle:menu_weapons_market = CreateMenu(WeaponsMenuMarketHandle); new Handle:menu_weapons_market = CreateMenu(WeaponsMenuMarketHandle);
SetGlobalTransTarget(client); SetGlobalTransTarget(client);
@ -428,7 +428,7 @@ WeaponsMenuMarket(client)
AddMenuItem(menu_weapons_market, "togglebuyzone", togglebuyzone); AddMenuItem(menu_weapons_market, "togglebuyzone", togglebuyzone);
// Create a "Back" button to the weapons main menu // Create a "Back" button to the weapons main menu.
SetMenuExitBackButton(menu_weapons_market, true); SetMenuExitBackButton(menu_weapons_market, true);
// Send menu // Send menu
@ -444,7 +444,7 @@ WeaponsMenuMarket(client)
*/ */
public WeaponsMenuMarketHandle(Handle:menu_weapons_market, MenuAction:action, client, slot) public WeaponsMenuMarketHandle(Handle:menu_weapons_market, MenuAction:action, client, slot)
{ {
// Client selected an option // Client selected an option.
if (action == MenuAction_Select) if (action == MenuAction_Select)
{ {
switch(slot) switch(slot)
@ -462,19 +462,19 @@ public WeaponsMenuMarketHandle(Handle:menu_weapons_market, MenuAction:action, cl
} }
} }
// Resend menu // Resend menu.
WeaponsMenuMarket(client); WeaponsMenuMarket(client);
} }
// Client closed the menu // Client closed the menu.
if (action == MenuAction_Cancel) if (action == MenuAction_Cancel)
{ {
// Client hit "Back" button // Client hit "Back" button.
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
WeaponsMenuMain(client); WeaponsMenuMain(client);
} }
} }
// Client hit "Exit" button // Client hit "Exit" button.
else if (action == MenuAction_End) else if (action == MenuAction_End)
{ {
CloseHandle(menu_weapons_market); CloseHandle(menu_weapons_market);

View File

@ -38,22 +38,22 @@ enum WpnRestrictQuery
*/ */
RestrictInit() 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", RestrictBuyHook); RegConsoleCmd("buy", RestrictBuyHook);
} }
/** /**
* Clears weapon restrict data * Clears weapon restrict data.
*/ */
RestrictClearData() RestrictClearData()
{ {
// Clear restricted weapons // Clear restricted weapons.
RestrictWeaponUnrestrictAll(); RestrictWeaponUnrestrictAll();
// Load weapon group data // Load weapon group data.
if (kvWeaponGroups != INVALID_HANDLE) if (kvWeaponGroups != INVALID_HANDLE)
{ {
CloseHandle(kvWeaponGroups); CloseHandle(kvWeaponGroups);
@ -67,13 +67,13 @@ RestrictClearData()
*/ */
RestrictOnMapStart() RestrictOnMapStart()
{ {
// Restrict default restrictions (set in weapons.txt) // Restrict default restrictions. (set in weapons.txt)
RestrictDefaultRestrictions(); RestrictDefaultRestrictions();
decl String:path[PLATFORM_MAX_PATH]; decl String:path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "configs/zr/weapons/weapongroups.txt"); BuildPath(Path_SM, path, sizeof(path), "configs/zr/weapons/weapongroups.txt");
// If file isn't found, stop plugin // If file isn't found, stop plugin.
if (!FileToKeyValues(kvWeaponGroups, path)) if (!FileToKeyValues(kvWeaponGroups, path))
{ {
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS)) if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
@ -88,7 +88,7 @@ RestrictOnMapStart()
} }
/** /**
* Restrict default restrictions (set in weapons.txt) * Restrict default restrictions. (set in weapons.txt)
*/ */
RestrictDefaultRestrictions() RestrictDefaultRestrictions()
{ {
@ -103,7 +103,7 @@ RestrictDefaultRestrictions()
{ {
KvGetSectionName(kvWeapons, weapon, sizeof(weapon)); KvGetSectionName(kvWeapons, weapon, sizeof(weapon));
// If weapon is defaulted to restricted, then restrict weapon // If weapon is defaulted to restricted, then restrict weapon.
decl String:restrict[8]; decl String:restrict[8];
KvGetString(kvWeapons, "restrict", restrict, sizeof(restrict), "no"); KvGetString(kvWeapons, "restrict", restrict, sizeof(restrict), "no");
@ -113,7 +113,7 @@ RestrictDefaultRestrictions()
RestrictPrintRestrictOutput(0, output, display, true); RestrictPrintRestrictOutput(0, output, display, true);
// Function calls above screwed with the keyvalue stack, so we have to set it back // Function calls above screwed with the keyvalue stack, so we have to set it back
// to where it was before those calls // to where it was before those calls.
KvRewind(kvWeapons); KvRewind(kvWeapons);
KvJumpToKey(kvWeapons, weapon); KvJumpToKey(kvWeapons, weapon);
} }
@ -179,7 +179,7 @@ RestrictWeaponUnrestrictAll()
} }
/** /**
* Hook Weapon_CanUse function on a client. * Client is joining the server.
* *
* @param client The client index. * @param client The client index.
*/ */
@ -207,15 +207,15 @@ RestrictOnClientDisconnect(client)
*/ */
public Action:RestrictBuyHook(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]);
if (!enabled) if (!enabled)
{ {
// Allow command // Allow command.
return Plugin_Continue; return Plugin_Continue;
} }
// If player is a zombie then block command // If player is a zombie then block command.
if (IsPlayerZombie(client)) if (IsPlayerZombie(client))
{ {
ZR_PrintToChat(client, "Zombie cant use weapon"); ZR_PrintToChat(client, "Zombie cant use weapon");
@ -229,16 +229,16 @@ public Action:RestrictBuyHook(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 (RestrictIsWeaponRestricted(weapon)) if (RestrictIsWeaponRestricted(weapon))
{ {
ZR_PrintToChat(client, "Weapon is restricted", weapon); ZR_PrintToChat(client, "Weapon is restricted", weapon);
// Block command // Block command.
return Plugin_Handled; return Plugin_Handled;
} }
// Allow command // Allow command.
return Plugin_Continue; return Plugin_Continue;
} }
@ -256,18 +256,23 @@ public Action:RestrictBuyHook(client, argc)
*/ */
WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "") WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
{ {
// Check if weapon is a custom group name.
if (RestrictIsWeaponGroup(weapon)) if (RestrictIsWeaponGroup(weapon))
{ {
// Return restrict failed if group is already restricted.
if (RestrictIsGroupRestricted(weapon)) if (RestrictIsGroupRestricted(weapon))
{ {
return Failed_Group; return Failed_Group;
} }
// Jump to weapon group key.
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
KvJumpToKey(kvWeaponGroups, weapon); KvJumpToKey(kvWeaponGroups, weapon);
// Get display name of the weapon group.
KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH); KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH);
// Traverse into the group's weapons.
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
decl String:groupweapon[WEAPONS_MAX_LENGTH]; decl String:groupweapon[WEAPONS_MAX_LENGTH];
@ -276,12 +281,13 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
{ {
KvGetSectionName(kvWeaponGroups, groupweapon, sizeof(groupweapon)); KvGetSectionName(kvWeaponGroups, groupweapon, sizeof(groupweapon));
// If weapon is invalid, then skip // If weapon is invalid, then skip.
if (!WeaponsIsValidWeapon(groupweapon)) if (!WeaponsIsValidWeapon(groupweapon))
{ {
continue; continue;
} }
// Add to restricted weapon array if not already restricted.
if (!RestrictIsWeaponRestricted(groupweapon)) if (!RestrictIsWeaponRestricted(groupweapon))
{ {
PushArrayString(gRestrictedWeapons, groupweapon); PushArrayString(gRestrictedWeapons, groupweapon);
@ -289,23 +295,29 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
} while (KvGotoNextKey(kvWeaponGroups)); } while (KvGotoNextKey(kvWeaponGroups));
} }
// Successfully restricted a group
return Successful_Group; return Successful_Group;
} }
// If weapon name is invalid then set display to invalid weapon name.
if (!WeaponsIsValidWeapon(weapon)) if (!WeaponsIsValidWeapon(weapon))
{ {
strcopy(display, WEAPONS_MAX_LENGTH, weapon); strcopy(display, WEAPONS_MAX_LENGTH, weapon);
// Weapon name was invalid.
return Invalid; return Invalid;
} }
// Get display name of the weapon.
WeaponGetDisplayName(weapon, display); WeaponGetDisplayName(weapon, display);
// Return restrict failed if weapon is already restricted.
if (RestrictIsWeaponRestricted(weapon)) if (RestrictIsWeaponRestricted(weapon))
{ {
return Failed_Weapon; return Failed_Weapon;
} }
// Add to restricted weapon array.
PushArrayString(gRestrictedWeapons, display); PushArrayString(gRestrictedWeapons, display);
return Successful_Weapon; return Successful_Weapon;
@ -315,8 +327,8 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
* Unrestricts a weapon. * Unrestricts a weapon.
* *
* @param weapon The weapon/group name. * @param weapon The weapon/group name.
* @param display String set to the name set in weapons.txt * @param display String set to the name set in weapons.txt.
* Set to the value of 'weapon' if invalid * Set to the value of 'weapon' if invalid.
* @return Successful_Weapon: The call successfully restricted a weapon. * @return Successful_Weapon: The call successfully restricted a weapon.
* Successful_Group: The call successfully restricted a weapon group. * Successful_Group: The call successfully restricted a weapon group.
* Failed_Weapon: The call failed to restrict a weapon. * Failed_Weapon: The call failed to restrict a weapon.
@ -325,18 +337,23 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
*/ */
WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = "") WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = "")
{ {
// Check if weapon is a custom group name.
if (RestrictIsWeaponGroup(weapon)) if (RestrictIsWeaponGroup(weapon))
{ {
// Return restrict failed if group isn't restricted.
if (RestrictIsGroupUnrestricted(weapon)) if (RestrictIsGroupUnrestricted(weapon))
{ {
return Failed_Group; return Failed_Group;
} }
// Jump to weapon group key.
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
KvJumpToKey(kvWeaponGroups, weapon); KvJumpToKey(kvWeaponGroups, weapon);
// Get display name of the weapon group.
KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH); KvGetSectionName(kvWeaponGroups, display, WEAPONS_MAX_LENGTH);
// Traverse into the group's weapons.
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
decl String:groupweapon[WEAPONS_MAX_LENGTH]; decl String:groupweapon[WEAPONS_MAX_LENGTH];
@ -351,8 +368,10 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = ""
continue; continue;
} }
// Remove from restricted weapon array if currently restricted.
if (RestrictIsWeaponRestricted(groupweapon)) if (RestrictIsWeaponRestricted(groupweapon))
{ {
// Verify weapon is in the array.
new weaponindex = RestrictGetIndex(groupweapon); new weaponindex = RestrictGetIndex(groupweapon);
if (weaponindex > -1) if (weaponindex > -1)
{ {
@ -362,9 +381,11 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = ""
} while (KvGotoNextKey(kvWeaponGroups)); } while (KvGotoNextKey(kvWeaponGroups));
} }
// Successfully unrestricted a group
return Successful_Group; return Successful_Group;
} }
// If weapon name is invalid then set display to invalid weapon name.
if (!WeaponsIsValidWeapon(weapon)) if (!WeaponsIsValidWeapon(weapon))
{ {
strcopy(display, WEAPONS_MAX_LENGTH, weapon); strcopy(display, WEAPONS_MAX_LENGTH, weapon);
@ -372,16 +393,20 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = ""
return Invalid; return Invalid;
} }
// Get display name of the weapon.
WeaponGetDisplayName(weapon, display); WeaponGetDisplayName(weapon, display);
// Return unrestrict failed if weapon isn't restricted.
if (!RestrictIsWeaponRestricted(weapon)) if (!RestrictIsWeaponRestricted(weapon))
{ {
return Failed_Weapon; return Failed_Weapon;
} }
// Verify weapon is in the array.
new weaponindex = RestrictGetIndex(display); new weaponindex = RestrictGetIndex(display);
if (weaponindex > -1) if (weaponindex > -1)
{ {
// Remove from restricted weapon array.
RemoveFromArray(gRestrictedWeapons, weaponindex); RemoveFromArray(gRestrictedWeapons, weaponindex);
} }
@ -398,7 +423,8 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = ""
RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon[], bool:reply) RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon[], bool:reply)
{ {
switch(output) switch(output)
{ {
// Weapon was successfully restricted.
case Successful_Weapon: case Successful_Weapon:
{ {
ZR_PrintToChat(0, "Restrict weapon", weapon); ZR_PrintToChat(0, "Restrict weapon", weapon);
@ -408,6 +434,7 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
ZR_LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon); ZR_LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
} }
} }
// Weapon group was successfully restricted.
case Successful_Group: case Successful_Group:
{ {
decl String:weaponlist[128]; decl String:weaponlist[128];
@ -420,6 +447,7 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
ZR_LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon); ZR_LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
} }
} }
// Weapon was already restricted.
case Failed_Weapon: case Failed_Weapon:
{ {
if (reply) if (reply)
@ -431,6 +459,7 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
ZR_PrintToChat(client, "Restrict weapon failed", weapon); ZR_PrintToChat(client, "Restrict weapon failed", weapon);
} }
} }
// Weapon group was already restricted.
case Failed_Group: case Failed_Group:
{ {
decl String:weaponlist[128]; decl String:weaponlist[128];
@ -445,6 +474,7 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
ZR_PrintToChat(client, "Restrict custom weapon group failed", weapon, weaponlist); ZR_PrintToChat(client, "Restrict custom weapon group failed", weapon, weaponlist);
} }
} }
// Weapon name was invalid.
case Invalid: case Invalid:
{ {
if (reply) if (reply)
@ -470,6 +500,7 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
{ {
switch(output) switch(output)
{ {
// Weapon was successfully unrestricted.
case Successful_Weapon: case Successful_Weapon:
{ {
ZR_PrintToChat(0, "Unrestrict weapon", weapon); ZR_PrintToChat(0, "Unrestrict weapon", weapon);
@ -479,6 +510,7 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
ZR_LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon); ZR_LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
} }
} }
// Weapon group was successfully unrestricted.
case Successful_Group: case Successful_Group:
{ {
decl String:weaponlist[128]; decl String:weaponlist[128];
@ -491,6 +523,7 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
ZR_LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon); ZR_LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
} }
} }
// Weapon wasn't restricted.
case Failed_Weapon: case Failed_Weapon:
{ {
if (reply) if (reply)
@ -502,6 +535,7 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
ZR_PrintToChat(client, "Unrestrict weapon failed", weapon); ZR_PrintToChat(client, "Unrestrict weapon failed", weapon);
} }
} }
// Weapon group wasn't restricted.
case Failed_Group: case Failed_Group:
{ {
decl String:weaponlist[128]; decl String:weaponlist[128];
@ -516,6 +550,7 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
ZR_PrintToChat(client, "Unrestrict custom weapon group failed", weapon, weaponlist); ZR_PrintToChat(client, "Unrestrict custom weapon group failed", weapon, weaponlist);
} }
} }
// Weapon name was invalid.
case Invalid: case Invalid:
{ {
if (reply) if (reply)
@ -534,22 +569,28 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
* Checks if a weapon is restricted. * Checks if a weapon is restricted.
* *
* @param weapon The weapon name. * @param weapon The weapon name.
* @return True if weapon is restricted, false if not.
*/ */
bool:RestrictIsWeaponRestricted(const String:weapon[]) bool:RestrictIsWeaponRestricted(const String:weapon[])
{ {
decl String:restrictedweapon[WEAPONS_MAX_LENGTH]; decl String:restrictedweapon[WEAPONS_MAX_LENGTH];
new size = GetArraySize(gRestrictedWeapons); new size = GetArraySize(gRestrictedWeapons);
// x = restricted weapon index.
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
{ {
GetArrayString(gRestrictedWeapons, x, restrictedweapon, sizeof(restrictedweapon)); GetArrayString(gRestrictedWeapons, x, restrictedweapon, sizeof(restrictedweapon));
// Check if weapon matches any weapon names in the restricted weapon array.
if (StrEqual(weapon, restrictedweapon, false)) if (StrEqual(weapon, restrictedweapon, false))
{ {
// Weapon is restricted.
return true; return true;
} }
} }
// Weapon is not restricted.
return false; return false;
} }
@ -560,11 +601,15 @@ bool:RestrictIsWeaponRestricted(const String:weapon[])
*/ */
bool:RestrictIsGroupRestricted(const String:weapongroup[]) bool:RestrictIsGroupRestricted(const String:weapongroup[])
{ {
// Reset keygroup's traversal stack.
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
// Traverse in to the group names.
if (KvJumpToKey(kvWeaponGroups, weapongroup)) if (KvJumpToKey(kvWeaponGroups, weapongroup))
{ {
decl String:groupweapon[WEAPONS_MAX_LENGTH]; decl String:groupweapon[WEAPONS_MAX_LENGTH];
// Traverse into the group's weapons.
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
do do
@ -592,11 +637,15 @@ bool:RestrictIsGroupRestricted(const String:weapongroup[])
*/ */
bool:RestrictIsGroupUnrestricted(const String:weapongroup[]) bool:RestrictIsGroupUnrestricted(const String:weapongroup[])
{ {
// Reset keygroup's traversal stack.
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
// Traverse in to the group names.
if (KvJumpToKey(kvWeaponGroups, weapongroup)) if (KvJumpToKey(kvWeaponGroups, weapongroup))
{ {
decl String:groupweapon[WEAPONS_MAX_LENGTH]; decl String:groupweapon[WEAPONS_MAX_LENGTH];
// Traverse into the group's weapons.
if (KvGotoFirstSubKey(kvWeaponGroups)) if (KvGotoFirstSubKey(kvWeaponGroups))
{ {
do do
@ -637,16 +686,21 @@ RestrictGetIndex(const String:weapon[])
decl String:restrictedweapon[WEAPONS_MAX_LENGTH]; decl String:restrictedweapon[WEAPONS_MAX_LENGTH];
new size = GetArraySize(gRestrictedWeapons); new size = GetArraySize(gRestrictedWeapons);
// x = restricted weapon index.
for (new x = 0; x < size; x++) for (new x = 0; x < size; x++)
{ {
GetArrayString(gRestrictedWeapons, x, restrictedweapon, sizeof(restrictedweapon)); GetArrayString(gRestrictedWeapons, x, restrictedweapon, sizeof(restrictedweapon));
// Check if weapon matches weapon in restricted weapons array.
if (StrEqual(weapon, restrictedweapon, false)) if (StrEqual(weapon, restrictedweapon, false))
{ {
// Return restricted weapon's index.
return x; return x;
} }
} }
// Weapon isn't restricted.
return -1; return -1;
} }
@ -658,10 +712,10 @@ RestrictGetIndex(const String:weapon[])
*/ */
bool:RestrictIsWeaponGroup(const String:groupname[]) bool:RestrictIsWeaponGroup(const String:groupname[])
{ {
// Reset the traversal stack // Reset keygroup's traversal stack.
KvRewind(kvWeaponGroups); KvRewind(kvWeaponGroups);
// Returns true if groupname is listed in the custom groups file // Returns true if groupname is listed in the custom groups file.
return KvJumpToKey(kvWeaponGroups, groupname); return KvJumpToKey(kvWeaponGroups, groupname);
} }
@ -715,7 +769,7 @@ RestrictCreateGroupWeaponsArray(&Handle:arrayGroupWeapons, const String:weapongr
{ {
KvGetSectionName(kvWeaponGroups, groupweapon, maxlen); KvGetSectionName(kvWeaponGroups, groupweapon, maxlen);
// If the weapon is invalid, then stop // If the weapon is invalid, then stop.
if (!WeaponsIsValidWeapon(groupweapon)) if (!WeaponsIsValidWeapon(groupweapon))
{ {
continue; continue;
@ -754,7 +808,7 @@ RestrictGetGroupWeapons(const String:groupname[], String:weaponlist[], maxlen, c
{ {
KvGetSectionName(kvWeaponGroups, groupweapon, sizeof(groupweapon)); KvGetSectionName(kvWeaponGroups, groupweapon, sizeof(groupweapon));
// If weapon is invalid, then skip // If weapon is invalid, then skip.
if (!WeaponsIsValidWeapon(groupweapon)) if (!WeaponsIsValidWeapon(groupweapon))
{ {
continue; continue;
@ -780,7 +834,7 @@ RestrictGetGroupWeapons(const String:groupname[], String:weaponlist[], maxlen, c
*/ */
public RestrictCanUse(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]);
if (!enabled) if (!enabled)
{ {
@ -790,16 +844,16 @@ public RestrictCanUse(client, weapon, dummy1, dummy2, dummy3, dummy4)
new String:weaponname[WEAPONS_MAX_LENGTH]; new String:weaponname[WEAPONS_MAX_LENGTH];
GetEdictClassname(weapon, weaponname, sizeof(weaponname)); GetEdictClassname(weapon, weaponname, sizeof(weaponname));
// Strip "weapon_" from entity name // Strip "weapon_" from entity name.
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 (RestrictIsWeaponRestricted(weaponname)) if (RestrictIsWeaponRestricted(weaponname))
{ {
return 0; return 0;
} }
// If the player is a zombie and the weapon isn't a knife then prevent pickup // If the player is a zombie and the weapon isn't a knife then prevent pickup.
if (IsPlayerZombie(client) && !StrEqual(weaponname, "knife")) if (IsPlayerZombie(client) && !StrEqual(weaponname, "knife"))
{ {
return 0; return 0;

View File

@ -25,7 +25,7 @@ new Handle:kvWeapons = INVALID_HANDLE;
#include "zr/weapons/menu_weapons" #include "zr/weapons/menu_weapons"
/** /**
* Weapons module init function * Weapons module init function.
*/ */
WeaponsInit() WeaponsInit()
{ {
@ -34,7 +34,7 @@ WeaponsInit()
} }
/** /**
* Clears weapon data * Clears weapon data.
*/ */
WeaponsClearData() WeaponsClearData()
{ {
@ -52,16 +52,16 @@ WeaponsClearData()
*/ */
WeaponsLoad() WeaponsLoad()
{ {
// Clear weapon data // Clear weapon data.
WeaponsClearData(); WeaponsClearData();
// Clear weapon restrict data // Clear weapon restrict data.
RestrictClearData(); RestrictClearData();
decl String:path[PLATFORM_MAX_PATH]; decl String:path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "configs/zr/weapons/weapons.txt"); BuildPath(Path_SM, path, sizeof(path), "configs/zr/weapons/weapons.txt");
// If file isn't found, stop plugin // If file isn't found, stop plugin.
if (!FileToKeyValues(kvWeapons, path)) if (!FileToKeyValues(kvWeapons, path))
{ {
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS)) if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
@ -72,16 +72,19 @@ WeaponsLoad()
return; return;
} }
// Validate weapons config // Validate weapons config.
WeaponsValidateConfig(); WeaponsValidateConfig();
// Forward event to sub-module // Forward event to sub-module.
RestrictOnMapStart(); RestrictOnMapStart();
} }
/**
* Validate weapon config file and settings.
*/
WeaponsValidateConfig() WeaponsValidateConfig()
{ {
// If log flag check fails, don't log // If log flag check fails, don't log.
if (!LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS)) if (!LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
{ {
return; return;
@ -94,15 +97,25 @@ WeaponsValidateConfig()
} }
} }
/**
* Client is joining the server.
*
* @param client The client index.
*/
WeaponsClientInit(client) WeaponsClientInit(client)
{ {
// Forward event to sub-module // Forward event to sub-module.
RestrictClientInit(client); RestrictClientInit(client);
} }
/**
* Client is leaving the server.
*
* @param client The client index.
*/
WeaponsOnClientDisconnect(client) WeaponsOnClientDisconnect(client)
{ {
// Forward event to sub-module // Forward event to sub-module.
RestrictOnClientDisconnect(client); RestrictOnClientDisconnect(client);
} }
@ -128,7 +141,7 @@ WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH)
{ {
KvGetSectionName(kvWeapons, weapon, maxlen); KvGetSectionName(kvWeapons, weapon, maxlen);
// Push weapon name into the array // Push weapon name into the array.
PushArrayString(arrayWeapons, weapon); PushArrayString(arrayWeapons, weapon);
// Increment count. // Increment count.
@ -141,12 +154,13 @@ WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH)
} }
/** /**
* 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.
* @return Returns true if valid, false it not. * @return Returns true if valid, false it not.
*/ */
bool:WeaponsIsValidWeapon(const String:weapon[]) bool:WeaponsIsValidWeapon(const String:weapon[])
{ {
// Reset keyvalue's traversal stack.
KvRewind(kvWeapons); KvRewind(kvWeapons);
if (KvGotoFirstSubKey(kvWeapons)) if (KvGotoFirstSubKey(kvWeapons))
{ {
@ -156,6 +170,7 @@ bool:WeaponsIsValidWeapon(const String:weapon[])
{ {
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon)); KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
// If weaponname matches a valid weapon, then return true.
if (StrEqual(validweapon, weapon, false)) if (StrEqual(validweapon, weapon, false))
{ {
return true; return true;
@ -164,16 +179,18 @@ bool:WeaponsIsValidWeapon(const String:weapon[])
} while (KvGotoNextKey(kvWeapons)); } while (KvGotoNextKey(kvWeapons));
} }
// Weapon is invalid.
return false; return false;
} }
/** /**
* Looks up a weapon in weapons.txt and returns exact display name * Looks up a weapon in weapons.txt and returns exact display name.
* @param weapon The weapon name. * @param weapon The weapon name.
* @param display Returns with the display name, is not changed if weapon is invalid. * @param display Returns with the display name, is not changed if weapon is invalid.
*/ */
WeaponGetDisplayName(const String:weapon[], String:display[]) WeaponGetDisplayName(const String:weapon[], String:display[])
{ {
// Reset keyvalue's traversal stack.
KvRewind(kvWeapons); KvRewind(kvWeapons);
if (KvGotoFirstSubKey(kvWeapons)) if (KvGotoFirstSubKey(kvWeapons))
{ {
@ -183,6 +200,7 @@ WeaponGetDisplayName(const String:weapon[], String:display[])
{ {
KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon)); KvGetSectionName(kvWeapons, validweapon, sizeof(validweapon));
// If weapon matches a valid weapon (case-insensitive), then return display name.
if (StrEqual(validweapon, weapon, false)) if (StrEqual(validweapon, weapon, false))
{ {
strcopy(display, WEAPONS_MAX_LENGTH, validweapon); strcopy(display, WEAPONS_MAX_LENGTH, validweapon);
@ -225,7 +243,7 @@ bool:WeaponsIsWeaponMenu(const String:weapon[])
} }
/** /**
* Returns knockback multiplier of the weapon * Returns knockback multiplier of the weapon.
* @param weapon The weapon name. * @param weapon The weapon name.
* @return The float value of the knockback multiplier, 1.0 if not found. * @return The float value of the knockback multiplier, 1.0 if not found.
*/ */