Lua assigning Non-unique names to mission (Full Version)

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



Message


Gunner98 -> Lua assigning Non-unique names to mission (9/25/2016 1:31:52 PM)

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')




Rory Noonan -> RE: Lua assigning Non-unique names to mission (9/25/2016 3:28:42 PM)

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?




Gunner98 -> RE: Lua assigning Non-unique names to mission (9/25/2016 4:26:55 PM)

No not essential. Its a minor action and I just didn't want to make it overly complex to script.

B




ckfinite -> RE: Lua assigning Non-unique names to mission (9/25/2016 5:36:30 PM)

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




Gunner98 -> RE: Lua assigning Non-unique names to mission (9/25/2016 5:46:07 PM)

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




kevinkins -> RE: Lua assigning Non-unique names to mission (9/26/2016 2:49:44 AM)

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.




Gunner98 -> RE: Lua assigning Non-unique names to mission (9/26/2016 2:51:43 AM)

Point at the spot on the map. Cntl+X then in your script Cntl+V

B




ckfinite -> RE: Lua assigning Non-unique names to mission (9/26/2016 10:08:54 PM)

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




Gunner98 -> RE: Lua assigning Non-unique names to mission (9/26/2016 10:25:13 PM)

Thanks CK

Works like a charm

B




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.625