Thanks to BDB on the Chimeric forum for pointers
How to use
|
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.