LUA Special Action help

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
TempestII
Posts: 233
Joined: Sat Oct 10, 2020 5:50 am

LUA Special Action help

Post by TempestII »

I've been playing around with the concept of players having the option to customise their forces at the start of a scenario via Special Actions. I don't have an issue with units like aircraft on bases/ships as I used the Ford Showcase Special Action LUA as a baseline to get a code that works.

What I am unsure of is the best way to allow players to use Special Actions to choose vessels. This is especially the case when it comes to customised ships, such as those with modified weapons, sensors, comms links etc. Therefore, I'm curious if there's a way to spawn in a unit from a Delta file via LUA?

Alternatively, a lesser solution that I'm aware may work is using Special Action LUA to trigger an Events Editor Action teleport, followed by a LUA command that kills the units that weren't picked. However, I have a couple of issues with this solution, the main one being that I can't work out how to get a Special Action to count as a Trigger.

Any help would be much appreciated!
User avatar
KLAB
Posts: 482
Joined: Tue Feb 27, 2007 5:24 pm

Re: LUA Special Action help

Post by KLAB »

Having re read what you wanted - apologies

You could use the Special action to both create the basic ship and include within it the LUA to then add whatever mount, sensors comms etc
or
Use a SE_SelectedUnits() to select an existing unit that would be upgraded?

Then delete unit would be case of a "if not else" etc from the remainder in the list?

https://www.matrixgames.com/forums/view ... 6&t=382530

Wish I could help with the Delta ini but that's still in my learning curve to do list.

K
User avatar
TempestII
Posts: 233
Joined: Sat Oct 10, 2020 5:50 am

Re: LUA Special Action help

Post by TempestII »

KLAB wrote: Thu Sep 21, 2023 11:35 am Having re read what you wanted - apologies

You could use the Special action to both create the basic ship and include within it the LUA to then add whatever mount, sensors comms etc
or
Use a SE_SelectedUnits() to select an existing unit that would be upgraded?

Then delete unit would be case of a "if not else" etc from the remainder in the list?

https://www.matrixgames.com/forums/view ... 6&t=382530

Wish I could help with the Delta ini but that's still in my learning curve to do list.

K
I did think of that option, but I have a couple of stumbling blocks:

1 - Spawning the ship with LUA isn't an issue, but is there a way to get the new unit's GUID via LUA? When I do my mods at the moment, I have to copy/paste the GUID in manually like below, which obviously isn't really doable for releasable scenarios.
local u = SE_GetUnit({guid='xxx'})

2 - Adding sensors, comms, and mounts is fine with LUA lines like these:
ScenEdit_UpdateUnit({guid=u.guid,mode='add_sensor',dbid=3466,arc_detect={'PB1','PB2','SB1','SB2','SMF1','SMF2','SMA1','SMA2','SS1','SS2','PS1','PS2','PMA1','PMA2','PMF1','PMF2'},arc_track={'PB1','PB2','SB1','SB2','SMF1','SMF2','SMA1','SMA2','SS1','SS2','PS1','PS2','PMA1','PMA2','PMF1','PMF2'}})
ScenEdit_UpdateUnit({guid=u.guid,mode='add_comms',dbid='4'});
ScenEdit_UpdateUnit({guid=u.guid,mode='add_mount',arc_mount={'360'},dbid=3148})

But I then can't seem to get the correct code for adding weapons to a mount; any ideas?
User avatar
KLAB
Posts: 482
Joined: Tue Feb 27, 2007 5:24 pm

Re: LUA Special Action help

Post by KLAB »

TempestII wrote: Fri Sep 22, 2023 3:34 am
KLAB wrote: Thu Sep 21, 2023 11:35 am Having re read what you wanted - apologies

You could use the Special action to both create the basic ship and include within it the LUA to then add whatever mount, sensors comms etc
or
Use a SE_SelectedUnits() to select an existing unit that would be upgraded?

Then delete unit would be case of a "if not else" etc from the remainder in the list?

https://www.matrixgames.com/forums/view ... 6&t=382530

Wish I could help with the Delta ini but that's still in my learning curve to do list.

K
I did think of that option, but I have a couple of stumbling blocks:

1 - Spawning the ship with LUA isn't an issue, but is there a way to get the new unit's GUID via LUA? When I do my mods at the moment, I have to copy/paste the GUID in manually like below, which obviously isn't really doable for releasable scenarios.
local u = SE_GetUnit({guid='xxx'})

