In game timer using Special Action

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

In game timer using Special Action

Post by Whicker »

I frequently wished I could have the game remind me at a certain time about something - say 4 hours from now a sub will be going into a danger zone.

Using Special Actions and some lua code I think I have done it - not too hard and you can make as many timers as you want.

When you run the special action it will ask you the time in minutes from now you want the timer to go off, and what you want to name the timer/what the message should be once it goes off. It will then create an event with a time based trigger, and an action to pop up a special message box.

The code is pretty simple and all you have to do is make the special action and paste in the code below. I have not bothered to do anything about removing all the events/triggers/actions, but I suppose that could be done.

function TimerTimeFromNowDotNetTime(addSeconds) -- Time helper cause event time is weird
local time = ScenEdit_CurrentTime()
local offSet = 62135596801 --number of seconds from 01-01-0001 to 01-01-1970
local newTime = (time + offSet + addSeconds)*10000000
local timeToUse = string.format("%18.0f",newTime)
return timeToUse
end

function CreateTimerEvent(minutes,message)
local t = ScenEdit_CurrentTime() --need to add something to the names to make them unique, using time
ScenEdit_SetEvent(minutes.." Minute Timer ("..message..")"..t, {mode="add",IsRepeatable=0})
ScenEdit_SetTrigger({mode="add", type="Time", name=minutes.." Minute Timer Trigger ("..message..")"..t, Time=TimerTimeFromNowDotNetTime(minutes*60) })
ScenEdit_SetAction({mode="add", type="LuaScript", name=minutes.." Minute Timer Action ("..message..")"..t,
scriptText='ScenEdit_SpecialMessage (ScenEdit_PlayerSide(),"Your Timer is Up: '..message..' ")'})
ScenEdit_SetEventTrigger(minutes.." Minute Timer ("..message..")"..t, {mode="add", name=minutes.." Minute Timer Trigger ("..message..")"..t})
ScenEdit_SetEventAction(minutes.." Minute Timer ("..message..")"..t, {mode="add", name=minutes.." Minute Timer Action ("..message..")"..t})
end

local timerMinutes = ScenEdit_InputBox('How long do want the timer to be in minutes?')
print('Response was ' ..timerMinutes)
local timerMessage = ScenEdit_InputBox('What do you want to call the timer?')
print('Response2 was ' .. timerMessage)
CreateTimerEvent(timerMinutes,timerMessage)

Attachments
InGameTimer.zip
(3.69 KiB) Downloaded 22 times
i224747
Posts: 89
Joined: Fri Nov 06, 2015 1:19 am

RE: In game timer using Special Action

Post by i224747 »

Thanks.

Also a countdown timer:
http://free-countdown-timer.com/


(2.8MB download size, free to use, released 01/2016)

Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: In game timer using Special Action

Post by Whicker »

but that isn't game time...
User avatar
Primarchx
Posts: 1954
Joined: Sun Jan 20, 2013 9:29 pm

RE: In game timer using Special Action

Post by Primarchx »

I was wishing for an in-game timer since Day 1. Thanks for this option!
User avatar
daveoreno
Posts: 65
Joined: Sat Aug 27, 2016 10:10 am
Location: Toronto, Canada

RE: In game timer using Special Action

Post by daveoreno »

I too have always wanted something like this. I long ago added it to the wish list.

Thanks.
User avatar
KC45
Posts: 310
Joined: Thu Nov 23, 2017 8:35 pm
Location: JPN

RE: In game timer using Special Action

Post by KC45 »

How about making like this two events.

make Event1:EventAction with lua code of [ScenEdit_SetEvent('name of Event2', {Isactive=true})]
make event2:with trigger-Regular time.

Once Event1 launched, Event2 is going active. Regular time starts countdown at decided time. And you guys don't have to write long long script.

It works and simpler I guess.
Wargame is fun if war is unreal
Post Reply

Return to “Mods and Scenarios”