Real Clocks

Thanks to BDB on the Chimeric forum for pointers

How to use

  1. Find the 'base class'. For the alarm clock it's a 'triggers'. In the Info view, find Triggers, right-click on Trigger and hit New...
  2. To save it just in your map, the package should be MyLevel. To save to a seperate package, give another name. (I may make a package of zones, clocks, triggers, etc.) If it's a mutator, you should give it another name.
  3. Give the thing a name, I suggest you use the same names I used, but you can use others.
  4. Copy from my page, paste to that code window.
  5. Compile changed scripts. (tools/compile changed)
  6. Info window, View/show packages, select the package (MyLevel for instance), and Save


Then each item depends on what you want to do. AlarmClock is a trigger, so use it like one. ClockHands are movers, so you create your clock hand however you would like, like a normal mover. When you want to make a ClockHand mover, position your maker brush, then right-click on the 'add mover' tool button (Not the menu 'Add Mover') and select ClockHand. The settings are commented in the code. After placing your item in your map, select it, and the new properties should be available to you.

Here is an AlarmClock, which you can set to fire a message and/or trigger an event. Make time-bombs for you maps!

AlarmClock.uc

//=============================================================================
// AlarmClock. Fires event at given time, displays optional message as well. Note, Level also contains the date
// and day of week, if you find that useful.
//=============================================================================
class AlarmClock expands Triggers;

var () int AlarmHour;
var () int AlarmMinute;
var () int AlarmSecond;
var () string AlarmMessage;
var() bool bShowMessage; // Display alarm message?

// Note: it might be more efficient to set a 1-second timer in BeginPlay and call this Timer instead of Tick
function Tick( float DeltaTime )
{

local actor A;
if (Level.Second == AlarmSecond && Level.Minute == AlarmMinute && Level.Hour == AlarmHour)
{
// Trigger all matching actors.
if ( bShowMessage && AlarmMessage != "" )
BroadcastMessage( AlarmMessage );
if ( Event != '' )
foreach AllActors( class 'Actor', A, Event )
A.Trigger( self, None );

}
}

defaultproperties
{
}

/// end of alarmclock


And here is a Mover, ClockHand, which rotates as minute, seconds, and/or hours tick by, so you can make real analog clocks in your level. Great for office clocks, clock towers, etc.

ClockHand.uc

//=============================================================================
// ClockHand. Make a brush, select ClockHand, then Add Mover button. Rotates like an analog clock. When placing,
// you need to set the Orientation to fit the wall or floor, see below. If you want to rotate the clock, so that 12 o'clock
// points in a different direction, you can do that with normal rotation in the editor.
//=============================================================================
class ClockHand expands Mover;

var () rotator Orientation; // normally: yaw=1, others=0 for a floor clock, roll=1, others = 0,
//or pitch=1, others =0, for wall clocks.
// If the clock is rotated any other way, try to match the Rotation you set for the clock face.

var() enum EClockHandType
{
CL_Seconds, // Tracks seconds
CL_Minutes, // tracks minutes
CL_Hours, // tracks hours
} ClockHandType;

var() enum EClockHourType
{
CH_Normal, // 12-hour
CH_Military // 24-hour
} ClockHourType;

var rotator OrigRotation;
var int lastSec;
var int lastMin;
var int lastHour;

function BeginPlay()
{
OrigRotation = Rotation;
lastSec = -1;
lastMin = -1;
lastHour = -1;

}


// Note: it might be more efficient to set a 1-second timer in BeginPlay and call this Timer instead of Tick

function Tick( float DeltaTime )
{
// optimization: don't bother if tick is in same second
if ((Level.Second != lastSec) || (Level.Minute != lastMin) || (Level.Hour != lastHour))
{

// there are 65536 units per circle, hence 65536/60 units per second or minute
if (ClockHandType == CL_Seconds)
// perhaps if this next operation were a cross product, it would be easier to arbitrarily rotate the whole thing?
SetRotation( OrigRotation + (Orientation * Level.Second * 1092.27) );

else if (ClockHandType == CL_Minutes)
SetRotation( OrigRotation + (Orientation * Level.Minute * 1092.27) );
else // hours
{
if (ClockHourType == CH_Normal)
SetRotation( OrigRotation + (Orientation * Level.Hour * 5461.33) );

else // military
SetRotation( OrigRotation + (Orientation * Level.Hour * 2730.67) );
}
lastSec = Level.Second;
lastMin = Level.Minute;
lastHour = Level.Hour;
}

}

defaultproperties
{

Orientation=(Roll=1)
}

/// End of ClockHand

Coming soon: timed alarms, so you can fire events, like sounds, every so often. Cuckoo clocks, Big Ben, etc. Maybe a talking clock too.


Back To Unreal Realm Of Concepts Home