Added periods after function comments, moved market handler code to markethandler.inc, made restrictions announced to the server
This commit is contained in:
87
src/zr/weapons/markethandler.inc
Normal file
87
src/zr/weapons/markethandler.inc
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* ====================
|
||||
* Zombie:Reloaded
|
||||
* File: markethandler.inc
|
||||
* Author: Greyscale
|
||||
* ====================
|
||||
*/
|
||||
|
||||
/**
|
||||
* (Market) Forward called when a client selects a weapon from the market.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @param weaponid The unique weapon ID used for market natives.
|
||||
* @return True to allow market to take over, false to block purchase.
|
||||
*/
|
||||
public bool:Market_OnWeaponSelected(client, String:weaponid[])
|
||||
{
|
||||
// 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 (IsPlayerZombie(client))
|
||||
{
|
||||
ZR_PrintToChat(client, "Zombie cant use weapon");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If player is using the rebuy option then allow
|
||||
if (StrEqual(weaponid, "rebuy"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
decl String:display[64];
|
||||
decl String:weapon[32];
|
||||
new price;
|
||||
|
||||
// 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
|
||||
ReplaceString(weapon, sizeof(weapon), "weapon_", "");
|
||||
|
||||
// If the weapon is restricted, then stop
|
||||
if (WeaponRestrictIsRestricted(weapon))
|
||||
{
|
||||
ZR_PrintToChat(client, "Weapon is restricted", weapon);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
ZR_PrintCenterText(client, "Market out of buyzone");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Market) Forward called one frame after a client selects a weapon from the market.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @param allowed True when the weapon was purchased successfully, false otherwise.
|
||||
*/
|
||||
public Market_PostOnWeaponSelected(client, &bool:allowed)
|
||||
{
|
||||
// If the purchase wasn't allowed, then stop
|
||||
if (!allowed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Resend market menu
|
||||
ZMarket(client);
|
||||
}
|
@ -7,12 +7,12 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Array to store restricted weapon names
|
||||
* Array to store restricted weapon names.
|
||||
*/
|
||||
new Handle:gRestrictedWeapons = INVALID_HANDLE;
|
||||
|
||||
/**
|
||||
* Array to store keyvalue data
|
||||
* Array to store keyvalue data.
|
||||
*/
|
||||
new Handle:kvWeaponGroups = INVALID_HANDLE;
|
||||
|
||||
@ -22,17 +22,17 @@ new Handle:kvWeaponGroups = INVALID_HANDLE;
|
||||
new gCanUseHookID[MAXPLAYERS+1];
|
||||
|
||||
/**
|
||||
* Query results returned when (un)restricting a weapon
|
||||
* Query results returned when (un)restricting a weapon.
|
||||
*/
|
||||
enum WpnRestrictQuery
|
||||
{
|
||||
Successful_Weapon, /** Weapon (un)restrict query was successful */
|
||||
Successful_Group, /** Group (un)restrict query was successful */
|
||||
Successful_Weapon, /** Weapon (un)restrict query was successful. */
|
||||
Successful_Group, /** Group (un)restrict query was successful. */
|
||||
Invalid, /** Weapon/Group invalid */
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize data and hook commands
|
||||
* Initialize data and hook commands.
|
||||
*/
|
||||
WeaponRestrictInit()
|
||||
{
|
||||
@ -44,7 +44,7 @@ WeaponRestrictInit()
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads weapon data from file
|
||||
* Loads weapon data from file.
|
||||
*/
|
||||
WeaponRestrictMapStart()
|
||||
{
|
||||
@ -69,7 +69,7 @@ WeaponRestrictMapStart()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears restricted weapon array
|
||||
* Clears restricted weapon array.
|
||||
*/
|
||||
RestrictWeaponUnrestrictAll()
|
||||
{
|
||||
@ -77,9 +77,9 @@ RestrictWeaponUnrestrictAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook Weapon_CanUse function on a client
|
||||
* Hook Weapon_CanUse function on a client.
|
||||
*
|
||||
* @param client The client index
|
||||
* @param client The client index.
|
||||
*/
|
||||
WeaponRestrictClientInit(client)
|
||||
{
|
||||
@ -87,9 +87,9 @@ WeaponRestrictClientInit(client)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhook Weapon_CanUse function on a client
|
||||
* Unhook Weapon_CanUse function on a client.
|
||||
*
|
||||
* @param client The client index
|
||||
* @param client The client index.
|
||||
*/
|
||||
WeaponRestrictClientDisconnect(client)
|
||||
{
|
||||
@ -98,10 +98,10 @@ WeaponRestrictClientDisconnect(client)
|
||||
|
||||
/**
|
||||
* Command callback function for the "buy" command
|
||||
* Used to block use of this command under certain conditions
|
||||
* Used to block use of this command under certain conditions.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @param argc Argument count
|
||||
* @param argc Argument count.
|
||||
*/
|
||||
public Action:WeaponRestrictBuyHook(client, argc)
|
||||
{
|
||||
@ -141,12 +141,12 @@ public Action:WeaponRestrictBuyHook(client, argc)
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricts a weapon
|
||||
* Restricts 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.
|
||||
* Invalid: The call was unsuccessful due to invalid weapon.
|
||||
* Invalid: The call was unsuccessful due to invalid weapon.
|
||||
*/
|
||||
WpnRestrictQuery:WeaponRestrictRestrict(const String:weapon[])
|
||||
{
|
||||
@ -183,7 +183,7 @@ WpnRestrictQuery:WeaponRestrictRestrict(const String:weapon[])
|
||||
}
|
||||
|
||||
/**
|
||||
* Unrestricts a weapon
|
||||
* Unrestricts a weapon.
|
||||
*
|
||||
* @param weapon The weapon/group name.
|
||||
* @return Successful_Weapon: The call successfully restricted a weapon.
|
||||
|
Reference in New Issue
Block a user