From 6e4675c256ea050c907b40b78215c2b2b9682ec0 Mon Sep 17 00:00:00 2001 From: Mikusch <25514044+Mikusch@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:40:02 +0100 Subject: [PATCH] Use new vscript events system --- scripts/vscripts/chaos.nut | 60 ++++--------------- scripts/vscripts/chaos/effects/callouts.nut | 8 +-- scripts/vscripts/chaos/effects/chipdamage.nut | 6 +- scripts/vscripts/chaos/effects/eyecamera.nut | 8 +-- .../chaos/effects/homingprojectiles.nut | 6 +- scripts/vscripts/chaos/effects/noclip.nut | 6 +- scripts/vscripts/chaos/effects/paintitems.nut | 6 +- .../chaos/effects/removewearables.nut | 6 +- .../vscripts/chaos/effects/thirdperson.nut | 6 +- .../vscripts/chaos/effects/tiltedcamera.nut | 8 +-- .../chaos/effects/uncontrollablerecoil.nut | 6 +- scripts/vscripts/chaos_util.nut | 17 ------ 12 files changed, 33 insertions(+), 110 deletions(-) diff --git a/scripts/vscripts/chaos.nut b/scripts/vscripts/chaos.nut index e673455..d0c818e 100644 --- a/scripts/vscripts/chaos.nut +++ b/scripts/vscripts/chaos.nut @@ -3,46 +3,20 @@ IncludeScript("chaos_util") const CHAOS_SCOPE_PREFIX = "CHAOS_" const CHAOS_LOG_PREFIX = "[TF2 Chaos VScript] " -::Chaos_GameEventCallbacks <- {} -::Chaos_ScriptHookCallbacks <- {} - -::__RunGameEventCallbacks <- function(event, params) -{ - __RunEventCallbacks(event, params, "Chaos_OnGameEvent_", "Chaos_GameEventCallbacks", false) - - if ("GameEventCallbacks" in getroottable()) - __RunEventCallbacks(event, params, "OnGameEvent_", "GameEventCallbacks", true) -} - -::__RunScriptHookCallbacks <- function(event, params) -{ - __RunEventCallbacks(event, params, "Chaos_OnScriptHook_", "Chaos_ScriptHookCallbacks", false) - - if ("ScriptHookCallbacks" in getroottable()) - __RunEventCallbacks(event, params, "OnScriptHook_", "ScriptHookCallbacks", true) -} - -::Chaos_CollectEventCallbacks <- function(scope) -{ - __CollectEventCallbacks(scope, "Chaos_OnGameEvent_", "Chaos_GameEventCallbacks", ::RegisterScriptGameEventListener) - __CollectEventCallbacks(scope, "Chaos_OnScriptHook_", "Chaos_ScriptHookCallbacks", ::RegisterScriptHookListener) -} - -ChaosEffectScopes <- {} - function Chaos_StartEffect(name, duration) { local scope_name = CHAOS_SCOPE_PREFIX + name - if (scope_name in ChaosEffectScopes) + if (scope_name in ROOT) { printf(CHAOS_LOG_PREFIX + "Attempted to start effect '%s' that is already started, restarting...\n", name) Chaos_EndEffect(name) } - getroottable()[scope_name] <- {} - local scope = getroottable()[scope_name] + ROOT[scope_name] <- {} + local scope = ROOT[scope_name] IncludeScript("chaos/effects/" + name.tolower(), scope) + __CollectGameEventCallbacks(scope) scope.Chaos_EffectName <- CHAOS_SCOPE_PREFIX + name @@ -58,7 +32,7 @@ function Chaos_StartEffect(name, duration) printf(CHAOS_LOG_PREFIX + "Starting effect '%s'\n", name) if (duration > 0) - ChaosEffectScopes[scope_name] <- scope + ROOT[scope_name] <- scope } else { @@ -71,10 +45,10 @@ function Chaos_StartEffect(name, duration) function Chaos_UpdateEffect(name) { local scope_name = CHAOS_SCOPE_PREFIX + name - if (!(scope_name in ChaosEffectScopes)) + if (!(scope_name in ROOT)) return - local scope = ChaosEffectScopes[scope_name] + local scope = ROOT[scope_name] if (scope == null) return @@ -89,13 +63,13 @@ function Chaos_EndEffect(name) printf(CHAOS_LOG_PREFIX + "Stopping effect '%s'\n", name) local scope_name = CHAOS_SCOPE_PREFIX + name - if (!(scope_name in ChaosEffectScopes)) + if (!(scope_name in ROOT)) { printf(CHAOS_LOG_PREFIX + "Effect '%s' not found in scope list!\n", name) return false } - local scope = ChaosEffectScopes[scope_name] + local scope = ROOT[scope_name] if (scope == null) { printf(CHAOS_LOG_PREFIX + "Effect '%s' scope was deleted early!\n", name) @@ -105,21 +79,7 @@ function Chaos_EndEffect(name) if ("ChaosEffect_OnEnd" in scope) scope.ChaosEffect_OnEnd() - foreach (event, scopes in Chaos_GameEventCallbacks) - { - local index = scopes.find(scope) - if (index != null) - scopes.remove(index) - } - - foreach (hook, scopes in Chaos_ScriptHookCallbacks) - { - local index = scopes.find(scope) - if (index != null) - scopes.remove(index) - } - - delete ChaosEffectScopes[scope_name] + delete ROOT[scope_name] return true } \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/callouts.nut b/scripts/vscripts/chaos/effects/callouts.nut index f022889..4bbe6e3 100644 --- a/scripts/vscripts/chaos/effects/callouts.nut +++ b/scripts/vscripts/chaos/effects/callouts.nut @@ -1,4 +1,4 @@ -function Chaos_OnGameEvent_player_spawn(params) +function OnGameEvent_player_spawn(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -26,7 +26,7 @@ function Chaos_OnGameEvent_player_spawn(params) } } -function Chaos_OnGameEvent_player_death(params) +function OnGameEvent_player_death(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -50,6 +50,4 @@ function Chaos_OnGameEvent_player_death(params) EntFireByHandle(other, "SpeakResponseConcept", "TLK_MVM_DEFENDER_DIED", -1, null, null) EntFireByHandle(other, "ClearContext", null, -1, null, null) } -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/chipdamage.nut b/scripts/vscripts/chaos/effects/chipdamage.nut index fbad647..124f830 100644 --- a/scripts/vscripts/chaos/effects/chipdamage.nut +++ b/scripts/vscripts/chaos/effects/chipdamage.nut @@ -1,10 +1,8 @@ -function Chaos_OnScriptHook_OnTakeDamage(params) +function OnScriptHook_OnTakeDamage(params) { // Only modify for CBaseCombatCharacter if (!NetProps.HasProp(params.const_entity, "m_flNextAttack")) return params.damage = 1 -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/eyecamera.nut b/scripts/vscripts/chaos/effects/eyecamera.nut index 045ba3b..287ee04 100644 --- a/scripts/vscripts/chaos/effects/eyecamera.nut +++ b/scripts/vscripts/chaos/effects/eyecamera.nut @@ -63,7 +63,7 @@ function RemoveViewControl(player) EntFireByHandle(viewcontrol, "Kill", null, -1, null, null) } -function Chaos_OnGameEvent_player_spawn(params) +function OnGameEvent_player_spawn(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -80,7 +80,7 @@ function Chaos_OnGameEvent_player_spawn(params) player.GetScriptScope().viewcontrol <- CreateViewControl(player) } -function Chaos_OnGameEvent_player_death(params) +function OnGameEvent_player_death(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -90,6 +90,4 @@ function Chaos_OnGameEvent_player_death(params) return RemoveViewControl(player) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/homingprojectiles.nut b/scripts/vscripts/chaos/effects/homingprojectiles.nut index 8e741d2..3208352 100644 --- a/scripts/vscripts/chaos/effects/homingprojectiles.nut +++ b/scripts/vscripts/chaos/effects/homingprojectiles.nut @@ -146,7 +146,7 @@ function ChaosEffect_OnEnd() projectile.SetLocalAngles(move_ang) } -function Chaos_OnScriptHook_OnTakeDamage(params) +function OnScriptHook_OnTakeDamage(params) { if (params.const_entity == worldspawn) return @@ -156,6 +156,4 @@ function Chaos_OnScriptHook_OnTakeDamage(params) return EntFireByHandle(params.inflictor, "Kill", null, 0.5, null, null) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/noclip.nut b/scripts/vscripts/chaos/effects/noclip.nut index 8f0f0e9..e16957e 100644 --- a/scripts/vscripts/chaos/effects/noclip.nut +++ b/scripts/vscripts/chaos/effects/noclip.nut @@ -28,13 +28,11 @@ function ChaosEffect_OnEnd() } } -function Chaos_OnGameEvent_player_spawn(params) +function OnGameEvent_player_spawn(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) return EntFireByHandle(player, "RunScriptCode", "self.SetMoveType(MOVETYPE_NOCLIP, MOVECOLLIDE_DEFAULT)", -1, null, null) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/paintitems.nut b/scripts/vscripts/chaos/effects/paintitems.nut index 1f7d0b9..974a824 100644 --- a/scripts/vscripts/chaos/effects/paintitems.nut +++ b/scripts/vscripts/chaos/effects/paintitems.nut @@ -27,13 +27,11 @@ function GetRandomColor() return RandomInt(0, 0x1000000) } -function Chaos_OnGameEvent_post_inventory_application(params) +function OnGameEvent_post_inventory_application(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) return ApplyRandomPaintToItems(player) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/removewearables.nut b/scripts/vscripts/chaos/effects/removewearables.nut index a3451c3..9d9fe94 100644 --- a/scripts/vscripts/chaos/effects/removewearables.nut +++ b/scripts/vscripts/chaos/effects/removewearables.nut @@ -30,13 +30,11 @@ function RemoveAllWearables(player) } } -function Chaos_OnGameEvent_post_inventory_application(params) +function OnGameEvent_post_inventory_application(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) return RemoveAllWearables(player) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/thirdperson.nut b/scripts/vscripts/chaos/effects/thirdperson.nut index 8d7598a..7bd657a 100644 --- a/scripts/vscripts/chaos/effects/thirdperson.nut +++ b/scripts/vscripts/chaos/effects/thirdperson.nut @@ -22,13 +22,11 @@ function ChaosEffect_OnEnd() } } -function Chaos_OnGameEvent_player_spawn(params) +function OnGameEvent_player_spawn(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) return EntFireByHandle(player, "RunScriptCode", "self.SetForcedTauntCam(1)", -1, null, null) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/tiltedcamera.nut b/scripts/vscripts/chaos/effects/tiltedcamera.nut index e7dd5ae..bfc6c14 100644 --- a/scripts/vscripts/chaos/effects/tiltedcamera.nut +++ b/scripts/vscripts/chaos/effects/tiltedcamera.nut @@ -22,7 +22,7 @@ function ChaosEffect_OnEnd() } } -function Chaos_OnGameEvent_player_spawn(params) +function OnGameEvent_player_spawn(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -31,7 +31,7 @@ function Chaos_OnGameEvent_player_spawn(params) SetEyeAngles(player, 90) } -function Chaos_OnGameEvent_player_teleported(params) +function OnGameEvent_player_teleported(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -45,6 +45,4 @@ function SetEyeAngles(player, z) local angles = player.EyeAngles() angles.z = z player.SnapEyeAngles(angles) -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos/effects/uncontrollablerecoil.nut b/scripts/vscripts/chaos/effects/uncontrollablerecoil.nut index d0df3f5..e43b2eb 100644 --- a/scripts/vscripts/chaos/effects/uncontrollablerecoil.nut +++ b/scripts/vscripts/chaos/effects/uncontrollablerecoil.nut @@ -46,7 +46,7 @@ function ChaosEffect_Update() return -1 } -function Chaos_OnGameEvent_player_spawn(params) +function OnGameEvent_player_spawn(params) { local player = GetPlayerFromUserID(params.userid) if (player == null) @@ -58,6 +58,4 @@ function Chaos_OnGameEvent_player_spawn(params) player.ValidateScriptScope() player.GetScriptScope().prevLastFireTime <- NetProps.GetPropFloat(weapon, "LocalActiveTFWeaponData.m_flLastFireTime") -} - -Chaos_CollectEventCallbacks(this) \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/vscripts/chaos_util.nut b/scripts/vscripts/chaos_util.nut index de7eaad..b6130b0 100644 --- a/scripts/vscripts/chaos_util.nut +++ b/scripts/vscripts/chaos_util.nut @@ -9,13 +9,6 @@ if (!("ConstantNamingConvention" in ROOT)) ROOT[k] <- v } -// m_lifeState values -const LIFE_ALIVE = 0 -const LIFE_DYING = 1 -const LIFE_DEAD = 2 -const LIFE_RESPAWNABLE = 3 -const LIFE_DISCARDBODY = 4 - // settings for m_takedamage const DAMAGE_NO = 0 const DAMAGE_EVENTS_ONLY = 1 @@ -50,16 +43,6 @@ const FLT_MAX = 0x7F7FFFFF ::worldspawn <- Entities.FindByClassname(null, "worldspawn") ::gamerules <- Entities.FindByClassname(null, "tf_gamerules") -CTFPlayer.IsAlive <- function() -{ - return NetProps.GetPropInt(this, "m_lifeState") == LIFE_ALIVE -} - -CTFBot.IsAlive <- function() -{ - return NetProps.GetPropInt(this, "m_lifeState") == LIFE_ALIVE -} - ::GetEnemyTeam <- function(team) { if (team == TF_TEAM_RED)