Setting a units EMCON via LUA

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
acowman2
Posts: 3
Joined: Sat Nov 23, 2024 1:06 am

Setting a units EMCON via LUA

Post by acowman2 »

Hi,

I've been trying to set a units emcon via lua in a scenario i'm working on. Here is the code I'm trying to use:

Code: Select all

local c1_units = { 
{ name='S-400 C1 #1', dbid=1668, latitude=45.2357921846878, longitude=33.2507438292646, set_emcon='y', emcon='radar=active' }
};

for i=1, #c1_units, 1 do
ScenEdit_DeleteUnit({ side = 'Russia', unitname = c1_units[i].name });
local newU = ScenEdit_AddUnit({ side = 'Russia', type='facility', dbid=c1_units[i].dbid, unitname=c1_units[i].name, latitude=c1_units[i].latitude, longitude=c1_units[i].longitude });
if c1_units[i].set_emcon=='y' then
newU.obeyEMCON = false;
ScenEdit_SetEMCON( 'unit', c1_units[i].name, c1_units[i].emcon );
end;
end;
The end result is that the unit gets created with obeyEMCON off but the radar does not switch to the ON position. Unfortunately it doesn't allow me to attach a .scen file nor do i have a url for any photos but am wondering if anyone can tell me anything from the code?

Thanks
acowman2
Posts: 3
Joined: Sat Nov 23, 2024 1:06 am

Re: Setting a units EMCON via LUA

Post by acowman2 »

I should also mention that the above code is ran in an event script with a timer as a trigger. When I run it in the actual lua script console, the output is the unit is created with radar on, but the "obey emcon" box is also checked (that's not a big deal but i need it to work with a timer as a trigger)
Post Reply

Return to “Lua Legion”