Scripting - Display Current Time

By Ronbocop
Offline
  • Posts: 5
  • Joined: Oct 2009
  • Link

Ronbocop says...

--[[
=================================================
***Display the Current Time***
Ron "Ronbocop" Carroll
=================================================
I wrote this because I needed to have players
reach an objective by a certain time to observe
some event that I was planning.
I couldn't find any reference to display the
time except for the mission time, which doesn't
help players to know that they are 23mins into
the game after an arbitrary mission start time
of 11:45 in the morning, especially since my
mates just skip the whole menu thing to get into
the game. This game also does not have a watch
a la ARMA either.
To do this I had to get the script to know
what time it was at the start of the mission.
This is the time that is set up in the Mission
Properties area under Environment, Date & Time.
In my case this was 2009/12/05 21:03 (my team
having landed on site around 21:00 and having
unloaded the ingress boat of a cache of weapons.

IMPORTANT: If you decide to change your mission
start time, do not forget to change the
"CurrentTime" parameter to match

IMPORTANT: Remember that onTimer is one of the
few commands that does not have an underscore,
"_" to separate the function-type from the
function-name.

You can call the displayCurrentTime()
function at any point you wish, ie, after
destroying an objective, retrieving some intel
or whatever. It will not interfere with you
minute by minute update.

Hope this fleshes out your missions &
campaigns. Enjoy
=================================================
]]
function onMissionStart()
--Display Current Mission Time
displayCurrentTime()

--Call routine to Display Current Time
--again after a minute
OFP:addTimer("DisplayTime",60000) --60x1000msec
end


--Display the CurrentTime
function displayCurrentTime()
--Mission time at start = 0
--21x60 mins per hour x60 secs per minute x1000msec
--to give 21:00hrs or 9pm +
--3x60 secs per minute x1000msec
--to give xx:03mins
CurrentTime = OFP:getMissionTime() + (21*60*60*1000) + (3*60*1000)
--Format for obtaining readable time from a calculated
--number in millisecongds
Hours, Minutes, Seconds = OFP:convertTimeToHMS(CurrentTime)
--Since 21:3:0 does not look like readable time you
--need to inflate or insert a zero into the text
if Minutes < 10 then
Minutes = "0" .. Minutes
end
if Seconds < 10 then
Seconds = "0" .. Seconds
end
--The "double full stops" is Lua's concatenate function
--The result will be a message in the bottom left corner
--ie "The Current Time is:- 21:03:00"
OFP:DisplaySystemMessage("Current Time is:- " .. Hours .. ":" .. Minutes .. ":" .. Seconds)
end

--Call the time every minute
function onTimerDisplayTime()
--[[You may delete the DisplayTime() timer here if you
wish as per normal but I haven't had a problem with it.]]
--OFP:removeTimer()

--Call the displayCurrentTime() function again
displayCurrentTime()
--Initiate this timer again to run 1min later
OFP:setTimer("DisplayTime",60000)
end
Offline
  • Posts: 5
  • Joined: Oct 2009
  • Link

Ronbocop says...

Sorry but that smiley is added by this editor, it should be OFP: displaySys.... without the space

Apologies for having posted it here too, seems a lot of trouble to arrange for free web hosting and creation of an image (just think of a watch) just for a script.

Hope someone finds it useful

Cheers
Ronbocop
Sorry, you need to be logged in and have a validated account to post on the forums.

OFPHQ Stats

Users Online

(Members: 0, Guests: 10)

twitter