Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua assigning Non-unique names to mission

 
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 assigning Non-unique names to mission Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua assigning Non-unique names to mission - 9/25/2016 1:31:52 PM   
Gunner98

 

Posts: 4816
Joined: 4/29/2005
From: The Great White North!
Status: offline
Trying to make a random script where units pop up regularly and cause the player some minor issues. The script below works for the random generation but when I do the standard - ScenEdit_AssignUnitToMission, Lua does what it's supposed to and grabs the first unit with the name. Is there a way I can make it grab all units with that same name?

Thanks

B



a = math.random(1,6)

if a == 1 then
ScenEdit_AddUnit({type='Ship', side='Cuba', name='Bandito', dbid='330', latitude='22.448075078579', longitude='-78.9575872674641'})

elseif a == 2 then
ScenEdit_AddUnit({type='Ship', side='Cuba', name='Bandito', dbid='330', latitude='22.6824953509623', longitude='-79.5730956697378'})

elseif a == 3 then
ScenEdit_AddUnit({type='Ship', side='Cuba', name='Bandito', dbid='330', latitude='23.0265691618325', longitude='-80.451326876993'})

elseif a == 4 then
ScenEdit_AddUnit({type='Ship', side='Cuba', name='Bandito', dbid='330', latitude='23.1006901157562', longitude='-81.1965671192377'})

elseif a == 5 then
ScenEdit_AddUnit({type='Ship', side='Cuba', name='Bandito', dbid='330', latitude='21.8084144174213', longitude='-77.3702693649615'})

elseif a == 6 then
ScenEdit_AddUnit({type='Ship', side='Cuba', name='Bandito', dbid='330', latitude='24.1456777943727', longitude='-78.0061405217515'})
end
ScenEdit_AssignUnitToMission('Bandito', 'East Strike')
Post #: 1
RE: Lua assigning Non-unique names to mission - 9/25/2016 3:28:42 PM   
Rory Noonan

 

Posts: 2723
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
Not at my computer now (and not good enough at Lua to use my phone) but you could use a key library variable to increment the unit name and then reference it in the assignment function. Is it essential that the units all have the same name?

(in reply to Gunner98)
Post #: 2
RE: Lua assigning Non-unique names to mission - 9/25/2016 4:26:55 PM   
Gunner98

 

Posts: 4816
Joined: 4/29/2005
From: The Great White North!
Status: offline
No not essential. Its a minor action and I just didn't want to make it overly complex to script.

B

(in reply to Rory Noonan)
Post #: 3
RE: Lua assigning Non-unique names to mission - 9/25/2016 5:36:30 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
To deal with units with the same name, you have three options:

* You can rename units as you examine them, then rename them back when you're done
* You can use GUIDs exclusively to select units
* You can use VP_GetSide to list all units of the side, then select from that

For an example of the last one, you could write

for _,v in pairs(VP_GetSide("Cuba").units) do
local unit = ScenEdit_GetUnit({guid=v.objectid})
if unit.name == "Bandito" then
unit.mission = "East Strike"
end
end

(in reply to Gunner98)
Post #: 4
RE: Lua assigning Non-unique names to mission - 9/25/2016 5:46:07 PM   
Gunner98

 

Posts: 4816
Joined: 4/29/2005
From: The Great White North!
Status: offline
CK

That example is brilliant, quick and simple. Thank you

Just tested it and got:

ERROR: invalid arguments to method call

Do I need to load a library or something up first?

B

(in reply to ckfinite)
Post #: 5
RE: Lua assigning Non-unique names to mission - 9/26/2016 2:49:44 AM   
kevinkins


Posts: 2135
Joined: 3/8/2006
Status: offline
Sorry to side track. But is there an easy way to copy and paste long. and lat. from the game map into your lua script. Or are you guys using an auxiliary map for that purpose? Thanks.

(in reply to Gunner98)
Post #: 6
RE: Lua assigning Non-unique names to mission - 9/26/2016 2:51:43 AM   
Gunner98

 

Posts: 4816
Joined: 4/29/2005
From: The Great White North!
Status: offline
Point at the spot on the map. Cntl+X then in your script Cntl+V

B

(in reply to kevinkins)
Post #: 7
RE: Lua assigning Non-unique names to mission - 9/26/2016 10:08:54 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
Sorry about the broken script, here's a fixed version

for _,v in pairs(VP_GetSide({name="Cuba"}).units) do
local unit = ScenEdit_GetUnit({guid=v.objectid})
if unit.name == "Bandito" then
unit.mission = "East Strike"
end
end

(in reply to Gunner98)
Post #: 8
RE: Lua assigning Non-unique names to mission - 9/26/2016 10:25:13 PM   
Gunner98

 

Posts: 4816
Joined: 4/29/2005
From: The Great White North!
Status: offline
Thanks CK

Works like a charm

B

(in reply to ckfinite)
Post #: 9
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua assigning Non-unique names to mission 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

0.145