From 9f1d800d49d2c37d8c69714522f98e0b7098cb60 Mon Sep 17 00:00:00 2001 From: Gazyi Date: Wed, 4 Sep 2024 00:55:45 +0300 Subject: [PATCH 1/2] Fix endless Stim ability not playing loop sound and visual effects. --- .../mod/scripts/vscripts/weapons/sh_stim.gnut | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut b/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut new file mode 100644 index 000000000..a3bd41db8 --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut @@ -0,0 +1,188 @@ + +global function StimShared_Init +global function StimPlayer +global function EndlessStimBegin +global function EndlessStimEnd + + +global int COCKPIT_STIM_FX +global int PILOT_STIM_HLD_FX + +global const float STIM_EFFECT_SEVERITY = 0.4 // assuming 'movement_speedboost_extraScale' is 2.0 + +void function StimShared_Init() +{ + COCKPIT_STIM_FX = PrecacheParticleSystem( $"P_heal" ) + PILOT_STIM_HLD_FX = PrecacheParticleSystem( $"P_pilot_stim_hld" ) + + #if CLIENT + StatusEffect_RegisterEnabledCallback( eStatusEffect.stim_visual_effect, StimVisualsEnabled ) + StatusEffect_RegisterDisabledCallback( eStatusEffect.stim_visual_effect, StimVisualsDisabled ) + #endif + + RegisterSignal( "EndStim" ) + RegisterSignal( "StopEndlessStim" ) +} + +void function EndlessStimBegin( entity player, float effectSeverity ) +{ + StimPlayer_Internal( player, USE_TIME_INFINITE, effectSeverity ) +} +void function EndlessStimEnd( entity player ) +{ + player.Signal( "StopEndlessStim" ) +} + +void function StimPlayer( entity player, float duration, float severity = STIM_EFFECT_SEVERITY ) +{ + StimPlayer_Internal( player, duration, severity ) +} + +void function StimPlayer_Internal( entity player, float duration, float effectSeverity ) +{ + // Handles for tracking endless status effects + int endlessStatusEffectHandle_SpeedBoost = 0 + int endlessStatusEffectHandle_StimVFX = 0 + if ( duration == USE_TIME_INFINITE ) + { + endlessStatusEffectHandle_SpeedBoost = StatusEffect_AddEndless( player, eStatusEffect.speed_boost, effectSeverity ) + endlessStatusEffectHandle_StimVFX = StatusEffect_AddEndless( player, eStatusEffect.stim_visual_effect, 1.0 ) + } + else + { + StatusEffect_AddTimed( player, eStatusEffect.speed_boost, effectSeverity, duration + 0.5, 0.25 ) // sound is slightly off + StatusEffect_AddTimed( player, eStatusEffect.stim_visual_effect, 1.0, duration, duration ) + } + +#if SERVER + thread StimThink( player, duration, endlessStatusEffectHandle_SpeedBoost, endlessStatusEffectHandle_StimVFX ) +#else // CLIENT + entity cockpit = player.GetCockpit() + if ( !IsValid( cockpit ) ) + return + + HealthHUD_ClearFX( player ) +#endif +} + +#if SERVER +void function StimThink( entity player, float duration, int endlessStatusEffectHandle_SpeedBoost, int endlessStatusEffectHandle_StimVFX ) +{ + player.EndSignal( "OnDeath" ) + player.EndSignal( "OnChangedPlayerClass" ) + + if ( endlessStatusEffectHandle_SpeedBoost != 0 || endlessStatusEffectHandle_StimVFX != 0 ) + { + player.EndSignal( "StopEndlessStim" ) + // TF|2 stim loop sounds don't actually loop, use TF|1 loop sound. + // BUG: It still stops playing sometimes for whatever reason ( Too many sounds? ) + EmitSoundOnEntity( player, "Pilot_Stimpack_Loop" ) + } + else + { + EmitSoundOnEntityOnlyToPlayer( player, player, "pilot_stimpack_loop_1P" ) + EmitSoundOnEntityExceptToPlayer( player, player, "pilot_stimpack_loop_3P" ) + } + + int attachmentIndex = player.LookupAttachment( "CHESTFOCUS" ) + + entity stimFX = StartParticleEffectOnEntity_ReturnEntity( player, PILOT_STIM_HLD_FX, FX_PATTACH_POINT_FOLLOW, attachmentIndex ) + stimFX.SetOwner( player ) + stimFX.kv.VisibilityFlags = (ENTITY_VISIBLE_TO_FRIENDLY | ENTITY_VISIBLE_TO_ENEMY) // not owner only + + //thread StimSlowmoAim( player, duration ) + + OnThreadEnd( + function() : ( player, stimFX, endlessStatusEffectHandle_SpeedBoost, endlessStatusEffectHandle_StimVFX ) + { + if ( !IsValid( player ) ) + return + + if ( IsValid( stimFX ) ) + EffectStop( stimFX ) + + if ( endlessStatusEffectHandle_SpeedBoost != 0 || endlessStatusEffectHandle_StimVFX != 0 ) + { + StopSoundOnEntity( player, "Pilot_Stimpack_Loop" ) + } + else + { + StopSoundOnEntity( player, "pilot_stimpack_loop_1P" ) + StopSoundOnEntity( player, "pilot_stimpack_loop_3P" ) + } + + if ( endlessStatusEffectHandle_SpeedBoost != 0 ) + StatusEffect_Stop( player, endlessStatusEffectHandle_SpeedBoost ) + + if ( endlessStatusEffectHandle_StimVFX != 0 ) + StatusEffect_Stop( player, endlessStatusEffectHandle_StimVFX ) + + player.Signal( "EndStim" ) + } + ) + + if ( duration == USE_TIME_INFINITE ) + WaitForever() + + wait duration - 2.0 + + EmitSoundOnEntityOnlyToPlayer( player, player, "pilot_stimpack_deactivate_1P" ) + EmitSoundOnEntityExceptToPlayer( player, player, "pilot_stimpack_deactivate_3P" ) + + wait 2.0 +} + +#else // CLIENT +void function StimVisualsEnabled( entity ent, int statusEffect, bool actuallyChanged ) +{ + if ( ent != GetLocalViewPlayer() ) + return + + entity player = ent + + entity cockpit = player.GetCockpit() + if ( !IsValid( cockpit ) ) + return + + int fxHandle = StartParticleEffectOnEntity( cockpit, COCKPIT_STIM_FX, FX_PATTACH_ABSORIGIN_FOLLOW, -1 ) + thread StimScreenFXThink( player, fxHandle, cockpit ) +} + +void function StimVisualsDisabled( entity ent, int statusEffect, bool actuallyChanged ) +{ + if ( ent != GetLocalViewPlayer() ) + return + + ent.Signal( "EndStim" ) +} + +void function StimScreenFXThink( entity player, int fxHandle, entity cockpit ) +{ + player.EndSignal( "EndStim" ) + player.EndSignal( "OnDeath" ) + cockpit.EndSignal( "OnDestroy" ) + + OnThreadEnd( + function() : ( fxHandle ) + { + if ( !EffectDoesExist( fxHandle ) ) + return + + EffectStop( fxHandle, false, true ) + } + ) + + for ( ;; ) + { + float velocityX = Length( player.GetVelocity() ) + + if ( !EffectDoesExist( fxHandle ) ) + break + + velocityX = GraphCapped( velocityX, 0.0, 360, 5, 200 ) + EffectSetControlPointVector( fxHandle, 1, Vector( velocityX, 999, 0 ) ) + WaitFrame() + } +} + +#endif \ No newline at end of file From 12de5cca2a7f6b809309dc315cb375869e87d19b Mon Sep 17 00:00:00 2001 From: Gazyi Date: Wed, 4 Sep 2024 01:01:35 +0300 Subject: [PATCH 2/2] Fix transferring active Pilot Stim ability to Titan when embarking it. --- Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut | 1 + 1 file changed, 1 insertion(+) diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut b/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut index a3bd41db8..fd21f464e 100644 --- a/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/sh_stim.gnut @@ -70,6 +70,7 @@ void function StimThink( entity player, float duration, int endlessStatusEffectH { player.EndSignal( "OnDeath" ) player.EndSignal( "OnChangedPlayerClass" ) + player.EndSignal( "player_embarks_titan" ) // Prevent transferring active Stim ability to Titan. if ( endlessStatusEffectHandle_SpeedBoost != 0 || endlessStatusEffectHandle_StimVFX != 0 ) {