Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

SDarkMagic
Copy link

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 and weapons/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 the ObituaryCallbackParams struct to the callback
  • AddCallback_OnEntityKilled - passes an instance of the ObituaryCallbackParams struct to the callback
  • AddCallback_OnUsedCore - passes the titan and weapon entities being used to the callback in that order
  • AddCallback_OnLocalPlayerDidDamage - passes an instance of PlayerDidDamageParams to the callback

@GeckoEidechse
Copy link
Member

GeckoEidechse commented Jan 8, 2024

Note to self that this adds vanilla files which will need to be committed first before merge

@GeckoEidechse
Copy link
Member

Just to be clear, this would basically replace S2.ClientCallback by integrating it into Northstar, right? ^^

@GeckoEidechse GeckoEidechse added the feedback wanted Feedback is wanted whether the changes by this PR are desired label Jan 23, 2024
@SDarkMagic
Copy link
Author

Correct

Copy link
Contributor

@NachosChipeados NachosChipeados left a 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.
image

@GeckoEidechse GeckoEidechse added needs code review Changes from PR still need to be reviewed in code almost ready to merge Apart from any small remaining other issues addressed by other labels, this would be ready to merge labels Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
almost ready to merge Apart from any small remaining other issues addressed by other labels, this would be ready to merge feedback wanted Feedback is wanted whether the changes by this PR are desired needs code review Changes from PR still need to be reviewed in code
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants