handle match close

This commit is contained in:
2023-09-07 00:33:58 +02:00
parent 03b775fec3
commit 64030e5ef0
2 changed files with 95 additions and 38 deletions
+86 -30
View File
@@ -1,7 +1,5 @@
global function matchstat_Init global function matchstat_Init
typedef weaponStats table <string, var>
// typedef playerWeaponStats table < string, weaponStats >
typedef playerSpecificStats table < string, var > typedef playerSpecificStats table < string, var >
typedef playerStats table < string, playerSpecificStats > typedef playerStats table < string, playerSpecificStats >
typedef players table < string, playerStats > typedef players table < string, playerStats >
@@ -20,13 +18,16 @@ void function matchstat_Init(){
} }
var function incrementVar(var value){ var function incrementVar(var value){
return expect int(value) + 1 return expect float(value) + 1
} }
void function CreatePlayer(string playerUID){ void function CreatePlayer(entity player){
string playerUID = player.GetUID()
if(!(playerUID in file.weaponsUsed)){ if(!(playerUID in file.weaponsUsed)){
var playerName = player.GetPlayerName()
file.weaponsUsed[playerUID] <- {} file.weaponsUsed[playerUID] <- {}
file.weaponsUsed[playerUID].weapons <- {} file.weaponsUsed[playerUID].weapons <- {}
file.weaponsUsed[playerUID].titans <- {}
file.weaponsUsed[playerUID].stats <- {} file.weaponsUsed[playerUID].stats <- {}
file.weaponsUsed[playerUID].stats.distance <- { file.weaponsUsed[playerUID].stats.distance <- {
ground = 0.0, ground = 0.0,
@@ -41,20 +42,40 @@ void function CreatePlayer(string playerUID){
} }
} }
void function CreateWeaponStats(string weaponName, string playerUID){ void function CreateWeaponStats(string weaponName, entity player){
CreatePlayer(playerUID) CreatePlayer(player)
string playerUID = player.GetUID()
if(!(weaponName in file.weaponsUsed[playerUID].weapons)){ if(!(weaponName in file.weaponsUsed[playerUID].weapons)){
weaponStats stats = { // Has to make ints floats because you can't mix types apparently
shotsFired = 0, playerSpecificStats stats = {
shotsHit = 0, shotsFired = 0.0,
shotsCrit = 0, shotsHit = 0.0,
shotsHeadshot = 0, shotsCrit = 0.0,
shotsRichochet = 0 shotsHeadshot = 0.0,
shotsRichochet = 0.0,
playtime = 0.0
} }
file.weaponsUsed[playerUID].weapons[weaponName] <- stats file.weaponsUsed[playerUID].weapons[weaponName] <- stats
} }
} }
void function CreateTitanStats(string titanName, entity player){
CreatePlayer(player)
string playerUID = player.GetUID()
if(!(titanName in file.weaponsUsed[playerUID].titans)){
// Has to make ints floats because you can't mix types apparently
playerSpecificStats stats = {
shotsFired = 0.0,
shotsHit = 0.0,
shotsCrit = 0.0,
shotsHeadshot = 0.0,
shotsRichochet = 0.0,
playtime = 0.0
}
file.weaponsUsed[playerUID].titans[titanName] <- stats
}
}
void function OnWeaponFired(entity weapon, WeaponPrimaryAttackParams attackParams, var ammoUsed){ void function OnWeaponFired(entity weapon, WeaponPrimaryAttackParams attackParams, var ammoUsed){
entity player = weapon.GetOwner() entity player = weapon.GetOwner()
string weaponName = weapon.GetWeaponClassName() string weaponName = weapon.GetWeaponClassName()
@@ -62,8 +83,13 @@ void function OnWeaponFired(entity weapon, WeaponPrimaryAttackParams attackParam
return return
} }
string playerUID = player.GetUID() string playerUID = player.GetUID()
CreateWeaponStats(weaponName, playerUID) CreateWeaponStats(weaponName, player)
file.weaponsUsed[playerUID].weapons[weaponName].shotsFired = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsFired) file.weaponsUsed[playerUID].weapons[weaponName].shotsFired = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsFired)
if(player.IsTitan()){
string titanName = GetTitanCharacterName(player)
CreateTitanStats(titanName, player)
file.weaponsUsed[playerUID].titans[titanName].shotsFired = incrementVar(file.weaponsUsed[playerUID].titans[titanName].shotsFired)
}
} }
void function OnDamage( entity victim, var damageInfo){ void function OnDamage( entity victim, var damageInfo){
@@ -87,21 +113,36 @@ void function OnDamage( entity victim, var damageInfo){
return return
} }
} }
CreateWeaponStats(weaponName, player)
CreateWeaponStats(weaponName, playerUID)
file.weaponsUsed[playerUID].weapons[weaponName].shotsHit = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsHit) file.weaponsUsed[playerUID].weapons[weaponName].shotsHit = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsHit)
if(player.IsTitan()){
string titanName = GetTitanCharacterName(player)
CreateTitanStats(titanName, player)
file.weaponsUsed[playerUID].titans[titanName].shotsHit = incrementVar(file.weaponsUsed[playerUID].titans[titanName].shotsHit)
}
int damageType = DamageInfo_GetCustomDamageType( damageInfo ) int damageType = DamageInfo_GetCustomDamageType( damageInfo )
bool crit = bool( damageType & DF_CRITICAL ) bool crit = bool( damageType & DF_CRITICAL )
bool headshot = bool( damageType & DF_HEADSHOT ) bool headshot = bool( damageType & DF_HEADSHOT )
if(crit){ // if(crit){
file.weaponsUsed[playerUID].weapons[weaponName].shotsCrit = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsCrit) // file.weaponsUsed[playerUID].weapons[weaponName].shotsCrit = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsCrit)
// if(player.IsTitan()){
// file.weaponsUsed[playerUID].titans[titanName].shotsCrit = incrementVar(file.weaponsUsed[playerUID].titans[titanName].shotsCrit)
// }
// }
if(headshot || crit){
file.weaponsUsed[playerUID].weapons[weaponName].shotsHeadshot = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsHeadshot)
if(player.IsTitan()){
string titanName = GetTitanCharacterName(player)
file.weaponsUsed[playerUID].titans[titanName].shotsHeadshot = incrementVar(file.weaponsUsed[playerUID].titans[titanName].shotsHeadshot)
} }
if(headshot){
file.weaponsUsed[playerUID].weapons[weaponName].shotsHeadshot = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsCrit)
} }
if ( inflictor && inflictor.IsProjectile() ){ if ( inflictor && inflictor.IsProjectile() ){
if(inflictor.proj.projectileBounceCount > 1){ if(inflictor.proj.projectileBounceCount > 1){
file.weaponsUsed[playerUID].weapons[weaponName].shotsRichochet = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsCrit) file.weaponsUsed[playerUID].weapons[weaponName].shotsRichochet = incrementVar(file.weaponsUsed[playerUID].weapons[weaponName].shotsRichochet)
if(player.IsTitan()){
string titanName = GetTitanCharacterName(player)
file.weaponsUsed[playerUID].titans[titanName].shotsRichochet = incrementVar(file.weaponsUsed[playerUID].titans[titanName].shotsRichochet)
}
} }
} }
@@ -110,7 +151,7 @@ void function OnDamage( entity victim, var damageInfo){
void function TrackPlayer(entity player) { void function TrackPlayer(entity player) {
string playerUID = player.GetUID() string playerUID = player.GetUID()
CreatePlayer(playerUID) CreatePlayer(player)
thread TrackPlayer_Threaded(player) thread TrackPlayer_Threaded(player)
} }
@@ -123,30 +164,45 @@ void function TrackPlayer_Threaded(entity player){
player.EndSignal( "OnDeath" ) player.EndSignal( "OnDeath" )
vector position = player.GetOrigin() vector position = player.GetOrigin()
string playerUID = player.GetUID() string playerUID = player.GetUID()
float interval = 0.2
while(true){ while(true){
wait 0.2 wait interval
// Hmm // Hmm
Assert( IsValid( player ) ) Assert( IsValid( player ) )
if(!IsValid(player)) return if(!IsValid(player)) return
if( player.IsTitan() || !player.IsPlayer()) continue
// Ugly, should probably use flags // Ugly, should probably use flags
if(GetGameState() == eGameState.WinnerDetermined) return if(GetGameState() == eGameState.WinnerDetermined) return
entity weapon = player.GetActiveWeapon()
if(weapon){
string weaponName = weapon.GetWeaponClassName()
CreateWeaponStats(weaponName, player)
file.weaponsUsed[playerUID].weapons[weaponName].playtime = expect float(file.weaponsUsed[playerUID].weapons[weaponName].playtime) + interval
}else{
CreatePlayer(player)
}
if(player.IsTitan()){
string titanName = GetTitanCharacterName(player)
CreateTitanStats(titanName, player)
file.weaponsUsed[playerUID].titans[titanName].playtime = expect float(file.weaponsUsed[playerUID].titans[titanName].playtime) + interval
}else if(player.IsPlayer()){
// Could be a little inaccurate but should work fine if interval is small enough // Could be a little inaccurate but should work fine if interval is small enough
vector diff = position - player.GetOrigin()
if(player.IsWallRunning()){ if(player.IsWallRunning()){
file.weaponsUsed[playerUID].stats.time.wall = expect float(file.weaponsUsed[playerUID].stats.time.wall) + 0.2 file.weaponsUsed[playerUID].stats.time.wall = expect float(file.weaponsUsed[playerUID].stats.time.wall) + interval
file.weaponsUsed[playerUID].stats.distance.wall = expect float(file.weaponsUsed[playerUID].stats.distance.wall) + Length(diff) file.weaponsUsed[playerUID].stats.distance.wall = expect float(file.weaponsUsed[playerUID].stats.distance.wall) + Distance(position, player.GetOrigin())
} }
else if(!player.IsOnGround()){ else if(!player.IsOnGround()){
file.weaponsUsed[playerUID].stats.time.air = expect float(file.weaponsUsed[playerUID].stats.time.air) + 0.2 file.weaponsUsed[playerUID].stats.time.air = expect float(file.weaponsUsed[playerUID].stats.time.air) + interval
file.weaponsUsed[playerUID].stats.distance.air = expect float(file.weaponsUsed[playerUID].stats.distance.air) + Length(diff) file.weaponsUsed[playerUID].stats.distance.air = expect float(file.weaponsUsed[playerUID].stats.distance.air) + Distance(position, player.GetOrigin())
} }
else{ else{
file.weaponsUsed[playerUID].stats.time.ground = expect float(file.weaponsUsed[playerUID].stats.time.ground) + 0.2 file.weaponsUsed[playerUID].stats.time.ground = expect float(file.weaponsUsed[playerUID].stats.time.ground) + interval
file.weaponsUsed[playerUID].stats.distance.ground = expect float(file.weaponsUsed[playerUID].stats.distance.ground) + Length(diff) file.weaponsUsed[playerUID].stats.distance.ground = expect float(file.weaponsUsed[playerUID].stats.distance.ground) + Distance(position, player.GetOrigin())
} }
}
position = player.GetOrigin() position = player.GetOrigin()
} }
} }
+1
View File
@@ -35,6 +35,7 @@ void function toneapi_Init(){
Tone_Register_Match() Tone_Register_Match()
AddCallback_OnClientConnected(JoinMessage) AddCallback_OnClientConnected(JoinMessage)
// AddCallback_OnClientConnected(RegisterPlayer)
} }
void function JoinMessage(entity player) { void function JoinMessage(entity player) {