Event Triggers and time - what kind of time is it using?
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Event Triggers and time - what kind of time is it using?
On both random time and time triggers, the time that is returned if I list an existing triggers properties is not unix epoch time. It has way more zeroes.
This is a time trigger set to 8/10/18 5:39:15PM
If I list it using the lua console I get:
local a = ScenEdit_SetTrigger({mode="list", name="time"})
print(a)
{ triggers = { [1] = { Time = { ID = '6a2234f1-f274-4fb0-aaa1-ac8d7dba5747', Description = 'time', Time = '636695195550000000' },
xml = '<EventTrigger_Time><ID>6a2234f1-f274-4fb0-aaa1-ac8d7dba5747</ID><Description>time</Description><Time>636695195550000000</Time></EventTrigger_Time>' } } }
How can I convert the current time into something I can use in a trigger I create?
Current time in the game is 30 minutes before then, but still this is a way different number:
local time = ScenEdit_CurrentTime ()
print(time)
1533920955
compared to:
636695195550000000
If I drop all the zeroes it looks like seconds = I did a random time and subtracted the 2 values and the difference was the same as seconds without all the 0s.
This is a time trigger set to 8/10/18 5:39:15PM
If I list it using the lua console I get:
local a = ScenEdit_SetTrigger({mode="list", name="time"})
print(a)
{ triggers = { [1] = { Time = { ID = '6a2234f1-f274-4fb0-aaa1-ac8d7dba5747', Description = 'time', Time = '636695195550000000' },
xml = '<EventTrigger_Time><ID>6a2234f1-f274-4fb0-aaa1-ac8d7dba5747</ID><Description>time</Description><Time>636695195550000000</Time></EventTrigger_Time>' } } }
How can I convert the current time into something I can use in a trigger I create?
Current time in the game is 30 minutes before then, but still this is a way different number:
local time = ScenEdit_CurrentTime ()
print(time)
1533920955
compared to:
636695195550000000
If I drop all the zeroes it looks like seconds = I did a random time and subtracted the 2 values and the difference was the same as seconds without all the 0s.
RE: Triggers and time - what kind of time is it using?
if you drop the zeroes it looks like number of seconds since 0001-01-01 AD. Great. Guessing this is a .net thing.
So maybe I just need the number of seconds from then to 1/1/1970? 62136914400?
then could add to that the current time and have a working time to make a new trigger. I wonder how many seconds are in a year? do you count leap years? time is hard.
So maybe I just need the number of seconds from then to 1/1/1970? 62136914400?
then could add to that the current time and have a working time to make a new trigger. I wonder how many seconds are in a year? do you count leap years? time is hard.
RE: Triggers and time - what kind of time is it using?
this function seems to work:
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
pass in thenumber of seconds from now that you want to set a time for a trigger and it will convert that to the time I think it wants. Tested a couple times so far. The string format bit is because when you multiply it by 10000000 to get the correct number of zeroes it converts it to an exponent which it doesn't seem to like in the trigger.
is there a way to make a time based trigger in lua without doing this? I have only seen triggers for unit remains in area.
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
pass in thenumber of seconds from now that you want to set a time for a trigger and it will convert that to the time I think it wants. Tested a couple times so far. The string format bit is because when you multiply it by 10000000 to get the correct number of zeroes it converts it to an exponent which it doesn't seem to like in the trigger.
is there a way to make a time based trigger in lua without doing this? I have only seen triggers for unit remains in area.
RE: Triggers and time - what kind of time is it using?
Greetings, Salutations, and all that sort of rubbish!
If I understand what you are asking, the question is: is there an easy way to do an elapsed time?
Example: unit X enters the area, and after a period of time elapses event Y happens.
Do I understand what you are asking?
If I understand what you are asking, the question is: is there an easy way to do an elapsed time?
Example: unit X enters the area, and after a period of time elapses event Y happens.
Do I understand what you are asking?
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
RE: Triggers and time - what kind of time is it using?
in Lua I want to create a Trigger, at a set time, say 2 hours from whatever the current game time is.
key is that I need to be able to create it via lua.
key is that I need to be able to create it via lua.
RE: Triggers and time - what kind of time is it using?
Hello, again.
If you look at the LUA documentation:
Mission Mission. •guid: (string) The GUID of the mission. [READONLY]
•name: (string) Name of mission
•isactive: (bool) True if mission is currently active
•side: (string) Mission belongs to side
•starttime: (DateTime) Time mission starts
•endtime: (DateTime) Time mission ends
•type: (MissionClass) Mission class(patrol,strike,etc). [READONLY]
•subtype: (MissionSubClass) Mission class(asw,land,etc). [READONLY]
•SISH: (bool) 'Scrub if side human' tick box
•unitlist: ({ GUID }) A table of units assigned to mission. [READONLY]
•targetlist: ({ GUID }) A table of targets assigned to mission. [READONLY]
•aar: (AAR) A table of the mission air-to-air refueling options. [READONLY]
•ferrymission: (FerryMission) A table of the mission specific options. [READONLY]
•mineclearmission: (MineClearMission) A table of the mission specific options. [READONLY]
•minemission: (MineMission) A table of the mission specific options. [READONLY]
•supportmission: (SupportMission) A table of the mission specific options. [READONLY]
•patrolmission: (PatrolMission) A table of the mission specific options. [READONLY]
•strikemission: (StrikeMission) A table of the mission specific options. [READONLY]
•cargomission: (CargoMission) A table of the mission specific options. [READONLY]
It looks like YOU have to calculate the time, but the mission table does allow you to perform what you seek to do.
If you look at the LUA documentation:
Mission Mission. •guid: (string) The GUID of the mission. [READONLY]
•name: (string) Name of mission
•isactive: (bool) True if mission is currently active
•side: (string) Mission belongs to side
•starttime: (DateTime) Time mission starts
•endtime: (DateTime) Time mission ends
•type: (MissionClass) Mission class(patrol,strike,etc). [READONLY]
•subtype: (MissionSubClass) Mission class(asw,land,etc). [READONLY]
•SISH: (bool) 'Scrub if side human' tick box
•unitlist: ({ GUID }) A table of units assigned to mission. [READONLY]
•targetlist: ({ GUID }) A table of targets assigned to mission. [READONLY]
•aar: (AAR) A table of the mission air-to-air refueling options. [READONLY]
•ferrymission: (FerryMission) A table of the mission specific options. [READONLY]
•mineclearmission: (MineClearMission) A table of the mission specific options. [READONLY]
•minemission: (MineMission) A table of the mission specific options. [READONLY]
•supportmission: (SupportMission) A table of the mission specific options. [READONLY]
•patrolmission: (PatrolMission) A table of the mission specific options. [READONLY]
•strikemission: (StrikeMission) A table of the mission specific options. [READONLY]
•cargomission: (CargoMission) A table of the mission specific options. [READONLY]
It looks like YOU have to calculate the time, but the mission table does allow you to perform what you seek to do.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
RE: Triggers and time - what kind of time is it using?
That looks like it is for a mission, I need an Event Trigger, which I can see and set, the problem I am having is that the time - as far as I can tell - is not using the same type of time as the Scen time is - one is the Unix Epoch which is seconds from 1/1/1970, the other seems to be seconds from 1/1/0001 - though it is really 1/10,000,000 of a second for each second. Much more precise.
RE: Triggers and time - what kind of time is it using?
in Lua I want to create a Trigger, at a set time, say 2 hours from whatever the current game time is.
key is that I need to be able to create it via lua.
Whicker,
I’ve used a somewhat klunky method for time delay. It may not work for exactly what you want but here it is:
1. Set an initial start time trigger such as:
a. Unit destroyed.
b. Fixed time.
c. Random time.
d. Whatever.
2. On another player side when the initial trigger fires:
a. Create a mobile unit (say infantry).
b. Have it placed at spot that will take X time (based on unit’s speed and distance to target area)
c. Assign it to a mission that moves to pre-defined target area.
d. Fire the event you want when the unit enters the area.
e. Delete the unit or leave it with speed = 0.
It might take a little experimentation to get the travel time to what you want for your X.
I’ve used this method a couple of times and have been pleased with the results.
-Wayne Stiles
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
RE: Triggers and time - what kind of time is it using?
Wayne - are you doing that cause you can't set a specific time when you create the trigger via lua? that's on the right track of what I want to do. I do think I have the time part sorted out though - the function above seemed to work well, I still need to test it a lot more.
RE: Triggers and time - what kind of time is it using?
Perhaps we should ask for this feature... but I suppose we would have to figure out how we would want it to work before asking Dimitris.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
RE: Triggers and time - what kind of time is it using?
Wayne - are you doing that cause you can't set a specific time when you create the trigger via lua? that's on the right track of what I want to do. I do think I have the time part sorted out though - the function above seemed to work well, I still need to test it a lot more.
Pretty much. I agree that it would be nice if there were a "Wait" function that could be associated with an event or time.
Here is another method I’ve used to “Wait”:
1. An event happens and starts the "Waiting event".
2. The "Waiting event" triggers every five minutes and adds 1 to a non-player side score.
3. When that score exceeds a set amount your desired event(s) fires and the "Waiting Event" is turned off.
--
Waiting Start (Action) Triggered by an event such as embassy destroyed
ScenEdit_SetEvent ("Waiting", {IsActive = true})
--
Waiting Time Increment (Trigger)
Set to Five Minutes
--
Waiting (Event) Initially set to NOT active
Trigger = Waiting Time Increment (5 minutes)
Action = Waiting Count Check
--
Waiting Count Check (Some non player side) (Trigger)
Some non player side exceeds xx points
--
Waiting End (Action)
ScenEdit_SetEvent ("Waiting", {IsActive = false})
-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Triggers and time - what kind of time is it using?
The 'Time' contains nano-seconds rather than just seconds. It is from a .Net date/time conversion.
When setting up the date/time via Lua, you can use the real date as in
When setting up the date/time via Lua, you can use the real date as in
The command will covert the date/time to the .Net representation.local ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time='09/05/2016 23:03:55'})
print(ev)
local mytime = ScenEdit_CurrentTime ()
mytime = mytime + 2*60*60 -- 2 hours time
local newtime = os.date('%d/%m/%Y %H:%m:%S',mytime)
print(newtime)
ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time=newtime})
print(ev)
Michael
RE: Triggers and time - what kind of time is it using?
perfect. Thanks for the info.
RE: Triggers and time - what kind of time is it using?
one small correction:
the time part of that has %m - which is really month not Minutes, should be %M.
os.date('%d/%m/%Y %H:%M:%S',mytime)
os.date('%d/%m/%Y %H:%m:%S',mytime)
the time part of that has %m - which is really month not Minutes, should be %M.
os.date('%d/%m/%Y %H:%M:%S',mytime)
RE: Triggers and time - what kind of time is it using?
also needs to be utc time which needs the ! in front, and for me it wants the date as month/day/year not day/month/year so like:
newtime = os.date('!%m/%d/%Y %H:%M:%S',mytime)
I think I'll keep using my function above that converts from .net time to unix time.
newtime = os.date('!%m/%d/%Y %H:%M:%S',mytime)
I think I'll keep using my function above that converts from .net time to unix time.
RE: Triggers and time - what kind of time is it using?
ORIGINAL: michaelm75au
The 'Time' contains nano-seconds rather than just seconds. It is from a .Net date/time conversion.
When setting up the date/time via Lua, you can use the real date as inThe command will covert the date/time to the .Net representation.local ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time='09/05/2016 23:03:55'})
print(ev)
local mytime = ScenEdit_CurrentTime ()
mytime = mytime + 2*60*60 -- 2 hours time
local newtime = os.date('%d/%m/%Y %H:%m:%S',mytime)
print(newtime)
ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time=newtime})
print(ev)
Thank you AGAIN.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Triggers and time - what kind of time is it using?
Good catch. I had typed it correctly in console, but must have transposed it in error
ORIGINAL: Whicker
one small correction:
os.date('%d/%m/%Y %H:%m:%S',mytime)
the time part of that has %m - which is really month not Minutes, should be %M.
os.date('%d/%m/%Y %H:%M:%S',mytime)
Michael
RE: Triggers and time - what kind of time is it using?
So is this the correct syntax?
local newtime = os.date('!%m/%d/%Y %H:%M:%S',mytime)
And the whole function looks like this:
local ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time='09/05/2016 23:03:55'})
print(ev)
local mytime = ScenEdit_CurrentTime ()
mytime = mytime + 2*60*60 -- 2 hours time
local newtime = os.date('!%m/%d/%Y %H:%M:%S',mytime)
print(newtime)
ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time=newtime})
print(ev)
Sorry: I monkey with QuickBasic... LUA is new to me.
local newtime = os.date('!%m/%d/%Y %H:%M:%S',mytime)
And the whole function looks like this:
local ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time='09/05/2016 23:03:55'})
print(ev)
local mytime = ScenEdit_CurrentTime ()
mytime = mytime + 2*60*60 -- 2 hours time
local newtime = os.date('!%m/%d/%Y %H:%M:%S',mytime)
print(newtime)
ev = ScenEdit_SetTrigger({mode="update", type="Time", name="Trigger - time", time=newtime})
print(ev)
Sorry: I monkey with QuickBasic... LUA is new to me.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
RE: Triggers and time - what kind of time is it using?
If you want to create a new trigger, it could be something like:
local timeFromNow = 3600 -- one hour in seconds - time you want to add from current time in seconds
local myTime = ScenEdit_CurrentTime () --get the current time in unix time which is stored as seconds from 1/1/1970
local newTimeInSeconds = timeFromNow + myTime -- add the one to the other
local newTime = os.date('!%m/%d/%Y %H:%M:%S',newTimeInSeconds) --convert it to the right format m/d/year hh:mm:ss - otherwise it is just a really big number like 1533952956
print(newTime) --print it to see what it looks like
local newTrigger = ScenEdit_SetTrigger({mode="add", type="Time", name="New Trigger - time", time=newTime}) --add the trigger with the calculated time
I just did that in the console and it worked correctly. You should do it several times and make sure the 24 hour clock part works as well, I did 3600, 36000 and 48000 all looked good I think.
I'm sort of assuming that his code worked for him and that the date is different based on locale - so maybe in oz they do the date that way, and that is what it is expecting on his computer, but on mine the day first month second doesn't work. That or he got lucky and that example has month and days that were close enough to be interchangeable?
Would be nice to know what is going on with that.
local timeFromNow = 3600 -- one hour in seconds - time you want to add from current time in seconds
local myTime = ScenEdit_CurrentTime () --get the current time in unix time which is stored as seconds from 1/1/1970
local newTimeInSeconds = timeFromNow + myTime -- add the one to the other
local newTime = os.date('!%m/%d/%Y %H:%M:%S',newTimeInSeconds) --convert it to the right format m/d/year hh:mm:ss - otherwise it is just a really big number like 1533952956
print(newTime) --print it to see what it looks like
local newTrigger = ScenEdit_SetTrigger({mode="add", type="Time", name="New Trigger - time", time=newTime}) --add the trigger with the calculated time
I just did that in the console and it worked correctly. You should do it several times and make sure the 24 hour clock part works as well, I did 3600, 36000 and 48000 all looked good I think.
I'm sort of assuming that his code worked for him and that the date is different based on locale - so maybe in oz they do the date that way, and that is what it is expecting on his computer, but on mine the day first month second doesn't work. That or he got lucky and that example has month and days that were close enough to be interchangeable?
Would be nice to know what is going on with that.
RE: Triggers and time - what kind of time is it using?
if you run that multiple times make sure you change the name each time or it will error... (name="New Trigger - time")