Made a basic weapon API, fixed SetPlayerAlpha function, moved logging to its own file (had to be done now, it was hard to find before), made a separate cvar to disable logging fully.
This commit is contained in:
@ -86,9 +86,9 @@ RestrictOnMapStart()
|
||||
// If file isn't found, stop plugin.
|
||||
if (!FileToKeyValues(kvWeaponGroups, path))
|
||||
{
|
||||
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (LogCheckFlag(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
ZR_LogMessageFormatted(-1, "Weapons", "Config Validation", "Missing file weapongroups.txt.", LOG_FORMAT_TYPE_ERROR);
|
||||
LogMessageFormatted(-1, "Weapons", "Config Validation", "Missing file weapongroups.txt.", LOG_FORMAT_TYPE_ERROR);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -137,7 +137,7 @@ RestrictDefaultRestrictions()
|
||||
RestrictValidateWeaponGroups()
|
||||
{
|
||||
// If log flag check fails, don't log.
|
||||
if (!LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (!LogCheckFlag(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -165,7 +165,7 @@ RestrictValidateWeaponGroups()
|
||||
// If weapon is invalid, then log it.
|
||||
if (!WeaponsIsValidWeapon(groupweapon))
|
||||
{
|
||||
ZR_LogMessageFormatted(-1, "Weapon Restrict", "Config Validation", "Invalid weapon \"%s\" in group \"%s\" configured in weapongroups.txt.", LOG_FORMAT_TYPE_ERROR, groupweapon, weapongroup);
|
||||
LogMessageFormatted(-1, "Weapon Restrict", "Config Validation", "Invalid weapon \"%s\" in group \"%s\" configured in weapongroups.txt.", LOG_FORMAT_TYPE_ERROR, groupweapon, weapongroup);
|
||||
}
|
||||
} while (KvGotoNextKey(kvWeaponGroups));
|
||||
|
||||
@ -174,7 +174,7 @@ RestrictValidateWeaponGroups()
|
||||
// If it couldn't traverse to the weapons, then log no weapons within group.
|
||||
else
|
||||
{
|
||||
ZR_LogMessageFormatted(-1, "Weapon Restrict", "Config Validation", "No weapons listed in weapon group \"%s\" in weapongroups.txt.", LOG_FORMAT_TYPE_ERROR, weapongroup);
|
||||
LogMessageFormatted(-1, "Weapon Restrict", "Config Validation", "No weapons listed in weapon group \"%s\" in weapongroups.txt.", LOG_FORMAT_TYPE_ERROR, weapongroup);
|
||||
}
|
||||
} while (KvGotoNextKey(kvWeaponGroups));
|
||||
}
|
||||
@ -439,9 +439,9 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
|
||||
{
|
||||
ZR_PrintToChat(0, "Restrict weapon", weapon);
|
||||
|
||||
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (LogCheckFlag(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
ZR_LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
}
|
||||
}
|
||||
// Weapon group was successfully restricted.
|
||||
@ -452,9 +452,9 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
|
||||
|
||||
ZR_PrintToChat(0, "Restrict custom weapon group", weapon, weaponlist);
|
||||
|
||||
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (LogCheckFlag(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
ZR_LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
LogMessageFormatted(client, "Weapon Restrict", "Restrict", "\"%L\" restricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
}
|
||||
}
|
||||
// Weapon was already restricted.
|
||||
@ -515,9 +515,9 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
|
||||
{
|
||||
ZR_PrintToChat(0, "Unrestrict weapon", weapon);
|
||||
|
||||
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (LogCheckFlag(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
ZR_LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
}
|
||||
}
|
||||
// Weapon group was successfully unrestricted.
|
||||
@ -528,9 +528,9 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
|
||||
|
||||
ZR_PrintToChat(0, "Unrestrict custom weapon group", weapon, weaponlist);
|
||||
|
||||
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (LogCheckFlag(LOG_GAME_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
ZR_LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
LogMessageFormatted(client, "Weapon Restrict", "Unrestrict", "\"%L\" unrestricted weapon group: \"%s\".", LOG_FORMAT_TYPE_FULL, client, weapon);
|
||||
}
|
||||
}
|
||||
// Weapon wasn't restricted.
|
||||
|
@ -13,11 +13,28 @@
|
||||
* Maximum length of a weapon name string
|
||||
*/
|
||||
#define WEAPONS_MAX_LENGTH 32
|
||||
|
||||
/**
|
||||
* @endsection
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Number of weapon slots (For CS:S)
|
||||
*/
|
||||
#define WEAPONS_SLOTS_MAX 5
|
||||
|
||||
/**
|
||||
* Weapon types.
|
||||
*/
|
||||
enum WeaponsType
|
||||
{
|
||||
Type_Invalid = -1,
|
||||
Type_Primary = 0,
|
||||
Type_Secondary = 1,
|
||||
Type_Melee = 2,
|
||||
Type_Projectile = 3,
|
||||
Type_Explosive = 4,
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to store keyvalue data.
|
||||
*/
|
||||
@ -71,9 +88,9 @@ WeaponsLoad()
|
||||
// If file isn't found, stop plugin.
|
||||
if (!FileToKeyValues(kvWeapons, path))
|
||||
{
|
||||
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (LogCheckFlag(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
ZR_LogMessageFormatted(-1, "Weapons", "Config Validation", "Missing file weapons.txt, disabling weapons-based modules.", LOG_FORMAT_TYPE_ERROR);
|
||||
LogMessageFormatted(-1, "Weapons", "Config Validation", "Missing file weapons.txt.", LOG_FORMAT_TYPE_ERROR);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -92,7 +109,7 @@ WeaponsLoad()
|
||||
WeaponsValidateConfig()
|
||||
{
|
||||
// If log flag check fails, don't log.
|
||||
if (!LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
if (!LogCheckFlag(LOG_CORE_EVENTS, LOG_MODULE_WEAPONS))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -100,7 +117,7 @@ WeaponsValidateConfig()
|
||||
KvRewind(kvWeapons);
|
||||
if (!KvGotoFirstSubKey(kvWeapons))
|
||||
{
|
||||
ZR_LogMessageFormatted(-1, "Weapons", "Config Validation", "No weapons listed in weapons.txt, disabling weapons-based modules.", LOG_FORMAT_TYPE_ERROR);
|
||||
LogMessageFormatted(-1, "Weapons", "Config Validation", "No weapons listed in weapons.txt.", LOG_FORMAT_TYPE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,4 +292,70 @@ Float:WeaponGetWeaponKnockback(const String:weapon[])
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* General weapon API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return an array that contains all client's weapon indexes.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @param weapons The weapon index array.
|
||||
* -1 if no weapon in slot.
|
||||
*/
|
||||
WeaponsGetClientWeapons(client, weapons[WeaponsType])
|
||||
{
|
||||
// x = weapon slot.
|
||||
for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
|
||||
{
|
||||
weapons[x] = GetPlayerWeaponSlot(client, x);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns weapon index of the client's deployed weapon.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @return The weapon index of the deployed weapon.
|
||||
* -1 if no weapon is deployed.
|
||||
*/
|
||||
WeaponsGetDeployedWeaponIndex(client)
|
||||
{
|
||||
// Return the client's active weapon.
|
||||
return GetEntDataEnt2(client, offsActiveWeapon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns slot of client's deployed weapon.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @return The slot number of deployed weapon.
|
||||
*/
|
||||
WeaponsType:WeaponsGetDeployedWeaponSlot(client)
|
||||
{
|
||||
// Get all client's weapon indexes.
|
||||
new weapons[WeaponsType];
|
||||
WeaponsGetClientWeapons(client, weapons);
|
||||
|
||||
// Get client's deployed weapon.
|
||||
new deployedweapon = WeaponsGetDeployedWeaponIndex(client);
|
||||
|
||||
// If client has no deployed weapon, then stop.
|
||||
if (deployedweapon == -1)
|
||||
{
|
||||
return Type_Invalid;
|
||||
}
|
||||
|
||||
// x = weapon slot.
|
||||
for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
|
||||
{
|
||||
if (weapons[x] == deployedweapon)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
return Type_Invalid;
|
||||
}
|
Reference in New Issue
Block a user