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 PlayerAssist callback logic #908

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,29 @@ bool function PlayerOrNPCKilled( entity ent, var damageInfo )
ScoreEvent_TitanKilled( ent, attacker, damageInfo )
else
ScoreEvent_NPCKilled( ent, attacker, damageInfo )

entity victim = ent.IsTitan() ? ent.GetTitanSoul() : ent
if ( IsValid( victim ) )
{
table<int, bool> alreadyAssisted

foreach( DamageHistoryStruct attackerInfo in victim.e.recentDamageHistory )
{
if ( !IsValid( attackerInfo.attacker ) || !attackerInfo.attacker.IsPlayer() || attackerInfo.attacker == victim )
continue

bool exists = attackerInfo.attacker.GetEncodedEHandle() in alreadyAssisted ? true : false
if( attackerInfo.attacker != attacker && !exists )
{
alreadyAssisted[attackerInfo.attacker.GetEncodedEHandle()] <- true
foreach ( player in GetPlayerArray() )
Remote_CallFunction_Replay( player, "ServerCallback_SetAssistInformation", attackerInfo.damageSourceId, attacker.GetEncodedEHandle(), ent.GetEncodedEHandle(), attackerInfo.time )

foreach ( callback in svGlobal.onPlayerAssistCallbacks )
callback( attackerInfo.attacker, victim )
}
}
}
}
PostScoreEventUpdateStats( attacker, ent )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void function BaseGametype_Init_MPSP()

AddCallback_OnNPCKilled( CheckForAutoTitanDeath )
AddCallback_OnPlayerKilled( CheckForAutoTitanDeath )
AddCallback_OnPlayerAssist( PlayerAssistedKill )
RegisterSignal( "PlayerRespawnStarted" )
RegisterSignal( "KillCamOver" )

Expand Down Expand Up @@ -250,6 +251,18 @@ void function CodeCallback_OnPlayerRespawned( entity player )
ClearLastAttacker( player ) // so dying to anything doesn't credit the same attacker after respawning
}

void function PlayerAssistedKill( entity attacker, entity victim )
{
if( victim.IsPlayer() )
{
AddPlayerScore( attacker, "PilotAssist" )
attacker.AddToPlayerGameStat( PGS_ASSISTS, 1 )

if ( attacker.IsPlayer() )
Highlight_SetDeathRecapHighlight( attacker, "killer_outline" )
}
}

void function CodeCallback_OnPlayerKilled( entity player, var damageInfo )
{
PlayerOrNPCKilled( player, damageInfo )
Expand Down Expand Up @@ -307,28 +320,6 @@ void function PostDeathThread_MP( entity player, var damageInfo ) // based on ga
eHandle = inflictor.GetEncodedEHandle()
int methodOfDeath = DamageInfo_GetDamageSourceIdentifier( damageInfo )

table<int, bool> alreadyAssisted
if ( IsValid( attacker ) )
{
foreach( DamageHistoryStruct attackerInfo in player.e.recentDamageHistory )
{
if ( !IsValid( attackerInfo.attacker ) || !attackerInfo.attacker.IsPlayer() || attackerInfo.attacker == player )
continue

bool exists = attackerInfo.attacker.GetEncodedEHandle() in alreadyAssisted ? true : false
if( attackerInfo.attacker != attacker && !exists )
{
alreadyAssisted[attackerInfo.attacker.GetEncodedEHandle()] <- true
Remote_CallFunction_NonReplay( attackerInfo.attacker, "ServerCallback_SetAssistInformation", attackerInfo.damageSourceId, attacker.GetEncodedEHandle(), player.GetEncodedEHandle(), attackerInfo.time )
AddPlayerScore( attackerInfo.attacker, "PilotAssist" )
attackerInfo.attacker.AddToPlayerGameStat( PGS_ASSISTS, 1 )
}
}

if( attacker.IsPlayer() )
Highlight_SetDeathRecapHighlight( attacker, "killer_outline" )
}

player.p.rematchOrigin = player.p.deathOrigin
if ( IsValid( attacker ) && methodOfDeath == eDamageSourceId.titan_execution )
{
Expand Down
30 changes: 10 additions & 20 deletions Northstar.CustomServers/mod/scripts/vscripts/mp/_score.nut
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void function Score_Init()
{
SvXP_Init()
AddCallback_OnClientConnected( InitPlayerForScoreEvents )
AddCallback_OnPlayerAssist( TitanAssistedKill )
}

void function InitPlayerForScoreEvents( entity player )
Expand Down Expand Up @@ -216,30 +217,19 @@ void function ScoreEvent_TitanKilled( entity victim, entity attacker, var damage
AddPlayerScore( attacker, "KillTitan" )
}

entity soul = victim.GetTitanSoul()
if ( IsValid( soul ) )
{
table<int, bool> alreadyAssisted

foreach( DamageHistoryStruct attackerInfo in soul.e.recentDamageHistory )
{
if ( !IsValid( attackerInfo.attacker ) || !attackerInfo.attacker.IsPlayer() || attackerInfo.attacker == soul )
continue

bool exists = attackerInfo.attacker.GetEncodedEHandle() in alreadyAssisted ? true : false
if( attackerInfo.attacker != attacker && !exists )
{
alreadyAssisted[attackerInfo.attacker.GetEncodedEHandle()] <- true
AddPlayerScore(attackerInfo.attacker, "TitanAssist" )
Remote_CallFunction_NonReplay( attackerInfo.attacker, "ServerCallback_SetAssistInformation", attackerInfo.damageSourceId, attacker.GetEncodedEHandle(), soul.GetEncodedEHandle(), attackerInfo.time )
}
}
}

if( !victim.IsNPC() ) // don't let killing a npc titan plays dialogue
KilledPlayerTitanDialogue( attacker, victim )
}

void function TitanAssistedKill( entity attacker, entity victim )
{
if ( IsSoul( victim ) )
{
AddPlayerScore( attacker, "TitanAssist" )
attacker.AddToPlayerGameStat( PGS_ASSISTS, 1 )
}
}

void function ScoreEvent_NPCKilled( entity victim, entity attacker, var damageInfo )
{
try
Expand Down
Loading