-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Client Side Callback Hooks #779
base: main
Are you sure you want to change the base?
Conversation
Note to self that this adds vanilla files which will need to be committed first before merge |
Just to be clear, this would basically replace |
Correct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine in testing
https://github.com/user-attachments/assets/11818cae-f92e-4352-a47a-09ca9c474ee6
Script used:
untyped
global function testcallbacks_Init
void function testcallbacks_Init()
{
#if MP
AddCallback_OnPlayerKilled ( testcallbacks_player)
AddCallback_OnEntityKilled ( testcallbacks_entity)
#endif
AddCallback_OnUsedCore ( testcallbacks_core)
AddCallback_OnLocalPlayerDidDamage( testcallbacks_damage )
}
#if MP
void function testcallbacks_player( ObituaryCallbackParams params )
{
printt( "------------------" )
printt( "ow" )
printt( "------------------" )
}
void function testcallbacks_entity( ObituaryCallbackParams params )
{
printt( "------------------" )
printt( "oof" )
printt( "------------------" )
}
#endif
void function testcallbacks_core(entity player, entity titan)
{
printt( "------------------" )
printt( "ouch" )
printt( "------------------" )
}
void function testcallbacks_damage( PlayerDidDamageParams params )
{
printt( "------------------" )
printt( "owie" )
printt( "------------------" )
}
Another example:
untyped
global function SniperVGUI_Init
void function SniperVGUI_Init()
{
AddCallback_OnLocalPlayerDidDamage( SniperVGUI_DidDamage)
}
void function SniperVGUI_DidDamage( PlayerDidDamageParams params )
{
entity attacker = GetLocalViewPlayer()
if ( !IsValid( attacker ) )
return
entity victim = params.victim
if ( !IsValid( victim ) )
return
int damageType = params.damageType
int hitGroup = params.hitGroup
bool isCritShot = (damageType & DF_CRITICAL) ? true : false
entity activeweapon = attacker.GetActiveWeapon()
var isSniper
if ( IsValid (activeweapon) )
isSniper = activeweapon.GetWeaponInfoFileKeyField( "is_sniper" )
if ( !attacker.IsTitan() )
{
// Reapers only have the "chest" hitgroup so it looks bad
if (!victim.IsTitan() && !IsSuperSpectre( victim ) && victim.GetSignifierName() != "npc_turret_mega" )
{
if ( hitGroup != HITGROUP_GENERIC && isSniper )
attacker.Signal( "UpdateSniperVGUI", { hitGroup = hitGroup } )
}
else if (victim.IsTitan() )
{
if ( hitGroup == HITGROUP_GENERIC || isCritShot && isSniper )
attacker.Signal( "UpdateSniperVGUI", { hitGroup = hitGroup } )
}
}
}
I'd also like to add that i have a mod that would benefit from the OnLocalPlayerDidDamage
callback, since it currently overrides cl_player.gnut
and cl_sp_player.gnut
to make my changes.
Pretty much the only complaint i have, is that there should also be a OnLocalPlayerDidDamage
callback in cl_sp_player.gnut
, since trying to load into sp causes an error.
@@ -0,0 +1,647 @@ | |||
untyped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire file should probably be moved to Northstar.Custom
, since its a shared script
This change adds a few new global functions for registering client side callback functions as well as implementation for the callbacks. Specifically, the code from S2.ClientKillCallback is added to allow for easier installation of mods that depend on these features. Addtionally, callbacks that trigger when any entity is killed regardless of the type have been added. Similarly callback handlers are added to
cl_player.gnut
andweapons/sh_titancore_utility.gnut
to allow callbacks when the player does damage or uses a titan core.To register a new callback, the following functions can be used:
AddCallback_OnPlayerKilled
- passes an instance of theObituaryCallbackParams
struct to the callbackAddCallback_OnEntityKilled
- passes an instance of theObituaryCallbackParams
struct to the callbackAddCallback_OnUsedCore
- passes the titan and weapon entities being used to the callback in that orderAddCallback_OnLocalPlayerDidDamage
- passes an instance ofPlayerDidDamageParams
to the callback