Here you go. Copy/Paste this in a text editor, and mylevel it to your map.
Code: Select all
/*================================================
TriggerCounter
A simple trigger that keeps track of the time.
Warning: This trigger spams the chat log.
Author: DW>Ant
Date: August 10, 2010
================================================*/
class TriggerCounter extends Triggers
placeable;
var() bool bCountDown; //If True, it'll count down. False counts up
var() int Interval; //Seconds per Second
var() int StartingHour;
var() int StartingMinute;
var() int StartingSecond;
var() int TriggerHoursInc; //Increment x many hours per trigger
var() int TriggerMinutesInc; //Increment x many Minutes per trigger
var() int TriggerSecondsInc; //Increment x many seconds per trigger
//Internal variables. If you're copy/pasting this through UEd Text editor, then you may have to invert the FirstTrigger bool to NotFirstTrigger
var float Time;
var bool bCounting;
var bool bFirstTrigger;
var int Hour, Minute, Second;
function Trigger(actor Other, Pawn EventInstigator)
{
if (bCounting)
bCounting = false;
else
bCounting = true;
if (bFirstTrigger)
{
Hour = StartingHour;
Minute = StartingMinute;
Second = StartingSecond;
bFirstTrigger = false;
}
else //Increment the time
{
if (bCountDown)
{
Second = Second - TriggerSecondsInc;
if (Second < 0)
{
Minute--;
Second += 60;
if (Minute < 0)
{
Hour--;
Minute = 59;
if (Hour < 0)
Hour = 24;
}
}
//Inc Minutes
Minute = Minute - TriggerMinutesInc;
if (Minute < 0)
{
Hour--;
Minute += 60;
if (Hour < 0)
Hour = 24;
}
//Inc Hours
Hour = Hour - TriggerHoursInc;
if (Hour < 0)
Hour += 24;
}
else //Counting up
{
Second = Second + TriggerSecondsInc;
if (Second > 59)
{
Minute++;
Second -= 60;
if (Minute > 59)
{
Hour++;
Minute = 0;
if (Hour > 24)
Hour = 0;
}
}
//Inc Minutes
Minute = Minute + TriggerMinutesInc;
if (Minute > 59)
{
Hour++;
Minute -= 60;
if (Hour > 24)
Hour = 0;
}
//Inc Hours
Hour = Hour + TriggerHoursInc;
if (Hour < 0)
Hour -= 24;
}
}
}
function Tick(float DeltaTime)
{
if (bCounting)
{
if (bCountDown)
{
if (int(Time - DeltaTime) == int(Time-1))
{
//Time = Time + 1;
Second = Second - Interval;
if (Second < 0)
{
Minute--;
Second += 60; //Incase you have Intervals > 1. This will be buggy if Interval > 60 (negative seconds). If that's the case, then just create a new class and remove seconds.
if (Minute < 0)
{
Hour--;
Minute = 59;
if (Hour < 0)
Hour = 24;
}
}
Level.Game.Broadcast(None, Hour @ ":" @ Minute @ ":" @ Second);
}
Time -= DeltaTime;
}
else //Counting up
{
if (int(Time + DeltaTime) == int (Time+1))
{
//Time = Time - 1;
Second = Second + Interval;
if (Second > 59)
{
Minute++;
Second -= 60;
if (Minute > 59)
{
Hour++;
Minute = 0;
if (Hour > 24)
Hour = 0;
}
}
Level.Game.Broadcast(None, Hour @ ":" @ Minute @ ":" @ Second);
}
Time += DeltaTime;
}
}
super.Tick(DeltaTime);
}
//In UEd Text Editor, this will not work. You'll need to edit these variables manually, but since FirstTrigger is a hidden property, you'll need to delete that.
defaultproperties
{
bFirstTrigger=True
Interval=1
Texture=Texture'Gameplay.S_Counter'
}
If you're using the Unread Ed's Text editor, then you cannot include the defaultproperties section.
You can either edit this code to invert the bFirstTrigger property to bNotFirstTrigger. Then edit the If statement around line 35 "if (bFirstTrigger)" to "if (!NotFirstTrigger)" ! means if false. By default Boolean variables are set to false. Then a few lines down, don't forget to edit the line "bFirstTrigger = false;" to "bNotFirstTrigger = true;"
-or-
Save the code as it is and open the editor's console and type in: editdefault class=TriggerCounter. It should open the properties window, but you should see an additional None category. From there, you can edit any default properties for this class. In this case, go to bFirstTrigger, and change that to True. I warn you though, be very careful when editing default properties. It's worse than renaming stock packages. If you think you should edit hidden properties for other classes, be sure to subclass the class you want to edit, then edit the default properties for your myleveled new class. That way you don't have to worry about screwing up your UT installation.
The other two properties (Interval and Texture) are no biggie. You can edit those once you place this actor in your map.
How to use this actor:
Simple, give it a tag, then trigger the tag.
It will start counting either up or down.
Trigger the tag again to stop the counting.
Trigger it again to resume.
To skip values (I'm sure no match will last for 24 hours). Simply edit the TriggerSecondsInc, TriggerMinutesInc, and/or TriggerHoursInc to skip this many values per trigger. (note, your going to pause the trigger if you trigger it once, so you'll have to trigger this twice to make it resume. In another words, you'll need to half your increments since you'll be applying them twice).
The other property names are self-explanatory.
If there's something troubling you, let me know.[/color]