Using Lua to Call Specific Mounts (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios



Message


ExNusquam -> Using Lua to Call Specific Mounts (3/4/2017 7:42:44 PM)

So I'm trying to write a scenario where behaviors are generated based on weapons remaining on a unit (and where I'd need to change the number remaining on the fly). I can figure out the syntax to generate a table of mounts attached to a given unit via unit.mounts but I can't figure out the syntax to filter down to a single mount or weapon to pull or modify wpn_current. Does anyone have any idea how to accomplish this?




michaelm75au -> RE: Using Lua to Call Specific Mounts (3/4/2017 10:03:21 PM)

Simple script.

quote:

local unit = ScenEdit_GetUnit({name='mech inf'})
-- list of mounts (with devices present)
-- print(unit.mounts)
-- loop thru the mounts
for k,v in pairs(unit.mounts)
do
-- v is each mount
print('Mount ' .. k);print(v)
--loop thru the weapons on the mount
for k2,v2 in pairs(v.mount_weapons)
do
-- find particular weapon and do something to the first found on the mount
-- say reduce to 10 loads only if more than that
if v2.wpn_dbid == 1695 and v2.wpn_current > 10 then
print(v2)
local to = v2.wpn_current -10
local a = ScenEdit_AddReloadsToUnit({guid=unit.guid, wpn_dbid=v2.wpn_dbid,mount_guid=v.mount_guid, remove=true, number=to})
print('Mount ' .. k .. 'weapon load changed by ' .. a)
break
end
end
end
-- refresh unit
unit = ScenEdit_GetUnit({name='mech inf'})
print(unit.mounts)




michaelm75au -> RE: Using Lua to Call Specific Mounts (3/4/2017 10:19:57 PM)

As mounts are tables inside tables, you need to use the appropriate function to affect the elements inside them.
The complication to actual use the elements would be similar to the 'fuel' where you have to update the tables and then write them back in full.[:)]. I wanted to avoid this and the possibility of generating errors by not keying in the correct values.




ExNusquam -> RE: Using Lua to Call Specific Mounts (3/5/2017 6:59:18 PM)

Michael-
Thanks for the help! This is exactly what I was looking for.




bearhunter007 -> RE: Using Lua to Call Specific Mounts (3/27/2017 10:08:19 PM)

Michael,

Thanks for documenting your code. It's a simple script for you but "tables" are different then the arrays I'm used to working with in c and vba.




michaelm75au -> RE: Using Lua to Call Specific Mounts (3/28/2017 9:35:12 AM)

Yea, I have to stop and think which array/table I'm using most of time at work; SQL, Java, Perl, ...[:D]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.703125