| Home Page | Recent Changes | Preferences

# Barrel

UT :: Actor (UT) >> Decoration

It's just a wooden barrel. You can shoot it and it shatters.

## Extending

A respawning barrel.

Remaining problems:

- no effect of any kind when the barrel reappears. You might want some sort of swishy wizz or something
- you can be standing where the barrel really is when it reappears, and then you're sort of inside it

To use this script in your map: Create A Subclass.

    //=============================================================================
    // ReviveBarrel.
    //=============================================================================
    class ReviveBarrel extends Barrel;

    var() float TimeToRespawn;
    var int InitialHealth;

    function PreBeginPlay()
    {
      super.PreBeginPlay();
      InitialHealth = Health;
    }

    function Vanish(bool bVanish)
    {
      bHidden = bVanish;
      bBlockActors = !bVanish;
      bBlockPlayers = !bVanish;
      bProjTarget = !bVanish;
    }

    simulated function Frag(class<fragment> FragType, vector Momentum, float DSize, int NumFrags)
    {
      local int i;
      local actor A, Toucher;
      local Fragment s;

      if ( bOnlyTriggerable )
        return;
      if (Event!='')
        foreach AllActors( class 'Actor', A, Event )
          A.Trigger( Toucher, pawn(Toucher) );
      if ( Region.Zone.bDestructive )
      {
        Destroy();
        return;
      }
      for (i=0 ; i<NumFrags ; i++)
      {
        s = Spawn( FragType, Owner);
        s.CalcVelocity(Momentum,0);
        s.DrawScale = DSize*0.5+0.7*DSize*FRand();
      }

      GotoState('Absent');
    }

    state Absent
    {
    Begin:
      Health = InitialHealth; // restore health
      Vanish(true);

      Sleep( TimeToRespawn );

      Vanish(false);

      GotoState('Animate');
    }

Wormbo: You should toggle bHidden instead of changing the DrawType.

Tarquin: Thanks Had to sort out blocking as well. Mych will not like me calling that function Vanish() but I can't think of a better name

Wormbo: What about "SetVisibility" or "SetHidden"?

Tarquin: Great! Thanks

Foxpaw: It might not hurt to have both, sort of. It's a little bit of overhead at the interpreter level, but not that big of a deal. In my GUI classes I use a SetHidden function, then a Show and Hide function that are just one-line functions that call SetHidden( false ) and SetHidden( true ) respectively. Effectively it's the same, but I guess it kind of helps the readability. If you're into that sort of thing.

Tarquin: I was thinking this could make a tutorial about subclassing and states, but it's not very neat what with inheriting one state from Barrel and a load of code from Decoration. So I guess for SetHidden it's a case of what's clearest for people to read. Your idea of Show() just being a call to setHidden is neat, but I don't know how easy to grasp it would be.

Category Class (UT2003)

Category Custom Class

Category Tutorial

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In