Add global K/D calculation

This commit is contained in:
okvdai
2023-05-03 15:02:11 +02:00
parent 9798a5ff76
commit e6aaebef5f
4 changed files with 50 additions and 10 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"Name": "ToneAPI.pulse",
"Description": "Displays Tone API kill data in the Stats tab.",
"Version": "1.2.0",
"Version": "1.2.1",
"LoadPriority": 1,
"ConVars": [
{
+32
View File
@@ -1,5 +1,6 @@
global function pulseInit
global function GetWeaponStatsFromToneAPI
global function GetGlobalDataFromToneAPI
global function GetMapStatsFromToneAPI
global function GetGamemodeStatsFromToneAPI
global function getWeaponKillsFromToneAPI
@@ -19,6 +20,8 @@ global table globalToneAPIMapDistData = {}
global table globalToneAPIMapKillData = {}
global table globalToneAPIMapMDistData = {}
global table globalToneAPIGamemodeData = {}
global table globalToneAPIAllPlayerKillData = {}
global table globalToneAPIAllPlayerDeathData = {}
global table< table > globalToneAPIGamemodeMapData = {}
string prefix = "default"
@@ -65,6 +68,35 @@ void function GetWeaponStatsFromToneAPI()
NSHttpRequest(getWeaponStats, onSuccess, onFailure)
}
void function GetGlobalDataFromToneAPI()
{
print(prefix + "Getting global data...")
weaponEntries = 0
HttpRequest getGlobalStats
getGlobalStats.method = HttpRequestMethod.GET
getGlobalStats.url = HTTPrequestURL + "/weapons"
getGlobalStats.queryParameters["player"] <- ["!" + NSGetLocalPlayerUID()]
void functionref(HttpRequestResponse) onSuccess = void function(HttpRequestResponse response)
{
print(prefix + "Global data received, processing...")
table JSONForConversion = DecodeJSON(response.body)
foreach (var key, var value in JSONForConversion) {
table test = expect table(value)
globalToneAPIAllPlayerKillData[string(key)] <- test.kills
globalToneAPIAllPlayerDeathData[string(key)] <- test.deaths
weaponEntries += 1
}
print(prefix + "Global data has been processed with a total of " + string(weaponEntries) + " entries.")
}
void functionref(HttpRequestFailure) onFailure = void function(HttpRequestFailure failure)
{
print(prefix + "Encountered an error getting global data...")
}
NSHttpRequest(getGlobalStats, onSuccess, onFailure)
}
void function GetMapStatsFromToneAPI()
{
print(prefix + "Getting map data...")
+1
View File
@@ -46,6 +46,7 @@ void function OnViewStats_Open()
fetchGamemodeStatsFromToneAPI(mapName)
}
GetWeaponStatsFromToneAPI()
GetGlobalDataFromToneAPI()
GetMapStatsFromToneAPI()
GetGamemodeStatsFromToneAPI()
UI_SetPresentationType( ePresentationType.DEFAULT )
@@ -295,6 +295,16 @@ function UpdateViewStatsOverviewMenu()
totalPilotKills += value
}
var totalGlobalKills = 0
foreach (var key, var value in globalToneAPIAllPlayerKillData) {
totalGlobalKills += value
}
var totalGlobalDeaths = 0
foreach (var key, var value in globalToneAPIAllPlayerDeathData) {
totalGlobalDeaths += value
}
var totalPilotDeaths = 0
foreach (var key, var value in globalToneAPIDeathData) {
@@ -321,16 +331,13 @@ function UpdateViewStatsOverviewMenu()
float dval = float(totalPilotDeaths)
float kdval = float(int((kval / dval)*100))/100
float gkval = float(totalGlobalKills)
float gdval = float(totalGlobalDeaths)
float gkdval = float(int((gkval / gdval)*100))/100
SetStatsLabelValue( file.menu, "LifetimeAverageValue", [ "#STATS_KD_VALUE", kdval ] )
// Lifetime (PVP)
local lifetimeAveragePVP = player.GetPersistentVar( "kdratio_lifetime_pvp" ).tofloat()
local formattedLifetimeAveragePVP
if ( lifetimeAveragePVP % 1 == 0 )
formattedLifetimeAveragePVP = format( "%.0f", lifetimeAveragePVP )
else
formattedLifetimeAveragePVP = format( "%.1f", lifetimeAveragePVP )
SetStatsLabelValue( file.menu, "LifetimePVPAverageValue", [ "#STATS_KD_VALUE", formattedLifetimeAveragePVP ] )
SetStatsLabelValue( file.menu, "LifetimePVPAverageValue", [ "#STATS_KD_VALUE", gkdval ] )
bool last10GamesStatsVisible = gamesPlayed >= NUM_GAMES_TRACK_KDRATIO ? true : false
SetLast10GamesStatVisibility( file.menu, last10GamesStatsVisible )
@@ -378,7 +385,7 @@ function UpdateViewStatsOverviewMenu()
else
kdratiopvp_match_average = format( "%.1f", kdratiopvp_match_average )
SetStatsLabelValue( file.menu, "Last10GamesPVPValue", [ "#STATS_KD_VALUE", kdratiopvp_match_average ] )
PlotKDPointsOnGraph( file.menu, 1, kdratiopvp_match, lifetimeAveragePVP )
PlotKDPointsOnGraph( file.menu, 1, kdratiopvp_match, gkdval )
/////////////////////////
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue0" ), string( killsAsPilot ) )