Frog_PlatformDisappear_FixedRestart

#CustomActor

Version of Hat_PlatformDisappear that properly retains its DisappearDelay and DisappearDuration properties when reappearing.

Hat_PlatformDisappear sets the values of DisappearDelay and DisappearDuration back to the class defaults when the Restart function is called to make it reappear. This is a problem if you want to modify those properties, as modified values will not be properly retained between restarts. This custom version of the class rectifies that.

I don't think it's likely that this will malfunction in any way, but if you do run into any issues feel free to let me know.

Frog_PlatformDisappear_FixedRestart.uc

[RAW] [Download]

/**
 *
 * ORIGINAL Hat_PlatformDisappear SCRIPT: Copyright 2012-2015 Gears for Breakfast ApS. All Rights Reserved.
 *
 * Modified version Frog_PlatformDisappear_FixedRestart created by Dr. Treefrog.
 *
 */
 
class Frog_PlatformDisappear_FixedRestart extends Hat_Platform_Base
    placeable;
 
var() StaticMeshComponent Mesh;
var() const editconst LightEnvironmentComponent LightEnvironment;
var() float DisappearTime;
var() float DisappearDelay;
var() float DisappearDuration;
 
var float Scale;
var bool Activated;
 
 
//DRTREEFROG-ADD: Modify these values in Tick instead of DisappearDelay and DisappearDuration in order to preserve the modified values of DisappearDelay and DisappearDuration
var float CurrentDisappearDelay;
var float CurrentDisappearDuration;
 
defaultproperties
{
   Begin Object Class=StaticMeshComponent Name=Model0
        bUsePrecomputedShadows=TRUE
        LightingChannels = (Static=True,Dynamic=True)
   End Object
   Mesh=Model0
   CollisionComponent=Model0
   Components.Add(Model0)
 
   bEdShouldSnap=true;
   bWorldGeometry=false
   bBumpEvenIfWorldGeometry=true
   bCollideActors=true
   bBlockActors=true
 
   DisappearTime = 3;
   DisappearDelay = 1;
   DisappearDuration = 5;
   Scale = 1.0;
   TickOptimize = TickOptimize_None
 
   RemoteRole=ROLE_SimulatedProxy
}
 
simulated event PostBeginPlay()
{
    Super.PostBeginPlay();
 
    CurrentDisappearDelay = DisappearDelay;
    CurrentDisappearDuration = DisappearDuration;
 
    SetTickIsDisabled(true);
}
 
simulated event Attach( Actor Other )
{
     Super.Attach(Other);
    if (Activated) return;
    if (other.IsA('Hat_PawnGhost')) return;
 
    //Update these when activated in case of the values being modified during play
    CurrentDisappearDelay = DisappearDelay;
    CurrentDisappearDuration = DisappearDuration;
 
    Activated = true;
    Scale = 1.0;
    SetTickIsDisabled(false);
}
 
simulated event Tick(float d)
{
    Super.Tick(d);
 
    if (!Activated)
    {
        Scale += (1.0 - Scale)*FMin(d*5,1.0);
        Mesh.SetScale(Scale);
        return;
    }
 
    if (DisappearDelay > 0 && CurrentDisappearDelay > 0)
    {
        CurrentDisappearDelay -= d;
        if (CurrentDisappearDelay > 0)
        {
            Scale = 1.0 + Sin((DisappearDelay - CurrentDisappearDelay)*50)*0.05;
        }
    }
    if (CurrentDisappearDelay <= 0)
    {
        if (Scale > 0)
        {
            Scale -= d * (1.0/DisappearTime);
            if (Scale <= 0)
            {
                SetHidden(true);
            }
        }
        if (Scale <= 0)
        {
            CurrentDisappearDuration -= d;
            if (CurrentDisappearDuration <= 0)
            {
                Restart();
            }
        }
    }
    if (Scale > 0.0) Mesh.SetScale(Scale);
}
 
function Restart()
{
    SetHidden(false);
    Activated = false;
    CurrentDisappearDuration = DisappearDuration;
    CurrentDisappearDelay = DisappearDelay;
    Scale = 1.0;
    Mesh.SetScale(Scale);
    SetTickIsDisabled(true);
}