GPS data report in message log every 5 minutes

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
Orzel
Posts: 8
Joined: Wed Jan 10, 2024 12:20 pm

GPS data report in message log every 5 minutes

Post by Orzel »

Hi, once again I am forced to ask for your help.

I'm working on creating GPS data reports for a specific vessel's location, intending to display them in the message log every 5 minutes. I successfully crafted a function to print the GPS data, but I'm facing challenges with implementing the time interval event to trigger the GPS data script. I've attempted to set up the event, but I lack the necessary knowledge on how to proceed.

I'd like to ask if there are additional sources of information available on setting up events through Lua, apart from the Command Lua API Documentation. Alternatively, if someone has already accomplished something similar, I'd greatly appreciate any provided instructions.

My primary objective is to establish an event that activates a specific script every 5 minutes. If relevant, the existing "message" script utilizes the SpecialMessage function.

Thank you in advance for your support.
Kind Regards
User avatar
blu3s
Posts: 1122
Joined: Fri Jul 08, 2022 9:45 am

Re: GPS data report in message log every 5 minutes

Post by blu3s »

You have RegularTime trigger that fits with what you need.

You have apart from the Official documentation and the forum the following resources for Lua, not all cover events but probably you will find useful information:

Inside the Command installation there is a folder called Lua with numerous scripts with examples of different functionalities. You can search through these scripts for examples of using a certain function.

There's a YouTube channel with some content about Lua scripting that may be worth it to have a check (some functionality may refer to PRO version only): https://www.youtube.com/@MatrixProSims

Lua Snippets created by civilian users that you can check here: https://github.com/GrandStrategos/Comma ... 20Snippets
Orzel
Posts: 8
Joined: Wed Jan 10, 2024 12:20 pm

Re: GPS data report in message log every 5 minutes

Post by Orzel »

Thank you for your response.
I successfully configured the event using the RegularTime trigger. However, I am currently facing a different issue – how to link two components together?
Here is the code for the message:

Code: Select all

-- The message 1
local function testme(a)
    if a == nil then a = false; end
    local untb1 = ScenEdit_GetUnit({type='Ship', unitname ='ASW hunter1'});
local event_description = 'UNKNOWN EVENT';
    local iff = 'SIGMA';
    local fmt;
    if a then 
        fmt = 'Event: %s\r\n\r\nUnit: [%s] - %s , %s\r\n\r\nAltitude: %s\r\n\r\nLat: %s\r\n\r\nLon: %s\r\n\r\nSpeed: %s\r\n'
    else 
        fmt = 'Event: %s\r\nUnit: [%s] - %s , %s\r\nAltitude: %s\r\nLatitude: %s\r\nLongitude: %s\r\nSpeed: %s\r\n'
    end
    local msg = string.format(fmt,event_description,untb1.name,untb1.type,untb1.classname,untb1.altitude,untb1.latitude,untb1.longitude,untb1.speed);
    return msg
end
ScenEdit_SpecialMessage('Blue', testme(false))
And now I need to "plug it" into the event code, however I trully don't know how to do that so the message pops in the "Message log" window.
Event code:

Code: Select all

ScenEdit_SetTrigger({mode='add',type='RegularTime', name= 'triggerCourse', Interval = 5}) 
ScenEdit_SetAction({mode='add', type='LuaScript', name= 'ActionCourse', ScriptText ="I BELIEVE HERE SHOULD BE ADDITIONAL RELATION TO THE MESSAGE FUNCTION"})

ScenEdit_SetEvent('Course', {mode='add', isActive=True})
ScenEdit_SetEventTrigger('Course', {mode='add', name='triggerCourse'}) 
ScenEdit_SetEventAction('Course', {mode='add', name='ActionCourse'}) 
Can it be done for "SpecialMessage" or would it require setting up of SpecialAction?
Your assistance would be greatly appreciated.
User avatar
blu3s
Posts: 1122
Joined: Fri Jul 08, 2022 9:45 am

Re: GPS data report in message log every 5 minutes

Post by blu3s »

You can create a function like you did (but without the local or it won't work) and then in the call of SetAction use the SpecialMessage like you did

Code: Select all

ScenEdit_SetAction({mode='add', type='LuaScript', name= 'ActionCourse', ScriptText ="ScenEdit_SpecialMessage('Blue', testme(false))"})
Or just incorporate the call to SpecialMessage inside the function and in ScriptText call that function
Orzel
Posts: 8
Joined: Wed Jan 10, 2024 12:20 pm

Re: GPS data report in message log every 5 minutes

Post by Orzel »

Thank you for your assistance. I successfully achieved what I was going for. Wishing you a pleasant day!
Post Reply

Return to “Lua Legion”