Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Advise on modifying a Time Trigger

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Advise on modifying a Time Trigger Page: [1]
Login
Message << Older Topic   Newer Topic >>
Advise on modifying a Time Trigger - 2/6/2020 1:37:28 AM   
Primarchx


Posts: 3102
Joined: 1/20/2013
Status: offline
Here's some pseudocode for what I'm trying to do...

currtime = ScenEdit_CurrentTime()
-- reset a Timer Trigger to equal the current time + 10minutes (600 seconds)
local triggertime = ScenEdit_SetTrigger({mode='update',type='Time', name="TRIGGER All Clear", time = currtime+600})
---------------

So the whole thing here is how do I set that time as currtime+600? The Time field indicates it wants a date/time (so is that a string?). CurrentTime() gives a big number of seconds. Do I have to translate that? If so, what's the format? I'd do some testing but I'm out of town for a little while. Any pointers?
Post #: 1
RE: Advise on modifying a Time Trigger - 3/12/2020 11:59:33 PM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
So you need to convert times. The ScenEdit_CurrentTime returns a TimeStamp, which is a UTC Unix Timestamp of elapsed seconds since some point in 1970.

local currtime = ScenEdit_CurrentTime()
print(currtime)

Will return 1584065280. The trigger though needs DateTime, which is MM/DD/YYYY HH:MM:SS AM/PM.

Now you can't do math on DateTime so we do the math on the TimeStamp.

local currtime = ScenEdit_CurrentTime() --Get the current UTC Time
print(currtime)
local futuretime = currtime + 300 --Add 300 seconds to the UTC Time
print(futuretime)
local convtime = (os.date('%m-%d-%Y %H:%M:%S %p', futuretime)) --Convert the future time to DateTime
print(convtime)

Now you can use your ScenEdit_SetTrigger.

ScenEdit_SetTrigger({mode='update',type='Time', name="TimeTrigger", time = convtime})







_____________________________


(in reply to Primarchx)
Post #: 2
RE: Advise on modifying a Time Trigger - 3/13/2020 12:25:40 AM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
To add to this a bit. You can totally create an entire event, lua and all. In this example I wanted a radar to shut itself off if under attack. But then I wanted it to turn itself back on again in a few minutes.

local triggerunit = 'Radar PS' --This would be tied to UnitY() in the real script and likely use the guid.

ScenEdit_SetTrigger({mode='add',type='Time', name= triggerunit, time = convtime}) --Take our converted time value from above and make a future time trigger.

ScenEdit_SetAction({mode='add', type='LuaScript', name= 'triggerunitAction', ScriptText ="ScenEdit_SetEMCON('Group', 'VisbyGroup', 'Inherit;Radar=Active')"}) -- Add an action that changes the EMCON back to active.

ScenEdit_SetEvent('TimeTest Event', {mode='add', isActive=True}) -- Create the event. Would tie it in to UTC timestamp
above.
ScenEdit_SetEventTrigger('TimeTest Event', {mode='add', name=triggerunit}) --Add the trigger to the event.
ScenEdit_SetEventAction('TimeTest Event', {mode='add', name='triggerunitAction'}) -- Add the action to the event.

Hope this helps!

_____________________________


(in reply to TitaniumTrout)
Post #: 3
RE: Advise on modifying a Time Trigger - 3/13/2020 12:57:33 AM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
Further the rabbit hole takes us!

I think we'll run into issues with static names. So I've got it set to the guid. But say that same unit gets triggered again, the script will fail as it's trying to add events that already exist. So either we need to check if it's not nil, or we trash collect and delete the trigger, action, and event. If you go the if route you'll have to 'update' the trigger with a different time. Trash collecting might still be a good idea as a large scenario could quickly get a huge list of guid triggers, actions, and events. Trash collecting would be done by using \r\n to get new lines on the ScriptText part of the SetAction. Then when the new time trigger fires it will delete everything and the script can start fresh.

Once I work it into a scenario I'll post it up as an example.

local detectingunit = ScenEdit_UnitY()
print(detectingunit.unit.guid)

local currtime = ScenEdit_CurrentTime()
print(currtime)
local futuretime = currtime + 300
print(futuretime)
local convtime = (os.date('%m-%d-%Y %H:%M:%S %p', futuretime))
print(convtime)

local triggerunit = detectingunit.unit.guid

ScenEdit_SetTrigger({mode='add',type='Time', name='trigger'.. triggerunit, time = convtime})

ScenEdit_SetAction({mode='add', type='LuaScript', name= 'triggerunitAction'..triggerunit, ScriptText ="ScenEdit_SetEMCON('Group', 'VisbyGroup', 'Inherit;Radar=Passive')"})

ScenEdit_SetEvent('TimeTest Event'..triggerunit, {mode='add', isActive=True})