2 - Adding sensors, comms, and mounts is fine with LUA lines like these:
ScenEdit_UpdateUnit({guid=u.guid,mode='add_sensor',dbid=3466,arc_detect={'PB1','PB2','SB1','SB2','SMF1','SMF2','SMA1','SMA2','SS1','SS2','PS1','PS2','PMA1','PMA2','PMF1','PMF2'},arc_track={'PB1','PB2','SB1','SB2','SMF1','SMF2','SMA1','SMA2','SS1','SS2','PS1','PS2','PMA1','PMA2','PMF1','PMF2'}})
ScenEdit_UpdateUnit({guid=u.guid,mode='add_comms',dbid='4'});
ScenEdit_UpdateUnit({guid=u.guid,mode='add_mount',arc_mount={'360'},dbid=3148})

But I then can't seem to get the correct code for adding weapons to a mount; any ideas?
You can give the spawned unit a self defined guid so you know what the GUID is going to be in advance and write the LUA using just the GUID. It has the limitation of having just the one incarnation of the vessel mod of course ? But you could do something like the following to get a predictable GUID?

for planes = 1, 2, 1 do
ScenEdit_AddUnit({type = 'Air', unitname = 'Scourge #'..planes, guid = 'ScourgeRN #'..planes, loadoutid = 22718, proficiency=4, dbid = 6171, side = 'Sultanate', base='Djibouti International Airport'}) ??

Mod a Weapon to a mount -- now thats a novel one - I dont think its doable off hand - will try tonight.
User avatar
blu3s
Posts: 998
Joined: Fri Jul 08, 2022 9:45 am

Re: LUA Special Action help

Post by blu3s »

TempestII wrote: Fri Sep 22, 2023 3:34 am But I then can't seem to get the correct code for adding weapons to a mount; any ideas?
With this code you can obtain the mount you want to add a weapon:

Code: Select all

local unit = SE_GetUnit({name='F 110 Bonifaz', guid='AIL12Q-0HMTT5CH6OEJ8'})
for _,v in ipairs(unit.mounts) do
print(v.mount_name .. ' - ' .. v.mount_guid)
end
And with that you create the weapon record

Code: Select all

ScenEdit_UpdateUnit({guid=unit.guid, mode='add_weapon', mountid='AIL12Q-0HMTT5CH6OELO',dbid=171})
The weapon record dbid can be viewed in the DataWeaponRecord or in the window when you add a weapon record to a mount.

To add reloads to the weapon you can use:

Code: Select all

ScenEdit_AddReloadsToUnit( { side= unit.side , guid=unit.guid, mount_guid='AIL12Q-0HMTT5CH6OELO', wpn_dbid=378, number=12} )
Note that in UpdateUnit function, the dbid is for the WeaponRecord while on the AddReloadsToUnit the wpn_dbid refers to the weapon itself

If you run all the following in the sample scenario you view how you add 12 TLAM to the F 110

Code: Select all

local unit = SE_GetUnit({name='F 110 Bonifaz', guid='AIL12Q-0HMTT5CH6OERA'})
for _,v in ipairs(unit.mounts) do

print(v.mount_name .. ' - ' .. v.mount_guid)
end
local mount_guid = 'AIL12Q-0HMTT5CH6OETQ'

ScenEdit_UpdateUnit({guid=unit.guid, mode='add_weapon', mountid=mount_guid,dbid=171})
ScenEdit_AddReloadsToUnit( { side= unit.side , guid=unit.guid, mount_guid=mount_guid, wpn_dbid=378, number=12} )
Attachments
Add Weapon to Mount.zip
(8.04 KiB) Downloaded 25 times
User avatar
KLAB
Posts: 482
Joined: Tue Feb 27, 2007 5:24 pm

Re: LUA Special Action help

Post by KLAB »

Awesome, this has solved something I was trying to do too, many thanks.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: LUA Special Action help

Post by michaelm75au »

1 - Spawning the ship with LUA isn't an issue, but is there a way to get the new unit's GUID via LUA? When I do my mods at the moment, I have to copy/paste the GUID in manually like below, which obviously isn't really doable for releasable scenarios.
local u = SE_GetUnit({guid='xxx'})
Depending on how you spawn the unit, the SE_AddUnit() should return a unit wrapper which should have the GUID that can be saved. You would then need to keep track of these spawned units if there is further Lua code that needs to work on them.
Michael
Post Reply

Return to “Lua Legion”