From b21f9cd6bf612edb2faa164c0d2154647a5e1a89 Mon Sep 17 00:00:00 2001 From: Patrick Liesveld Date: Mon, 15 Aug 2016 16:22:31 -0400 Subject: [PATCH 1/5] Adds support for recording arrows --- sizzlingstats/LogStats.cpp | 48 ++++++++++++++++++++++++++++ sizzlingstats/SSPlayerData.cpp | 2 ++ sizzlingstats/SSPlayerData.h | 10 ++++-- sizzlingstats/SizzlingStats.cpp | 25 +++++++++++++++ sizzlingstats/SizzlingStats.h | 1 + sizzlingstats/WebStatsHandler.cpp | 2 ++ sizzlingstats/serverplugin_empty.cpp | 25 ++++++++++++++- 7 files changed, 109 insertions(+), 4 deletions(-) diff --git a/sizzlingstats/LogStats.cpp b/sizzlingstats/LogStats.cpp index da8974e..7676c6c 100644 --- a/sizzlingstats/LogStats.cpp +++ b/sizzlingstats/LogStats.cpp @@ -88,6 +88,7 @@ bool CLogStats::Load( CSizzPluginContext &plugin_context ) m_context->AddListener( this, "item_pickup", true ); m_context->AddListener( this, "player_hurt", true ); m_context->AddListener( this, "player_healed", true ); + m_context->AddListener( this, "arrow_impact", true ); m_context->AddListener( this, "player_spawn", true ); m_context->AddListener( this, "player_team", true ); m_context->AddListener( this, "player_changename", true ); @@ -275,6 +276,53 @@ void CLogStats::FireGameEvent( IGameEvent *event ) WriteLog( log ); //L 03/21/2011 - 02:35:56: "GooB<330>" picked up item "tf_ammo_pack" } + else if ( FStrEq( name, "arrow_impact" ) ) + { + // Only count crusader's crossbow + if ( event->GetInt("projectileType") == 11 ) + { + + int healer = event->GetInt( "shooter" ); + playerInfo &pInfo1 = m_entIndexToPlayerInfo[healer]; + + int patient = event->GetInt( "attachedEntity" ); + playerInfo &pInfo2 = m_entIndexToPlayerInfo[patient]; + + + // Only count arrows for alive players and on the same team + if (pInfo1.pPlayerInfo->IsPlayer() && !pInfo1.pPlayerInfo->IsDead() + && pInfo2.pPlayerInfo->IsPlayer() && !pInfo2.pPlayerInfo->IsDead() + && pInfo1.teamid == pInfo2.teamid) + { + vec_t distance = pInfo1.pPlayerInfo->GetAbsOrigin().DistTo(pInfo2.pPlayerInfo->GetAbsOrigin()); + + if ( pInfo1.steamid[0] == '\0' ) + { + m_context->GetSteamIDString(pInfo1.userid, pInfo1.steamid, sizeof(pInfo1.steamid)); + } + + if ( pInfo2.steamid[0] == '\0' ) + { + m_context->GetSteamIDString(pInfo2.userid, pInfo2.steamid, sizeof(pInfo2.steamid)); + } + + char log[196]; + Q_snprintf( log, 196, "\"%s<%d><%s><%s>\" triggered \"arrow_impact\" against \"%s<%d><%s><%s> (distance \"%.2f\")\"\n", + pInfo1.name, + healer, + pInfo1.steamid, + teamNames[pInfo1.teamid], + pInfo2.name, + patient, + pInfo2.steamid, + teamNames[pInfo2.teamid], + distance ); + WriteLog( log ); + // L 08/15/2016 - 15:47:39: "happs<1><[U:1:20443063]>" triggered "arrow_impact" against "Chell<2> (distance "822.21")" + } + } + + } else if ( FStrEq( name, "player_spawn" ) ) { int userid = event->GetInt( "userid" ); diff --git a/sizzlingstats/SSPlayerData.cpp b/sizzlingstats/SSPlayerData.cpp index a75e5a5..7049a64 100644 --- a/sizzlingstats/SSPlayerData.cpp +++ b/sizzlingstats/SSPlayerData.cpp @@ -61,6 +61,8 @@ void SS_PlayerData::UpdateRoundExtraData( const extradata_t &dat ) m_RoundScoreData.data[MedPicks] = dat.medpicks; m_RoundScoreData.data[UbersDropped] = dat.ubersdropped; m_RoundScoreData.data[OverkillDamage] = dat.overkillDamage; + m_RoundScoreData.data[ArrowsLanded] = dat.arrowslanded; + m_RoundScoreData.data[ArrowsReceived] = dat.arrowsrecv; } int SS_PlayerData::GetStat( int StatID ) diff --git a/sizzlingstats/SSPlayerData.h b/sizzlingstats/SSPlayerData.h index afb0d67..10ec6ab 100644 --- a/sizzlingstats/SSPlayerData.h +++ b/sizzlingstats/SSPlayerData.h @@ -44,15 +44,15 @@ enum stats MedPicks, UbersDropped, OverkillDamage, - ShotsFired, - ShotsHit, + ArrowsLanded, + ArrowsReceived, NumOfStats }; typedef struct extradata_s { extradata_s(): - healsrecv(0), medpicks(0), ubersdropped(0), overkillDamage(0) + healsrecv(0), medpicks(0), ubersdropped(0), overkillDamage(0), arrowslanded(0), arrowsrecv(0) { } @@ -62,6 +62,8 @@ typedef struct extradata_s medpicks = a; ubersdropped = a; overkillDamage = a; + arrowslanded = a; + arrowsrecv = a; return *this; } @@ -69,6 +71,8 @@ typedef struct extradata_s short medpicks; short ubersdropped; int overkillDamage; + short arrowslanded; + short arrowsrecv; } extradata_t; struct ScoreData diff --git a/sizzlingstats/SizzlingStats.cpp b/sizzlingstats/SizzlingStats.cpp index 8504d69..9e4418c 100644 --- a/sizzlingstats/SizzlingStats.cpp +++ b/sizzlingstats/SizzlingStats.cpp @@ -131,6 +131,15 @@ void SizzlingStats::PlayerHealed( int entindex, int amount ) data.m_pExtraData->healsrecv += amount; } +void SizzlingStats::PlayerArrowed( int patientEntIndex, int medicEntIndex, float distance ) +{ + playerAndExtra_t medic_data = m_PlayerDataManager.GetPlayerData(medicEntIndex); + medic_data.m_pExtraData->arrowslanded += 1; + + playerAndExtra_t data = m_PlayerDataManager.GetPlayerData(medicEntIndex); + data.m_pExtraData->arrowsrecv += 1; +} + void SizzlingStats::MedPick( int entindex ) { playerAndExtra_t data = m_PlayerDataManager.GetPlayerData(entindex); @@ -512,6 +521,8 @@ void SizzlingStats::SS_DisplayStats( CSizzPluginContext *pPluginContext, int ent int ubers = playerData.GetStat(Invulns); int drops = playerData.GetStat(UbersDropped); int medpicks = playerData.GetStat(MedPicks); + int arrowsLanded = playerData.GetStat(ArrowsLanded); + int arrowsReceived = playerData.GetStat(ArrowsReceived); IPlayerInfo *pPlayerInfo = pPluginContext->GetPlayerInfo(ent_index); CTFPlayerWrapper player(pPluginContext->BaseEntityFromEntIndex(ent_index)); @@ -549,6 +560,13 @@ void SizzlingStats::SS_DisplayStats( CSizzPluginContext *pPluginContext, int ent SS_SingleUserChatMessage(pPluginContext, ent_index, pText); } + if ( arrowsReceived != 0 ) + { + memset( pText, 0, sizeof(pText) ); + V_snprintf( pText, 64, "Arrows Received: %i\n", arrowsReceived ); + SS_SingleUserChatMessage(pPluginContext, ent_index, pText); + } + if ( medpicks != 0 ) { memset( pText, 0, sizeof(pText) ); @@ -556,6 +574,13 @@ void SizzlingStats::SS_DisplayStats( CSizzPluginContext *pPluginContext, int ent SS_SingleUserChatMessage(pPluginContext, ent_index, pText); } + if ( arrowsLanded != 0 ) + { + memset( pText, 0, sizeof(pText) ); + V_snprintf( pText, 64, "Arrows Landed: %i\n", arrowsLanded ); + SS_SingleUserChatMessage(pPluginContext, ent_index, pText); + } + if ( (backstabs != 0) && (headshots != 0) ) { memset( pText, 0, sizeof(pText) ); diff --git a/sizzlingstats/SizzlingStats.h b/sizzlingstats/SizzlingStats.h index 54bbc3c..fbb0c01 100644 --- a/sizzlingstats/SizzlingStats.h +++ b/sizzlingstats/SizzlingStats.h @@ -51,6 +51,7 @@ class SizzlingStats void LoadConfig( CSizzPluginContext *pPluginContext ); void PlayerHealed( int entindex, int amount ); + void PlayerArrowed( int patientEntIndex, int medicEntIndex, float distance ); void MedPick( int entindex ); void UberDropped( int entindex ); void OnPlayerDeath(int inflictorEntIndex, int victimEntIndex); diff --git a/sizzlingstats/WebStatsHandler.cpp b/sizzlingstats/WebStatsHandler.cpp index 9a541dc..502d3cd 100644 --- a/sizzlingstats/WebStatsHandler.cpp +++ b/sizzlingstats/WebStatsHandler.cpp @@ -300,6 +300,8 @@ void CWebStatsHandler::producePostString(const hostInfo_t &host, const CUtlVecto jsonWriter.InsertKV("medpicks", pScores->getStat(MedPicks)); jsonWriter.InsertKV("ubersdropped", pScores->getStat(UbersDropped)); jsonWriter.InsertKV("overkillDamage", pScores->getStat(OverkillDamage)); + jsonWriter.InsertKV("arrowsLanded", pScores->getStat(ArrowsLanded)); + jsonWriter.InsertKV("arrowsReceived", pScores->getStat(ArrowsReceived)); jsonWriter.EndObject(); } } diff --git a/sizzlingstats/serverplugin_empty.cpp b/sizzlingstats/serverplugin_empty.cpp index dca683e..4c95948 100644 --- a/sizzlingstats/serverplugin_empty.cpp +++ b/sizzlingstats/serverplugin_empty.cpp @@ -291,6 +291,9 @@ bool CEmptyServerPlugin::Load( CreateInterfaceFn interfaceFactory, CreateInterfa // player healed (not incl buffs) m_plugin_context.AddListener( this, "player_healed", true ); + + // player arrowed (crusader, same team only) + m_plugin_context.AddListener( this, "arrow_impact", true ); // happens when mp_winlimit or mp_timelimit is met or something i don't know, i forget m_plugin_context.AddListener( this, "teamplay_game_over", true ); @@ -514,7 +517,7 @@ void CEmptyServerPlugin::GameFrame( bool simulating ) { using namespace Teamplay_GameRule_States; - //Msg( UTIL_VarArgs( "round state is now %s\n", GetStateName(state) ) ); + //Msg( UTIL_VarArgs( "round state is now %s\n", GetStateName((gamerules_roundstate_t)roundstate) ) ); switch (roundstate) { case GR_STATE_PREROUND: @@ -841,6 +844,26 @@ void CEmptyServerPlugin::FireGameEvent( IGameEvent *event ) } } } + else if ( m_bShouldRecord && FStrEq( name, "arrow_impact" ) ) + { + if (event->GetInt("projectileType") == 11) // crusader's crossbow + { + const int victim = event->GetInt("attachedEntity"); + const int medic = event->GetInt("shooter"); + if (victim > 0 && medic > 0) + { + IPlayerInfo *pVictim = m_plugin_context.GetPlayerInfo( victim ); + IPlayerInfo *pMedic = m_plugin_context.GetPlayerInfo( medic ); + // same team + if (pVictim && pMedic && pVictim->GetTeamIndex() == pMedic->GetTeamIndex()) + { + vec_t distance = sqrt(pVictim->GetAbsOrigin().DistToSqr(pMedic->GetAbsOrigin())); + m_SizzlingStats.PlayerArrowed(victim, medic, distance); + } + } + } + + } else if ( m_bShouldRecord && FStrEq( name, "player_death" ) ) { const int victim = event->GetInt("victim_entindex"); From 3193fc11961b55d3c002d717f2351b51ad8d7aa7 Mon Sep 17 00:00:00 2001 From: Patrick Liesveld Date: Mon, 22 Aug 2016 11:07:54 -0400 Subject: [PATCH 2/5] PR feedback removed magic number usage distance calculations use DistTo --- sizzlinglib/include/SizzPluginContext.h | 1 + sizzlingstats/LogStats.cpp | 2 +- sizzlingstats/serverplugin_empty.cpp | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sizzlinglib/include/SizzPluginContext.h b/sizzlinglib/include/SizzPluginContext.h index e0d39ac..f6bfe56 100644 --- a/sizzlinglib/include/SizzPluginContext.h +++ b/sizzlinglib/include/SizzPluginContext.h @@ -274,4 +274,5 @@ class CSizzPluginContext ConVarRef m_refRedTeamName; }; +const int sCrusadersCrossbowType = 11; #endif // SIZZ_PLUGIN_CONTEXT_H diff --git a/sizzlingstats/LogStats.cpp b/sizzlingstats/LogStats.cpp index 7676c6c..7911f7a 100644 --- a/sizzlingstats/LogStats.cpp +++ b/sizzlingstats/LogStats.cpp @@ -279,7 +279,7 @@ void CLogStats::FireGameEvent( IGameEvent *event ) else if ( FStrEq( name, "arrow_impact" ) ) { // Only count crusader's crossbow - if ( event->GetInt("projectileType") == 11 ) + if ( event->GetInt("projectileType") == sCrusadersCrossbowType ) { int healer = event->GetInt( "shooter" ); diff --git a/sizzlingstats/serverplugin_empty.cpp b/sizzlingstats/serverplugin_empty.cpp index 4c95948..47d7f55 100644 --- a/sizzlingstats/serverplugin_empty.cpp +++ b/sizzlingstats/serverplugin_empty.cpp @@ -846,7 +846,7 @@ void CEmptyServerPlugin::FireGameEvent( IGameEvent *event ) } else if ( m_bShouldRecord && FStrEq( name, "arrow_impact" ) ) { - if (event->GetInt("projectileType") == 11) // crusader's crossbow + if (event->GetInt("projectileType") == sCrusadersCrossbowType) { const int victim = event->GetInt("attachedEntity"); const int medic = event->GetInt("shooter"); @@ -854,10 +854,10 @@ void CEmptyServerPlugin::FireGameEvent( IGameEvent *event ) { IPlayerInfo *pVictim = m_plugin_context.GetPlayerInfo( victim ); IPlayerInfo *pMedic = m_plugin_context.GetPlayerInfo( medic ); - // same team + if (pVictim && pMedic && pVictim->GetTeamIndex() == pMedic->GetTeamIndex()) { - vec_t distance = sqrt(pVictim->GetAbsOrigin().DistToSqr(pMedic->GetAbsOrigin())); + vec_t distance = pVictim->GetAbsOrigin().DistTo(pMedic->GetAbsOrigin()); m_SizzlingStats.PlayerArrowed(victim, medic, distance); } } From 9bb8d29508f4ee4c3b0a402a530d8bde7aa80269 Mon Sep 17 00:00:00 2001 From: Patrick Liesveld Date: Mon, 22 Aug 2016 20:37:31 -0400 Subject: [PATCH 3/5] Bug fix in counting arrows --- sizzlingstats/SizzlingStats.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sizzlingstats/SizzlingStats.cpp b/sizzlingstats/SizzlingStats.cpp index 9e4418c..fd86541 100644 --- a/sizzlingstats/SizzlingStats.cpp +++ b/sizzlingstats/SizzlingStats.cpp @@ -136,7 +136,7 @@ void SizzlingStats::PlayerArrowed( int patientEntIndex, int medicEntIndex, float playerAndExtra_t medic_data = m_PlayerDataManager.GetPlayerData(medicEntIndex); medic_data.m_pExtraData->arrowslanded += 1; - playerAndExtra_t data = m_PlayerDataManager.GetPlayerData(medicEntIndex); + playerAndExtra_t data = m_PlayerDataManager.GetPlayerData(patientEntIndex); data.m_pExtraData->arrowsrecv += 1; } From fbc14a0da5163e69201bf0a46c721fca95bead36 Mon Sep 17 00:00:00 2001 From: Patrick Liesveld Date: Mon, 22 Aug 2016 21:02:42 -0400 Subject: [PATCH 4/5] Removed check in LogStats --- sizzlingstats/LogStats.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sizzlingstats/LogStats.cpp b/sizzlingstats/LogStats.cpp index 7911f7a..5f37bc7 100644 --- a/sizzlingstats/LogStats.cpp +++ b/sizzlingstats/LogStats.cpp @@ -288,11 +288,7 @@ void CLogStats::FireGameEvent( IGameEvent *event ) int patient = event->GetInt( "attachedEntity" ); playerInfo &pInfo2 = m_entIndexToPlayerInfo[patient]; - - // Only count arrows for alive players and on the same team - if (pInfo1.pPlayerInfo->IsPlayer() && !pInfo1.pPlayerInfo->IsDead() - && pInfo2.pPlayerInfo->IsPlayer() && !pInfo2.pPlayerInfo->IsDead() - && pInfo1.teamid == pInfo2.teamid) + if (pInfo1.teamid == pInfo2.teamid) { vec_t distance = pInfo1.pPlayerInfo->GetAbsOrigin().DistTo(pInfo2.pPlayerInfo->GetAbsOrigin()); From f1be71a3e4c4d959dc6af8c4dbeb63f0fcddc6d0 Mon Sep 17 00:00:00 2001 From: Patrick Liesveld Date: Sat, 27 Aug 2016 13:00:41 -0400 Subject: [PATCH 5/5] Moved sCrusadersCrossbowType to file-scope --- sizzlinglib/include/SizzPluginContext.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sizzlinglib/include/SizzPluginContext.h b/sizzlinglib/include/SizzPluginContext.h index f6bfe56..cfbd52f 100644 --- a/sizzlinglib/include/SizzPluginContext.h +++ b/sizzlinglib/include/SizzPluginContext.h @@ -274,5 +274,5 @@ class CSizzPluginContext ConVarRef m_refRedTeamName; }; -const int sCrusadersCrossbowType = 11; +static const int sCrusadersCrossbowType = 11; #endif // SIZZ_PLUGIN_CONTEXT_H