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;
@ -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.
* @return The client index of the other stuck player, -1 when
@ -61,11 +61,11 @@ AntiStickIsStuck(client)
GetClientAbsOrigin(client, clientloc);
// x = client index
// x = client index.
new maxplayers = GetMaxClients();
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)
{
continue;
@ -82,7 +82,7 @@ AntiStickIsStuck(client)
new Float:eyeloc[3];
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:zdistance = FloatAbs(stuckloc[2] - clientloc[2]);
@ -107,13 +107,13 @@ public Action:AntiStickTimer(Handle:timer)
new maxplayers = GetMaxClients();
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))
{
continue;
}
// Stop if the player isn't stuck
// Stop if the player isn't stuck.
new stuckindex = AntiStickIsStuck(x);
if (stuckindex == -1)
{
@ -138,17 +138,18 @@ public Action:AntiStickTimer(Handle:timer)
* Repeated timer function.
* Re-solidifies a player being unstuck.
*
* @param timer The timer handle.
* @param index The client 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))
{
return Plugin_Stop;
}
// Stop if the player is still stuck
// Stop if the player is still stuck.
if (AntiStickIsStuck(index) > -1)
{
return Plugin_Continue;

View File

@ -31,9 +31,12 @@ new Handle:kvHitgroups = INVALID_HANDLE;
* @endsection
*/
/**
* Clears hitgroup data.
*/
HitgroupsClearData()
{
// Load hitgroup data
// Load hitgroup data.
if (kvHitgroups != INVALID_HANDLE)
{
CloseHandle(kvHitgroups);
@ -42,6 +45,9 @@ HitgroupsClearData()
kvHitgroups = CreateKeyValues("hitgroups");
}
/**
* Loads hitgroup data from file.
*/
HitgroupsLoad()
{
// Clear hitgroup data
@ -50,7 +56,7 @@ HitgroupsLoad()
decl String:path[PLATFORM_MAX_PATH];
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 (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS))
@ -61,13 +67,16 @@ HitgroupsLoad()
return;
}
// Validate hitgroups config
// Validate hitgroups config.
HitgroupsValidateConfig();
}
/**
* Validate hitgroup config file and settings.
*/
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))
{
return;
@ -80,6 +89,11 @@ HitgroupsValidateConfig()
}
}
/**
* Retrieve hitgroup knockback value.
*
* @param hitgroup The hitgroup index.
*/
Float:HitgroupsGetHitgroupKnockback(hitgroup)
{
// Reset keyvalue's traversal stack.

View File

@ -6,7 +6,8 @@
* ====================
*/
/** Player hurt event
/** Player hurt event.
*
* @param client The victim index. (zombie)
* @param attacker The attacker index. (human)
* @param weapon The weapon used.
@ -59,7 +60,7 @@ KnockbackPlayerHurt(client, attacker, const String:weapon[], hitgroup, dmg_healt
// Retrieve hitgroup knockback boost.
new Float:boostHitgroup = HitgroupsGetHitgroupKnockback(hitgroup);
// Apply all knockback multipliers
// Apply all knockback multipliers.
knockback *= float(dmg_health) * boostWeapon * boostHitgroup;
// Apply knockback.
@ -70,6 +71,7 @@ KnockbackPlayerHurt(client, attacker, const String:weapon[], hitgroup, dmg_healt
/**
* Sets velocity on a player.
*
* @param client The client index.
* @param startpoint The starting coordinate to push from.
* @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)
*
* @param entity The entity index.
* @param contentsMask The contents mask.
* @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).
*
* @param heLoc The location of the exploding grenade.
* @return The entity index of the grenade.
*/

View File

@ -15,13 +15,13 @@
*/
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))
{
return false;
}
// If player is a zombie, then stop
// If player is a zombie, then stop.
if (IsPlayerZombie(client))
{
ZR_PrintToChat(client, "Zombie cant use weapon");
@ -29,7 +29,7 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
return false;
}
// If player is using the rebuy option then allow
// If player is using the rebuy option then allow.
if (StrEqual(weaponid, "rebuy"))
{
return true;
@ -39,16 +39,16 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
decl String:weapon[WEAPONS_MAX_LENGTH];
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))
{
return false;
}
// Strip "weapon_" from entity name
// Strip "weapon_" from entity name.
ReplaceString(weapon, sizeof(weapon), "weapon_", "");
// If the weapon is restricted, then stop
// If the weapon is restricted, then stop.
if (RestrictIsWeaponRestricted(weapon))
{
ZR_PrintToChat(client, "Weapon is restricted", weapon);
@ -56,7 +56,7 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
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]);
if (!IsClientInBuyZone(client) && buyzone)
{
@ -76,12 +76,12 @@ public bool:Market_OnWeaponSelected(client, String:weaponid[])
*/
public Market_PostOnWeaponSelected(client, &bool:allowed)
{
// If the purchase wasn't allowed, then stop
// If the purchase wasn't allowed, then stop.
if (!allowed)
{
return;
}
// Resend market menu
// Resend market menu.
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];
/**
* 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];
@ -31,7 +31,7 @@ new String:curMenuGroup[WEAPONS_MAX_LENGTH][MAXPLAYERS + 1];
*/
WeaponsMenuMain(client)
{
// Create menu handle
// Create menu handle.
new Handle:menu_weapons_main = CreateMenu(WeaponsMenuMainHandle);
SetGlobalTransTarget(client);
@ -49,7 +49,7 @@ WeaponsMenuMain(client)
AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction);
AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction);
// Disable market option if market isn't installed
// Disable market option if market isn't installed.
if (market)
{
AddMenuItem(menu_weapons_main, "zmarket", zmarket);
@ -59,10 +59,10 @@ WeaponsMenuMain(client)
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);
// Send menu
// Send menu.
DisplayMenu(menu_weapons_main, client, MENU_TIME_FOREVER);
}
@ -75,7 +75,7 @@ WeaponsMenuMain(client)
*/
public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client, slot)
{
// Client selected an option
// Client selected an option.
if (action == MenuAction_Select)
{
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)
{
// Client hit "Back" button
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
ZRAdminMenu(client);
}
}
// Client hit "Exit" button
// Client hit "Exit" button.
else if (action == MenuAction_End)
{
CloseHandle(menu_weapons_main);
@ -116,15 +116,15 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
*/
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;
// Create menu handle
// Create menu handle.
new Handle:menu_weapons_weapons = CreateMenu(WeaponsMenuWeaponsHandle);
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])
{
case Weapon:
@ -136,7 +136,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
new Handle:arrayWeapons = INVALID_HANDLE;
new size = WeaponsCreateWeaponArray(arrayWeapons);
// x = Array index
// x = Array index.
for (new x = 0; x < size; x++)
{
GetArrayString(arrayWeapons, x, weapon, sizeof(weapon));
@ -148,7 +148,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
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);
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)
{
decl String:empty[64];
@ -170,10 +170,10 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
AddMenuItem(menu_weapons_weapons, "empty", empty, ITEMDRAW_DISABLED);
}
// Kill the array handle
// Kill the array handle.
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:
{
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 size = RestrictCreateGroupArray(arrayWeaponGroups);
// x = Array index
// x = Array index.
for (new x = 0; x < size; x++)
{
GetArrayString(arrayWeaponGroups, x, weapongroup, sizeof(weapongroup));
@ -202,7 +202,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
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)
{
decl String:empty[64];
@ -230,7 +230,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
*/
public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action, client, slot)
{
// Client selected an option
// Client selected an option.
if (action == MenuAction_Select)
{
decl String:weapon[WEAPONS_MAX_LENGTH];
@ -238,7 +238,7 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
switch(curMenuWeapons[client])
{
// Client is restricting a single weapon
// Client is restricting a single weapon.
case Weapon:
{
new WpnRestrictQuery:output;
@ -254,27 +254,27 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
RestrictPrintUnrestrictOutput(client, output, weapon, false);
}
// Resend menu
// Resend menu.
WeaponsMenuWeapons(client, curMenuWeapons[client]);
}
// Client is accessing a weapon group
// Client is accessing a weapon group.
case WeaponGroup:
{
// Send weapon group menu
// Send weapon group menu.
WeaponsMenuWeaponGroup(client, weapon);
}
}
}
// Client closed the menu
// Client closed the menu.
if (action == MenuAction_Cancel)
{
// Client hit "Back" button
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
WeaponsMenuMain(client);
}
}
// Client hit "Exit" button
// Client hit "Exit" button.
else if (action == MenuAction_End)
{
CloseHandle(menu_weapons_weapons);
@ -285,7 +285,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
{
strcopy(curMenuGroup[client], WEAPONS_MAX_LENGTH, weapongroup);
// Create menu handle
// Create menu handle.
new Handle:menu_weapons_groupweapon = CreateMenu(WeaponsMenuWeaponGroupHandle);
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 size = RestrictCreateGroupWeaponsArray(arrayGroupWeapons, weapongroup);
// x = Array index
// x = Array index.
for (new x = 0; x < size; x++)
{
GetArrayString(arrayGroupWeapons, x, groupweapon, sizeof(groupweapon));
@ -334,7 +334,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
AddMenuItem(menu_weapons_groupweapon, groupweapon, display);
}
// Kill the array handle
// Kill the array handle.
CloseHandle(arrayGroupWeapons);
SetMenuExitBackButton(menu_weapons_groupweapon, true);
@ -351,7 +351,7 @@ WeaponsMenuWeaponGroup(client, const String:weapongroup[])
*/
public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:action, client, slot)
{
// Client selected an option
// Client selected an option.
if (action == MenuAction_Select)
{
switch(slot)
@ -387,19 +387,19 @@ public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:
}
}
// Resend menu
// Resend menu.
WeaponsMenuWeaponGroup(client, curMenuGroup[client]);
}
// Client closed the menu
// Client closed the menu.
if (action == MenuAction_Cancel)
{
// Client hit "Back" button
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
WeaponsMenuWeapons(client, curMenuWeapons[client]);
}
}
// Client hit "Exit" button
// Client hit "Exit" button.
else if (action == MenuAction_End)
{
CloseHandle(menu_weapons_groupweapon);
@ -412,7 +412,7 @@ public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:
*/
WeaponsMenuMarket(client)
{
// Create menu handle
// Create menu handle.
new Handle:menu_weapons_market = CreateMenu(WeaponsMenuMarketHandle);
SetGlobalTransTarget(client);
@ -428,7 +428,7 @@ WeaponsMenuMarket(client)
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);
// Send menu
@ -444,7 +444,7 @@ WeaponsMenuMarket(client)
*/
public WeaponsMenuMarketHandle(Handle:menu_weapons_market, MenuAction:action, client, slot)
{
// Client selected an option
// Client selected an option.
if (action == MenuAction_Select)
{
switch(slot)
@ -462,19 +462,19 @@ public WeaponsMenuMarketHandle(Handle:menu_weapons_market, MenuAction:action, cl
}
}
// Resend menu
// Resend menu.
WeaponsMenuMarket(client);
}
// Client closed the menu
// Client closed the menu.
if (action == MenuAction_Cancel)
{
// Client hit "Back" button
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
WeaponsMenuMain(client);
}
}
// Client hit "Exit" button
// Client hit "Exit" button.
else if (action == MenuAction_End)
{
CloseHandle(menu_weapons_market);

View File

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

View File

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