ScenEdit_SetEventTrigger('TimeTest Event'..triggerunit, {mode='add', name='trigger'.. triggerunit})
ScenEdit_SetEventAction('TimeTest Event'..triggerunit, {mode='add', name='triggerunitAction'..triggerunit})

_____________________________


(in reply to TitaniumTrout)
Post #: 4
RE: Advise on modifying a Time Trigger - 3/13/2020 6:23:49 AM   
Zanthra

 

Posts: 122
Joined: 2/6/2019
Status: offline
What about using a global variable as a serial number for creating the trigger names?

if not _G.triggerSerialID then
_G.triggerSerialID = 1
end
ScenEdit_SetTrigger({mode='add',type='Time', name='trigger'.._G.triggerSerialID, time = convtime})
...
_G.triggerSerialID = _G.triggerSerialID + 1

< Message edited by Zanthra -- 3/13/2020 6:40:34 AM >

(in reply to TitaniumTrout)
Post #: 5
RE: Advise on modifying a Time Trigger - 3/13/2020 10:39:12 AM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
That works too! I ended up just appending the time it's supposed to trigger to the GUID. I'm trying to find a good way to see if a trigger/action exists, going to dig into it more today. After that it'll be adding the deletion actions...


quote:

ORIGINAL: Zanthra

What about using a global variable as a serial number for creating the trigger names?

if not _G.triggerSerialID then
_G.triggerSerialID = 1
end
ScenEdit_SetTrigger({mode='add',type='Time', name='trigger'.._G.triggerSerialID, time = convtime})
...
_G.triggerSerialID = _G.triggerSerialID + 1



_____________________________


(in reply to Zanthra)
Post #: 6
RE: Advise on modifying a Time Trigger - 3/13/2020 3:28:46 PM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
Here we go! This cleans out the old triggers at the same time as sending the all clear.

local detectingunit = ScenEdit_UnitY()
print(detectingunit.unit.guid)

local currtime = ScenEdit_CurrentTime()
print(currtime)
local futuretime = currtime + 300
print(futuretime)
local convtime = (os.date('%m-%d-%Y %H:%M:%S %p', futuretime))
print(convtime)

local triggerunit = detectingunit.unit.guid .. convtime

local triggergroup = detectingunit.unit.group.name
print(triggergroup)


ScenEdit_SetTrigger({mode='add',type='Time', name='trigger'.. triggerunit, time = convtime})

local SetEMCON = "ScenEdit_SetEMCON('Group', '"..triggergroup.."', 'Inherit;Radar=Active')"
local RemoveT = "ScenEdit_SetTrigger({mode='remove', type = 'Time', name='trigger"..triggerunit.."' })"
local RemoveA = "ScenEdit_SetAction({mode='remove', type = 'Luascript', name= 'triggerunitAction"..triggerunit.."'})"
local RemoveE = "ScenEdit_SetEvent('TimeTest Event"..triggerunit.."', {mode='remove'})"
--Must delete event first, then delete action and trigger.
local ScriptTextComp = SetEMCON.. "\r\n" ..RemoveE.. "\r\n" ..RemoveA.. "\r\n" ..RemoveT.. "\r\n" 
print(ScriptTextComp)

ScenEdit_SetAction({mode='add', type='LuaScript', name= 'triggerunitAction'..triggerunit, ScriptText = ScriptTextComp})

ScenEdit_SetEvent('TimeTest Event'..triggerunit, {mode='add', isActive=True})

ScenEdit_SetEventTrigger('TimeTest Event'..triggerunit, {mode='add', name='trigger'.. triggerunit})
ScenEdit_SetEventAction('TimeTest Event'..triggerunit, {mode='add', name='triggerunitAction'..triggerunit})




..

< Message edited by TitaniumTrout -- 3/13/2020 3:29:05 PM >


_____________________________


(in reply to TitaniumTrout)
Post #: 7
RE: Advise on modifying a Time Trigger - 4/13/2020 3:20:27 PM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline

I've taken this script above and tried to adopt it to my Special Actions. I think it will work but have a couple questions:

Requirement: The Special Action will activate a cell of bombers. I want the player to have use of them for 48 hours (including the 20hr load time) so that s/he gets one mission. As part of the special action this coded is included:


quote:

----Time Trigger--------------
---Special Action code---
local currtime = ScenEdit_CurrentTime()
print(currtime)
local futuretime = currtime + 172800 ----48 hrs is there a better way of saying this
print(futuretime)
local convtime = (os.date('%m-%d-%Y %H:%M:%S %p', futuretime))
print(convtime)



local SetEvent = "ScenEdit_SetEvent (Delete Alpha cell, true, false, false)"
local SetTrigger = "ScenEdit_SetTrigger({mode='add',type='Time', name='Alpha Cell delete', time = convtime})"
local ExecuteAction = "ScenEdit_ExecuteEventAction({'deleteAlpha'})"


