Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Grouping units

 
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 >> Lua Legion >> Grouping units Page: [1]
Login
Message << Older Topic   Newer Topic >>
Grouping units - 6/19/2019 1:28:31 AM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
Hay guys

Building a base on the AI side. This will happen at a certain point where a single unit airfield on a neutral side will be replaced by a multiple unit base on a bad guy side. I want it so the player can attack it if he does so before it is too heavily defended.

No issues adding all the units, that all works. Question is how do I group the units into a base?

Tx

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Post #: 1
RE: Grouping units - 6/19/2019 6:02:08 AM   
hasler

 

Posts: 39
Joined: 7/31/2017
Status: offline
I am away from my computer right now but I do unit and group creation like the linked example on the Lua got hub. http://commandlua.github.io/examples/scenedit_addunit.lua.html

(in reply to Gunner98)
Post #: 2
RE: Grouping units - 6/19/2019 9:25:54 AM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
OK - never saw this example before, right there in front of me. Thanks

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to hasler)
Post #: 3
RE: Grouping units - 7/13/2019 12:44:47 AM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
OK Just able to get back to this now:

Getting an error:
ERROR: [string "Console"]:32: '}' expected (to close '{' at line 26) near 'for'

Played around with it for a while but no joy - any ideas?

Tx

------------------------------------

