add passives to loadout

This commit is contained in:
2023-08-10 12:33:09 +02:00
parent 4deda3a113
commit 06202bb311
+322 -250
View File
@@ -1,313 +1,368 @@
global function killstat_Init global
function killstat_Init
struct { struct {
string killstatVersion string killstatVersion
string Tone_URI string Tone_URI
string Tone_protocol string Tone_protocol
string Tone_token string Tone_token
bool connected bool connected
string matchId string matchId
string gameMode string gameMode
string map string map
} file }
file
void function killstat_Init() { void
file.killstatVersion = GetConVarString("killstat_version")
file.Tone_URI = GetConVarString("Tone_URI")
file.Tone_token = GetConVarString("Tone_token")
file.connected = false
//Test auth and print result to console when server start function killstat_Init() {
Tone_Test_Auth() file.killstatVersion = GetConVarString("killstat_version")
file.Tone_URI = GetConVarString("Tone_URI")
file.Tone_token = GetConVarString("Tone_token")
file.connected = false
//We should probably blacklist mp_lobby this //Test auth and print result to console when server start
Tone_Register_Match() Tone_Test_Auth()
// callbacks
AddCallback_GameStateEnter(eGameState.Playing, killstat_Begin) //We should probably blacklist mp_lobby this
AddCallback_OnPlayerKilled(killstat_Record) Tone_Register_Match()
AddCallback_GameStateEnter(eGameState.Postmatch, killstat_End) // callbacks
AddCallback_OnClientConnected(JoinMessage) AddCallback_GameStateEnter(eGameState.Playing, killstat_Begin)
AddCallback_OnPlayerKilled(killstat_Record)
AddCallback_GameStateEnter(eGameState.Postmatch, killstat_End)
AddCallback_OnClientConnected(JoinMessage)
} }
string prefix = "\x1b[38;5;81m[TONE API]\x1b[0m " string prefix = "\x1b[38;5;81m[TONE API]\x1b[0m "
void function JoinMessage(entity player) { void
//Chat_ServerPrivateMessage(player, prefix + "This server collects data using the Tone API. Check your data here: \x1b[34mtoneapi.com/" + player.GetPlayerName()+ "\x1b[0m", false, false)
Chat_ServerPrivateMessage(player, prefix + "This server collects data using the WIP Tone API. View statistics at https://toneapi.github.io/ToneAPI_webclient/", false, false) function JoinMessage(entity player) {
//Chat_ServerPrivateMessage(player, prefix + "This server collects data using the Tone API. Check your data here: \x1b[34mtoneapi.com/" + player.GetPlayerName()+ "\x1b[0m", false, false)
Chat_ServerPrivateMessage(player, prefix + "This server collects data using the WIP Tone API. View statistics at https://toneapi.github.io/ToneAPI_webclient/", false, false)
} }
void function killstat_Begin() { void
//TODO : request MatchID from API ------------------------------------------------------------------------------------------------
//TODO : request anonymization data from API
Log("-----BEGIN KILLSTAT-----") function killstat_Begin() {
Log("Sending kill data to " + file.Tone_URI + "/kill") //TODO : request MatchID from API ------------------------------------------------------------------------------------------------
//TODO : request anonymization data from API
Log("-----BEGIN KILLSTAT-----")
Log("Sending kill data to " + file.Tone_URI + "/kill")
} }
void function killstat_Record(entity victim, entity attacker, var damageInfo) { void
if ( !victim.IsPlayer() || !attacker.IsPlayer() || GetGameState() != eGameState.Playing )
return function killstat_Record(entity victim, entity attacker,
// if(file.matchId) var damageInfo) {
// return if (!victim.IsPlayer() || !attacker.IsPlayer() || GetGameState() != eGameState.Playing)
return
// if(file.matchId)
// return
table attackerValues = {} table attackerValues = {}
table<string, var> victimValues = {} table < string,
var > victimValues = {}
array<entity> attackerWeapons = attacker.GetMainWeapons() array < entity > attackerWeapons = attacker.GetMainWeapons()
array<entity> victimWeapons = victim.GetMainWeapons() array < entity > victimWeapons = victim.GetMainWeapons()
array<entity> attackerOffhandWeapons = attacker.GetOffhandWeapons() array < entity > attackerOffhandWeapons = attacker.GetOffhandWeapons()
array<entity> victimOffhandWeapons = victim.GetOffhandWeapons() array < entity > victimOffhandWeapons = victim.GetOffhandWeapons()
attackerWeapons.sort(MainWeaponSort) attackerWeapons.sort(MainWeaponSort)
victimWeapons.sort(MainWeaponSort) victimWeapons.sort(MainWeaponSort)
entity aw1 = GetNthWeapon(attackerWeapons, 0) entity aw1 = GetNthWeapon(attackerWeapons, 0)
entity aw2 = GetNthWeapon(attackerWeapons, 1) entity aw2 = GetNthWeapon(attackerWeapons, 1)
entity aw3 = GetNthWeapon(attackerWeapons, 2) entity aw3 = GetNthWeapon(attackerWeapons, 2)
entity vw1 = GetNthWeapon(victimWeapons, 0) entity vw1 = GetNthWeapon(victimWeapons, 0)
entity vw2 = GetNthWeapon(victimWeapons, 1) entity vw2 = GetNthWeapon(victimWeapons, 1)
entity vw3 = GetNthWeapon(victimWeapons, 2) entity vw3 = GetNthWeapon(victimWeapons, 2)
entity aow1 = GetNthWeapon(attackerOffhandWeapons, 0) entity aow1 = GetNthWeapon(attackerOffhandWeapons, 0)
entity aow2 = GetNthWeapon(attackerOffhandWeapons, 1) entity aow2 = GetNthWeapon(attackerOffhandWeapons, 1)
entity aow3 = GetNthWeapon(attackerOffhandWeapons, 2) entity aow3 = GetNthWeapon(attackerOffhandWeapons, 2)
entity vow1 = GetNthWeapon(victimOffhandWeapons, 0) entity vow1 = GetNthWeapon(victimOffhandWeapons, 0)
entity vow2 = GetNthWeapon(victimOffhandWeapons, 1) entity vow2 = GetNthWeapon(victimOffhandWeapons, 1)
entity vow3 = GetNthWeapon(victimOffhandWeapons, 2) entity vow3 = GetNthWeapon(victimOffhandWeapons, 2)
int damageSourceId = DamageInfo_GetDamageSourceIdentifier(damageInfo) int damageSourceId = DamageInfo_GetDamageSourceIdentifier(damageInfo)
string damageName = DamageSourceIDToString(damageSourceId) string damageName = DamageSourceIDToString(damageSourceId)
float dist = Distance(attacker.GetOrigin(), victim.GetOrigin()) float dist = Distance(attacker.GetOrigin(), victim.GetOrigin())
table values = { table values = {
killstat_version = file.killstatVersion killstat_version = file.killstatVersion
match_id = file.matchId match_id = file.matchId
game_time = Time() game_time = Time()
player_count = GetPlayerArray().len() player_count = GetPlayerArray().len()
cause_of_death = damageName cause_of_death = damageName
distance = dist distance = dist
attacker = { attacker = {
name = attacker.GetPlayerName() name = attacker.GetPlayerName()
id = attacker.GetUID() id = attacker.GetUID()
titan = GetTitan(attacker) velocity = Distance( < 0, 0, 0 > , attacker.GetVelocity())
velocity = Distance(<0,0,0>, attacker.GetVelocity()) cloaked = attacker.IsCloaked(true)
cloaked = attacker.IsCloaked( true ) state = GetMovementState(attacker)
state = GetMovementState(attacker) current_weapon = {
current_weapon = { name = GetWeaponName(attacker.GetLatestPrimaryWeapon())
name = GetWeaponName(attacker.GetLatestPrimaryWeapon()) mods = GetWeaponMods(attacker.GetLatestPrimaryWeapon())
mods = GetWeaponMods(attacker.GetLatestPrimaryWeapon()) }
} loadout = {
loadout = { primary = {
primary = { name = GetWeaponName(aw1)
name = GetWeaponName(aw1) mods = GetWeaponMods(aw1)
mods = GetWeaponMods(aw1) }
} secondary = {
secondary = { name = GetWeaponName(aw2)
name = GetWeaponName(aw2) mods = GetWeaponMods(aw2)
mods = GetWeaponMods(aw2) }
} anti_titan = {
anti_titan = { name = GetWeaponName(aw3)
name = GetWeaponName(aw3) mods = GetWeaponMods(aw3)
mods = GetWeaponMods(aw3) }
} ordnance = {
ordnance = { name = GetWeaponName(aow1)
name = GetWeaponName(aow1) mods = GetWeaponMods(aow1)
mods = GetWeaponMods(aow1) }
} tactical = {
tactical = { name = GetWeaponName(aow2)
name = GetWeaponName(aow2) mods = GetWeaponMods(aow2)
mods = GetWeaponMods(aow2) }
} passive1 = getPlayerPassive1(attacker)
} passive2 = getPlayerPassive2(attacker)
} titan = GetTitan(attacker)
victim = { }
name = victim.GetPlayerName() }
id = victim.GetUID() victim = {
titan = GetTitan(victim) name = victim.GetPlayerName()
velocity = Distance(<0,0,0>, victim.GetVelocity()) id = victim.GetUID()
cloaked = victim.IsCloaked( true ) velocity = Distance( < 0, 0, 0 > , victim.GetVelocity())
state = GetMovementState(victim) cloaked = victim.IsCloaked(true)
current_weapon = { state = GetMovementState(victim)
name = GetWeaponName(victim.GetLatestPrimaryWeapon()) current_weapon = {
mods = GetWeaponMods(victim.GetLatestPrimaryWeapon()) name = GetWeaponName(victim.GetLatestPrimaryWeapon())
} mods = GetWeaponMods(victim.GetLatestPrimaryWeapon())
loadout = { }
primary = { loadout = {
name = GetWeaponName(vw1) primary = {
mods = GetWeaponMods(vw1) name = GetWeaponName(vw1)
} mods = GetWeaponMods(vw1)
secondary = { }
name = GetWeaponName(vw2) secondary = {
mods = GetWeaponMods(vw2) name = GetWeaponName(vw2)
} mods = GetWeaponMods(vw2)
anti_titan = { }
name = GetWeaponName(vw3) anti_titan = {
mods = GetWeaponMods(vw3) name = GetWeaponName(vw3)
} mods = GetWeaponMods(vw3)
ordnance = { }
name = GetWeaponName(vow1) ordnance = {
mods = GetWeaponMods(vow1) name = GetWeaponName(vow1)
} mods = GetWeaponMods(vow1)
tactical = { }
name = GetWeaponName(vow2) tactical = {
mods = GetWeaponMods(vow2) name = GetWeaponName(vow2)
} mods = GetWeaponMods(vow2)
} }
} passive1 = getPlayerPassive1(victim)
} passive2 = getPlayerPassive2(victim)
titan = GetTitan(victim)
}
}
}
HttpRequest request HttpRequest request
request.method = HttpRequestMethod.POST request.method = HttpRequestMethod.POST
request.url = file.Tone_URI + "/server/kill" request.url = file.Tone_URI + "/server/kill"
request.body = EncodeJSON(values) request.body = EncodeJSON(values)
Tone_HTTP_Request( Tone_HTTP_Request(
request, request,
void function ( HttpRequestResponse response ) {} void
) function(HttpRequestResponse response) {}
)
} }
void function killstat_End() { void
Log("-----END KILLSTAT-----")
function killstat_End() {
Log("-----END KILLSTAT-----")
} }
string function GetMovementState(entity player){ string
Assert(IsPilot(player))
//IsPhaseShifted function GetMovementState(entity player) {
//IsStanding Assert(IsPilot(player))
if(player.IsWallHanging()) //IsPhaseShifted
return "WallHanging" //IsStanding
if(player.IsWallRunning()) if (player.IsWallHanging())
return "WallRunning" return "WallHanging"
if(player.IsZiplining()) if (player.IsWallRunning())
return "Ziplining" return "WallRunning"
if(!player.IsOnGround()) if (player.IsZiplining())
return "Ziplining"
if (!player.IsOnGround())
return "Airborne" return "Airborne"
if(player.IsCrouched()) if (player.IsCrouched())
return "Crouching" return "Crouching"
return "OnGround" return "OnGround"
} }
// Should sort main weapons in following order: // Should sort main weapons in following order:
// 1. primary // 1. primary
// 2. secondary // 2. secondary
// 3. anti-titan // 3. anti-titan
int function MainWeaponSort(entity a, entity b) { int
int aID = a.GetDamageSourceID()
int bID = b.GetDamageSourceID()
int aIdx = MAIN_DAMAGE_SOURCES.find(aID) function MainWeaponSort(entity a, entity b) {
int bIdx = MAIN_DAMAGE_SOURCES.find(bID) int aID = a.GetDamageSourceID()
int bID = b.GetDamageSourceID()
if (aIdx == bIdx) { int aIdx = MAIN_DAMAGE_SOURCES.find(aID)
return 0 int bIdx = MAIN_DAMAGE_SOURCES.find(bID)
} else if (aIdx != -1 && bIdx == -1) {
return -1
} else if (aIdx == -1 && bIdx != -1) {
return 1
}
return aIdx < bIdx ? -1 : 1 if (aIdx == bIdx) {
return 0
} else if (aIdx != -1 && bIdx == -1) {
return -1
} else if (aIdx == -1 && bIdx != -1) {
return 1
}
return aIdx < bIdx ? -1 : 1
} }
entity function GetNthWeapon(array<entity> weapons, int index) { entity
return index < weapons.len() ? weapons[index] : null function GetNthWeapon(array < entity > weapons, int index) {
return index < weapons.len() ? weapons[index] : null
} }
string function GetWeaponName(entity weapon) { string
string s = "null" function GetWeaponName(entity weapon) {
if (weapon != null) { string s = "null"
s = weapon.GetWeaponClassName() if (weapon != null) {
} s = weapon.GetWeaponClassName()
return s }
return s
} }
int function GetWeaponMods(entity weapon) { int
if (weapon == null) { function GetWeaponMods(entity weapon) {
return 0 if (weapon == null) {
} return 0
int modBits = weapon.GetModBitField() }
// return format("%d", modBits) int modBits = weapon.GetModBitField()
return modBits // return format("%d", modBits)
return modBits
} }
string function GetTitan(entity player) { string
if(!player.IsTitan()) return "null" function GetTitan(entity player) {
return GetTitanCharacterName(player) if (!player.IsTitan()) return "null"
return GetTitanCharacterName(player)
} }
void function Log(string s) { void
print(prefix + " " + s) function Log(string s) {
print(prefix + " " + s)
} }
void function Tone_Test_Auth(){ void
HttpRequest request function Tone_Test_Auth() {
request.method = HttpRequestMethod.POST HttpRequest request
request.url = file.Tone_URI + "/" request.method = HttpRequestMethod.POST
Tone_HTTP_Request( request.url = file.Tone_URI + "/"
request, Tone_HTTP_Request(
void function ( HttpRequestResponse response ) { request,
Log("Tone API Online !") void
file.connected = true function(HttpRequestResponse response) {
} Log("Tone API Online !")
) file.connected = true
}
)
} }
void function Tone_Register_Match(){ void
HttpRequest request function Tone_Register_Match() {
request.method = HttpRequestMethod.POST HttpRequest request
request.url = file.Tone_URI + "/match" request.method = HttpRequestMethod.POST
request.body = EncodeJSON({ request.url = file.Tone_URI + "/match"
gameMode = GameRules_GetGameMode() request.body = EncodeJSON({
map = StringReplace(GetMapName(), "mp_", "") gameMode = GameRules_GetGameMode()
servername = GetConVarString("ns_server_name") map = StringReplace(GetMapName(), "mp_", "")
}) servername = GetConVarString("ns_server_name")
Tone_HTTP_Request( })
request, Tone_HTTP_Request(
void function ( HttpRequestResponse response ) { request,
Log("match ID : " + response.body) void
file.matchId = response.body function(HttpRequestResponse response) {
} Log("match ID : " + response.body)
) file.matchId = response.body
}
)
} }
void function Tone_HTTP_Request(HttpRequest request, void functionref( HttpRequestResponse ) cbSuccess){ void
if(!request.method) request.method = HttpRequestMethod.POST function Tone_HTTP_Request(HttpRequest request, void functionref(HttpRequestResponse) cbSuccess) {
if(request.url == ""){ if (!request.method) request.method = HttpRequestMethod.POST
Log("[ERRR] Couldn't find URI for request. This should be reported") if (request.url == "") {
return Log("[ERRR] Couldn't find URI for request. This should be reported")
} return
request.headers = {Authorization = ["Bearer "+ file.Tone_token]} }
request.headers = {
Authorization = ["Bearer " + file.Tone_token]
}
NSHttpRequest( NSHttpRequest(
request, request,
void function ( HttpRequestResponse response ) : (cbSuccess) void
{ function(HttpRequestResponse response): (cbSuccess) {
if(response.statusCode == 200 || response.statusCode == 201){ if (response.statusCode == 200 || response.statusCode == 201) {
cbSuccess(response) cbSuccess(response)
}else{ } else {
Log("[WARN] Something might be wrong with your token") Log("[WARN] Something might be wrong with your token")
Log("[WARN]" + response.statusCode) Log("[WARN]" + response.statusCode)
Log("[WARN]" + response.body) Log("[WARN]" + response.body)
} }
}, },
void function ( HttpRequestFailure failure ) void
{ function(HttpRequestFailure failure) {
Log("[WARN] Couldn't request the server! ToneAPI may be down.") Log("[WARN] Couldn't request the server! ToneAPI may be down.")
Log("[WARN]" + failure.errorCode) Log("[WARN]" + failure.errorCode)
Log("[WARN]" + failure.errorMessage) Log("[WARN]" + failure.errorMessage)
} }
) )
} }
string
function getPlayerPassive1(player entity) {
foreach(string passive in passive1Names) {
if (PlayerHasPassive(player, passive)) {
return passive
}
}
return null
}
array<int> MAIN_DAMAGE_SOURCES = [ string
// primaries function getPlayerPassive2(player entity) {
foreach(string passive in passive2Names) {
if (PlayerHasPassive(player, passive)) {
return passive
}
}
return null
}
array < int > MAIN_DAMAGE_SOURCES = [
// primaries
eDamageSourceId.mp_weapon_car, eDamageSourceId.mp_weapon_car,
eDamageSourceId.mp_weapon_r97, eDamageSourceId.mp_weapon_r97,
eDamageSourceId.mp_weapon_alternator_smg, eDamageSourceId.mp_weapon_alternator_smg,
@@ -332,15 +387,32 @@ array<int> MAIN_DAMAGE_SOURCES = [
eDamageSourceId.mp_weapon_shotgun_pistol, eDamageSourceId.mp_weapon_shotgun_pistol,
eDamageSourceId.mp_weapon_wingman_n, eDamageSourceId.mp_weapon_wingman_n,
// secondaries // secondaries
eDamageSourceId.mp_weapon_smart_pistol, eDamageSourceId.mp_weapon_smart_pistol,
eDamageSourceId.mp_weapon_wingman, eDamageSourceId.mp_weapon_wingman,
eDamageSourceId.mp_weapon_semipistol, eDamageSourceId.mp_weapon_semipistol,
eDamageSourceId.mp_weapon_autopistol, eDamageSourceId.mp_weapon_autopistol,
// anti-titan // anti-titan
eDamageSourceId.mp_weapon_mgl, eDamageSourceId.mp_weapon_mgl,
eDamageSourceId.mp_weapon_rocket_launcher, eDamageSourceId.mp_weapon_rocket_launcher,
eDamageSourceId.mp_weapon_arc_launcher, eDamageSourceId.mp_weapon_arc_launcher,
eDamageSourceId.mp_weapon_defender eDamageSourceId.mp_weapon_defender
]
array < string > passive1Names = [
"pas_ordnance_pack",
"pas_power_cell",
"pas_fast_embark",
"pas_fast_health_regen"
]
array < string > passive2Names = [
"pas_stealth_movement",
"pas_wallhang",
"pas_ads_hover",
"pas_enemy_death_icons",
"pas_at_hunter"
] ]