When I test it in the Console things seem to work correctly - which put me in a state of shock so I think something MUST be wrong

The return in the console is:

quote:

local SetEvent = "ScenEdit_SetEvent (Delete Alpha cell, true, false, false)"
local SetTrigger = "ScenEdit_SetTrigger({mode='add',type='Time', name='Alpha Cell delete', time = convtime})"
local ExecuteAction = "ScenEdit_ExecuteEventAction({'deleteAlpha'})"
763977600
764150400
03-20-1994 08:00:00 AM


Questions:

I don't see a new mission or trigger created in those menus - are they simply in the background?
How can I check that?
How do I clear it so that the player is starting from a fresh time stamp?
I there a better way than to add 48hrs in seconds, is there a notation for minutes, hours or days?

Thanks.


_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to TitaniumTrout)
Post #: 8
RE: Advise on modifying a Time Trigger - 4/13/2020 11:25:51 PM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
To use an existing script as example:
quote:

-- Create Event
ScenEdit_SetEvent("Event - Cancel Pilot "..downedPilot.guid, {mode="add",IsRepeatable=0})

-- Create Trigger
ScenEdit_SetTrigger({mode="add", type="RegularTime", name="Trigger - Cancel Pilot "..downedPilot.guid, interval=randInterval})

-- Create Action
ScenEdit_SetAction({mode="add", type="LuaScript", name="Action - Cancel Pilot "..downedPilot.guid, scriptText="StartSARFailedTargetPickup(ScenEdit_EventX())"})

-- Set Triggers And Actions to an event
ScenEdit_SetEventTrigger("Event - Cancel Pilot "..downedPilot.guid, {mode="add", name="Trigger - Cancel Pilot "..downedPilot.guid})
ScenEdit_SetEventAction("Event - Cancel Pilot "..downedPilot.guid, {mode="add", name="Action - Cancel Pilot "..downedPilot.guid})


_____________________________

Michael

(in reply to Gunner98)
Post #: 9
RE: Advise on modifying a Time Trigger - 4/13/2020 11:44:03 PM   
Whicker

 

Posts: 664
Joined: 6/20/2018
Status: offline
isn't there a problem with using the os.date conversion? the scen is set in a specific time zone, it is not likely the time zone of the player - is it giving you a UTC date/time? or the time in the timezone of the locale of the user? I can't wrap my head around that.

at some point I think Michaelm posted a code sample and when I ran it locally the time in the game was off by a few time zones.

So I used a converted to the real game time the triggers use which is different than the seconds from 1/1/1970 - I think it is mili-seconds from then? looks like from 1-1-0001 not 1970 and then in 10millionths of a second?

quote:


-- Time helper
function timeFromNowDotNetTime(addSeconds)
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

timeFromNowDotNetTime(600) -- change to game time the triggers use 10 minutes from now.



(in reply to michaelm75au)
Post #: 10
RE: Advise on modifying a Time Trigger - 4/14/2020 12:13:00 AM   
Whicker

 

Posts: 664
Joined: 6/20/2018
Status: offline
i think (os.date('%m-%d-%Y %H:%M:%S %p', futuretime)) works fine - I think the example I had trouble with must have manually changed the month or the day and since the position of the day or month varies based on locale it didn't work? i don't think it was a time zone - i think it was a different date cause my locale is month-day-year and his is day-month-year.

or maybe someone in another locale would write it as %d-%m-%Y? would someone who writes the date as 4 April 1999 be able to use the os.date in this order: (os.date('%m-%d-%Y %H:%M:%S %p', futuretime))?

(in reply to Whicker)
Post #: 11
RE: Advise on modifying a Time Trigger - 4/14/2020 5:06:55 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
@Gunner98

Check out the attached test rig, I think it demos the basics of what you want.

- a Special action that goes and creates strike aircraft sticks them in a base, records their guid's into keys so we know who should be deleted later and it persists across sessions and creates or updates an timed event to effect the removal 48hr later in game time.

It's comprised mainly of the SA, 1 generated event, 1 generated trigger, and two LUA action scripts.
The additional every 1 second event and action relates to working around the time issues outside events.

When you load the scene choose side a.
Look around, press play and then try the special action, look at events\triggers again (you'll see the new ones).
If you don't want to wait 48hr for removal...just tweak the generated timedBomberRemoval trigger time... or alternatively before using the SA edit the special action and change the seconds from 72800 to like 10.



Attachment (1)

(in reply to Gunner98)
Post #: 12
RE: Advise on modifying a Time Trigger - 4/14/2020 10:22:18 AM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
Thanks everyone, appreciate the help. Should be able to check these methods out later in the day.

Cheers

B

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to KnightHawk75)
Post #: 13
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Advise on modifying a Time Trigger Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.000