function AddMultipleUnits()
-- list of units to add
-- there are 2 base types of elements in this table - unit and group
-- unit: contains data for adding the unit, and optional group or mission data. the mission data is not used in this example.
-- group: contains data for adding some group information. the group is assumed to have been created when it was assigned to a unit
local newUnits = {
{unit={type = 'Facility', name = 'Maribor main Runway', heading = 120, dbid = 55, side = 'Hugary', latitude='46.4803890511425', longitude='15.6878028852709'},
{unit={type = 'Facility', name = 'Maribor grass Runway', heading = 120, dbid = 945, side = 'Hugary', latitude='46.4814496219698', longitude='15.6896462040406'},
{unit={type = 'Facility', name = 'Maribor parking', dbid = 186, side = 'Hugary', latitude='46.4805743060371', longitude='15.6852357716592'},
{unit={type = 'Facility', name = 'Maribor parking', dbid = 186, side = 'Hugary', latitude='46.4804070784834', longitude='15.6854777981397'},
{unit={type = 'Facility', name = 'Maribor parking', dbid = 186, side = 'Hugary', latitude='46.4801134880231', longitude='15.6856922948778'},
{unit={type = 'Facility', name = 'Maribor parking', dbid = 186, side = 'Hugary', latitude='46.4796105298677', longitude='15.6864813619985'},
{unit={type = 'Facility', name = 'Maribor parking', dbid = 186, side = 'Hugary', latitude='46.4793804779242', longitude='15.6866653289655'},
{unit={type = 'Facility', name = 'Maribor parking', dbid = 186, side = 'Hugary', latitude='46.4792086519584', longitude='15.6867853295262'},
{unit={type = 'Facility', name = 'Maribor access', dbid = 306, side = 'Hugary', latitude='46.4804079946791', longitude='15.6865743476855'},
{unit={type = 'Facility', name = 'Maribor access', dbid = 306, side = 'Hugary', latitude='46.4798000404651', longitude='15.6871814779628'},
{unit={type = 'Facility', name = 'Maribor Control Twr', dbid = 3, side = 'Hugary', latitude='46.4793161568347', longitude='15.6851137247781'},
{unit={type = 'Facility', name = 'Maribor Hangar', dbid = 9, side = 'Hugary', latitude='46.4786876099595', longitude='15.68629942848'},
{unit={type = 'Facility', name = 'Maribor Ammo', dbid = 320, side = 'Hugary', latitude='46.4808465642364', longitude='15.6851757196959'},
{unit={type = 'Facility', name = 'Maribor Fuel', dbid = 944, side = 'Hugary', latitude='46.4782466613332', longitude='15.6881227119196'},
{unit={type = 'Facility', name = 'MANPADS', dbid = 416, side = 'Hugary', latitude='46.4821508520397', longitude='15.6832893809333'},
{unit={type = 'Facility', name = 'MANPADS', dbid = 416, side = 'Hugary', latitude='46.4768610848761', longitude='15.6848074901503'},
{unit={type = 'Facility', name = 'MANPADS', dbid = 416, side = 'Hugary', latitude='46.4793522402419', longitude='15.6913775009575'},
{unit={type = 'Facility', name = 'MANPADS', dbid = 416, side = 'Hugary', latitude='46.4834711133154', longitude='15.6877321512789'},
{unit={type = 'Facility', name = 'ZU-23-2', dbid = 2468, side = 'Hugary', latitude='46.4803890981919', longitude='15.684688367051'},
{unit={type = 'Facility', name = 'ZU-23-2', dbid = 2468, side = 'Hugary', latitude='46.4786662193619', longitude='15.6867238319341'},
{unit={type = 'Facility', name = 'ZU-23-2', dbid = 2468, side = 'Hugary', latitude='46.4802583518172', longitude='15.6899795108315'},
{unit={type = 'Facility', name = 'ZU-23-2', dbid = 2468, side = 'Hugary', latitude='46.4817310715893', longitude='15.6882468148245'},
{group={side='Hugary', name='Maribor Airbase',{latitude='46.4803890511425', longitude='15.6878028852709'}}}},
}
-- process the table, adding the units to the scenario
for i = 1, #newUnits, 1 do
-- the table element .unit contains data??
if newUnits.unit ~= nil then
print('adding #' .. i .. ' ' .. newUnits.unit.name)
-- the table element .unit contains the data to pass as the parameter to the SE_AddUnit() function
local u1 = ScenEdit_AddUnit( newUnits.unit )
-- check that the function worked. a 'unit' wrapper should be returned
if u1 == nil then
print( "failed to add unit")
else
-- does the same table entry contain an element .group. this is the group to assign unit to
if newUnits.group ~= nil then
u1.group=newUnits.group -- this will also create the group if it doesn't exist.
end
end
elseif newUnits.group ~= nil then
print('adding #' .. i .. ' ' .. newUnits.group.name)
-- update the group with the data from the table
local u1 = ScenEdit_SetUnit( newUnits.group )
if u1 == nil then
print( "failed to add unit")
end
end
end
end

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to Gunner98)
Post #: 4
RE: Grouping units - 7/13/2019 1:06:34 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
There seems to be a missing '}' at the ends of the {unit=........}. They should be 'one block'
E.g.
quote:


{unit=
{
type = 'Facility', name = 'Maribor main Runway', heading = 120, dbid = 55, side = 'Hugary', latitude='46.4803890511425', longitude='15.6878028852709'
}
},


_____________________________

Michael

(in reply to Gunner98)
Post #: 5
RE: Grouping units - 7/13/2019 1:28:18 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Actually there are a few things wrong. Let me drop in a full updated version

_____________________________

Michael

(in reply to michaelm75au)
Post #: 6
RE: Grouping units - 7/13/2019 1:34:59 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
You forgot the index to the newUnits table. You may have done it when pasted but '[ i ]' means italic in the posting
The other thing is that if you want to assign the units to a group, you need to do so in the 'unit=' as shown.

Attached the code as a file as the I forgot the post formatting kills it.

Attachment (1)

< Message edited by michaelm75au -- 7/13/2019 1:43:42 AM >


_____________________________

Michael

(in reply to michaelm75au)
Post #: 7
RE: Grouping units - 7/13/2019 1:51:32 AM   
Whicker

 

Posts: 664
Joined: 6/20/2018
Status: offline
That example is sort of complex, the important part of adding a unit to a group is simply to set the units group value to the name of the group:

local u = SE_GetUnit({blah blah})
u.group="that big group"

(in reply to michaelm75au)
Post #: 8
RE: Grouping units - 7/13/2019 1:54:27 AM   
Whicker

 

Posts: 664
Joined: 6/20/2018
Status: offline
I played around with making an air base via a lua function, it worked pretty well:

quote:


function W_CreateAirBase(basename,side,latlonTable, runways, taxiways, accesspoints, tarmacspaces, hangers, ammopads,detectable)
local lat=latlonTable['latitude']
local lon=latlonTable['longitude']
for i=1,runways do
local u = ScenEdit_AddUnit({side=side, type='Facility', name='Runway '..i, dbid=55, autodetectable=detectable, Lat=lat, Lon=lon})
u.group =basename
lat=lat +.004
end --runways

lat=latlonTable['latitude'] --reset lat and add to lon

lon=latlonTable['longitude'] + .002
for i=1,taxiways do
local u = ScenEdit_AddUnit({side=side, type='Facility', name='Taxiway '..i, dbid=1424, autodetectable=detectable, Lat=lat, Lon=lon})
u.group =basename
lat=lat +.004
end
lat=latlonTable['latitude'] --reset lat and add to lon

lon=latlonTable['longitude'] + .004
for i=1,accesspoints do
local u = ScenEdit_AddUnit({side=side, type='Facility', name='Access Point '..i, dbid=353, autodetectable=detectable, Lat=lat, Lon=lon})
u.group =basename
lat=lat +.002
end
lat=latlonTable['latitude'] --reset lat and add to lon

lon=latlonTable['longitude'] + .006
for i=1,tarmacspaces do
local u = ScenEdit_AddUnit({side=side, type='Facility', name='Tarmac Space '..i, dbid=344, autodetectable=detectable, Lat=lat, Lon=lon})
u.group =basename
lat=lat +.002
end
lat=latlonTable['latitude'] --reset lat and add to lon

lon=latlonTable['longitude'] + .008
for i=1,ammopads do
local u = ScenEdit_AddUnit({side=side, type='Facility', name='Ammo Pad '..i, dbid=1496, autodetectable=detectable, Lat=lat, Lon=lon})
u.group =basename
lat=lat +.002
end

lon=latlonTable['longitude'] - .002
for i=1,hangers do
local u = ScenEdit_AddUnit({side=side, type='Facility', name='Hanger '..i, dbid=9, autodetectable=detectable, Lat=lat, Lon=lon})
u.group =basename
lat=lat -.002
end
end --function end

W_CreateAirBase('Red FOB','Red', {latitude='-3.16785920176629', longitude='128.539230124161'},2,2,4,8,2,1,true)





< Message edited by Whicker -- 7/13/2019 2:01:37 AM >

(in reply to Whicker)
Post #: 9
RE: Grouping units - 7/13/2019 11:24:28 AM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
Thanks very much for the help guys, I'll play around with it today.

B

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to Whicker)
Post #: 10
RE: Grouping units - 7/13/2019 12:11:26 PM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
Michael

That works like a charm - thank you very much once again

Whicker
I'm going to use your bit in my next scenario on Iceland - have been mulling over some ideas for that one quite some time and your code will come in very handy.

OK now I just need to write up some briefings and now that the prosecution zone bit is fixed I can get to testing! Cheers guys

B



< Message edited by Gunner98 -- 7/13/2019 12:13:31 PM >


_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to michaelm75au)
Post #: 11
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Grouping units 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

1.393