Adds OnWeaponAttackCallbacks (#983)

* remove thread that breaks boosts

* add OnWeaponAttack callbacks

* add to file struct

---------

Co-authored-by: cat_or_not <41955154+catornot@users.noreply.github.com>
This commit is contained in:
Allusive 2026-03-21 20:15:03 -07:00 committed by GitHub
parent 94fabac8f9
commit 672a3f5fc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,6 +25,10 @@ global function CodeCallback_WeaponDropped
global function AddCallback_OnWeaponDropped
#endif
global function CodeCallback_OnWeaponAttack
global function AddCallback_OnWeaponAttack
global function RemoveCallback_OnWeaponAttack
struct AccumulatedDamageData
{
float accumulatedDamage
@ -46,6 +50,7 @@ struct
table<entity, AccumulatedDamageData> playerAccumulatedDamageData
array< void functionref( entity ) > weaponDroppedCallbacks
array< void functionref( entity, entity, string, int ) > weaponAttackCallbacks
} file
void function CodeCallback_Init()
@ -1055,4 +1060,24 @@ void function CodeCallback_WeaponDropped( entity weapon )
foreach( callback in file.weaponDroppedCallbacks )
callback( weapon )
}
#endif // #if MP
#endif // #if MP
void function AddCallback_OnWeaponAttack( void functionref( entity player, entity weapon, string weaponName, int attackIndex ) callbackFunc )
{
Assert( !file.weaponAttackCallbacks.contains( callbackFunc ), "Already added " + string( callbackFunc ) + " with AddCallback_OnWeaponAttackCallback" )
file.weaponAttackCallbacks.append( callbackFunc )
}
void function RemoveCallback_OnWeaponAttack( void functionref( entity player, entity weapon, string weaponName, int attackIndex ) callbackFunc )
{
Assert( file.weaponAttackCallbacks.contains( callbackFunc ), "Tried to remove " + string( callbackFunc ) + " with RemoveCallback_OnWeaponAttackCallback but it was not found" )
file.weaponAttackCallbacks.fastremovebyvalue( callbackFunc )
}
void function CodeCallback_OnWeaponAttack(entity player, entity weapon, string weaponName,int shotsFired)
{
foreach ( callbackFunc in file.weaponAttackCallbacks )
{
callbackFunc( player, weapon, weaponName, shotsFired )
}
}