Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Using Lua to Call Specific Mounts

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Using Lua to Call Specific Mounts Page: [1]
Login
Message << Older Topic   Newer Topic >>
Using Lua to Call Specific Mounts - 3/4/2017 7:42:44 PM   
ExNusquam

 

Posts: 513
Joined: 3/4/2014
From: Washington, D.C.
Status: offline
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?
Post #: 1
RE: Using Lua to Call Specific Mounts - 3/4/2017 10:03:21 PM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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)


_____________________________

Michael

(in reply to ExNusquam)
Post #: 2
RE: Using Lua to Call Specific Mounts - 3/4/2017 10:19:57 PM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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.

_____________________________

Michael

(in reply to michaelm75au)
Post #: 3
RE: Using Lua to Call Specific Mounts - 3/5/2017 6:59:18 PM   
ExNusquam

 

Posts: 513
Joined: 3/4/2014
From: Washington, D.C.
Status: offline
Michael-
Thanks for the help! This is exactly what I was looking for.

(in reply to michaelm75au)
Post #: 4
RE: Using Lua to Call Specific Mounts - 3/27/2017 10:08:19 PM   
bearhunter007

 

Posts: 23
Joined: 3/11/2017
Status: offline
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.

(in reply to ExNusquam)
Post #: 5
RE: Using Lua to Call Specific Mounts - 3/28/2017 9:35:12 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Yea, I have to stop and think which array/table I'm using most of time at work; SQL, Java, Perl, ...

_____________________________

Michael

(in reply to bearhunter007)
Post #: 6
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Using Lua to Call Specific Mounts Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

7.375