This is a very simple extension to expose some functionality that cannot currently be accessed via Sourcemod directly.
Currently 3 forwards are exposed.
Code:
/**
* @brief Called to determine if a player can use a given weapon
*
* @param client A client index
* @param weapon The classname of the weapon
* @return Plugin_Handled to block usage, Plugin_Continue to allow it.
*/
forward Action:Weapon_CanUse(client, const String:weapon[]);
/**
* @brief Called when the active weapon changes
*
* @param client A client index
* @param oldWeapon The weapon entity index of the weapon switching from
* @param newWeapon The weapon entity index of the weapon switching to
* @return None
*/
forward OnChangeActiveWeapon(client, oldWeapon, newWeapon);
/**
* @brief Called to determine if a player can switch to a given weapon
*
* @param client A client index
* @param weapon The classname of the weapon
* @return Plugin_Handled to block usage, Plugin_Continue to allow it.
*/
forward Action:Weapon_CanSwitchTo(client, const String:weapon[]);
I would warn the OnChangeActiveWeapon() probably doesn't do what you would expect. I left it in because it can be used to catch certain events.
The focus with this extension is simplicity, I tried to make these functions as simple as possible to use. In doing so I have sacrificed some of the flexibility and power that something like the hacks extension has.
I will be adding to this over time so let me know if you need anything specific.
I believe that the ability to hook virtual forwards is something that will eventually be added to sourcemod but this is intended to help in the interim.
Instructions:
Copy the extension to your addons/sourcemod/extensions directory and include the include file in your plugin. You also need to copy the weapons.games.txt file to your addons/sourcemod/gamedata directory.
The
source code is also available.
Supported Mods:
Counter Strike: Source
Day of Defeat: Source
Halflife2: Deathmatch
Sourceforts
Pirates, Vikings and Knights
Insurgency(Weapon_CanUse and Weapon_CanSwitchTo only)