Skip to content

Commit

Permalink
Add weapon dropped callback
Browse files Browse the repository at this point in the history
Adds a callback for when a weapon is dropped.
In the progress this also fixes weapons still dropping unintentionally in certain case.
  • Loading branch information
NoCatt authored Feb 28, 2024
1 parent f2041fb commit 51eb5ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
20 changes: 4 additions & 16 deletions Northstar.CustomServers/mod/scripts/vscripts/_loadouts_mp.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ void function SvLoadoutsMP_Init()
AddClientCommandCallback( "InGameMPMenuClosed", ClientCommandCallback_InGameMPMenuClosed )
AddClientCommandCallback( "LoadoutMenuClosed", ClientCommandCallback_LoadoutMenuClosed )
}

AddCallback_OnPlayerKilled( DestroyDroppedWeapon )
}

void function SetLoadoutGracePeriodEnabled( bool enabled )
Expand All @@ -62,20 +60,10 @@ void function SetLoadoutGracePeriodEnabled( bool enabled )

void function SetWeaponDropsEnabled( bool enabled )
{
file.weaponDropsEnabled = enabled
}

void function DestroyDroppedWeapon( entity victim, entity attacker, var damageInfo )
{
if ( !file.weaponDropsEnabled && IsValid( victim.GetActiveWeapon() ) )
thread DelayDestroyDroppedWeapon( victim.GetActiveWeapon() )
}

void function DelayDestroyDroppedWeapon( entity weapon )
{
WaitEndFrame()
if ( IsValid( weapon ) )
weapon.Destroy()
if( enabled )
FlagSet( "WeaponDropsAllowed" )
else
FlagClear( "WeaponDropsAllowed" )
}

void function AddCallback_OnTryGetTitanLoadout( TryGetTitanLoadoutCallbackType callback )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void function BaseGametype_Init_MPSP()
AddCallback_OnPlayerKilled( CheckForAutoTitanDeath )
RegisterSignal( "PlayerRespawnStarted" )
RegisterSignal( "KillCamOver" )

FlagInit( "WeaponDropsAllowed", true )
}

void function SetIntermissionCamera( entity camera )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ global function CodeCallback_OnProjectileGrappled
global function DamageInfo_ScaleDamage
global function CodeCallback_CheckPassThroughAddsMods
global function SetTitanMeterGainScale
global function CodeCallback_WeaponDropped
global function AddCallback_OnWeaponDropped

#if MP
global function CodeCallback_OnServerAnimEvent
Expand All @@ -43,6 +45,7 @@ struct
]

table<entity, AccumulatedDamageData> playerAccumulatedDamageData
array< void functionref( entity ) > weaponDroppedCallbacks
} file

void function CodeCallback_Init()
Expand Down Expand Up @@ -1030,4 +1033,26 @@ void function CodeCallback_OnServerAnimEvent( entity ent, string eventName )

PerfEnd( PerfIndexServer.CB_OnServerAnimEvent )
}

void function AddCallback_OnWeaponDropped( void functionref( entity ) callback )
{
file.weaponDroppedCallbacks.append( callback )
}

void function CodeCallback_WeaponDropped( entity weapon )
{
// shamelessly taken form SP
if ( !IsValid( weapon ) )
return

// Might look a bit hacky to put it here, but thats how SP does it
if ( !Flag( "WeaponDropsAllowed" ) )
{
weapon.Destroy()
return
}

foreach( callback in file.weaponDroppedCallbacks )
callback( weapon )
}
#endif // #if MP

0 comments on commit 51eb5ea

Please sign in to comment.