Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Adding unit

 
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 >> Adding unit Page: [1]
Login
Message << Older Topic   Newer Topic >>
Adding unit - 4/27/2020 4:43:45 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline
Hi everyone,

I don't know enough about the LUA language to be able to type it into the lua console so I am attempting to work on lua things the "cut and paste" method, so this is leaving me with questions.

I have previously gotten GUID specific information from a unit by right clicking on unit, scrolling down to 'scenario editor' and then copy information to clipboard.

Then pasting this information on an open Notepad.


Once I have done this, I have then gone to a place where I wish to place unit on the map, "ctl + X" to get Lat and Long info, copy that to same Notepad

then entering in the following:
ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002")

Resulting in this:
>> ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002")
ERROR: [string "Console"]:1: '}' expected near ')'

Great I am getting an error, no biggie, but being unfamiliar with the coding what part or parts of the string are the issue?

Thanks!



_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.
Post #: 1
RE: Adding unit - 4/27/2020 4:52:03 PM   
TitaniumTrout


Posts: 355
Joined: 10/20/2014
From: Michigan
Status: offline
You need to add a closing } .

This would be the correct usage.

ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002")}

_____________________________


(in reply to 1nutworld)
Post #: 2
RE: Adding unit - 4/27/2020 5:01:33 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline
>> ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002")}
ERROR: [string "Console"]:1: '}' expected near ')'


Hi Titanium! Still getting an error, after copying and pasting your correction.

By the way, I'm in Flint! One Michigander to another!

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to TitaniumTrout)
Post #: 3
RE: Adding unit - 4/27/2020 5:33:40 PM   
TitaniumTrout


Posts: 355
Joined: 10/20/2014
From: Michigan
Status: offline
Oops, my bad, you need to flip the brace and the enclosure.

ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002"})

All functions start with a round bracket ( and must end with a round bracket ). Most of the time you see a curly bracket (brace) as well. In some cases you will see braces nested inside as well for tables.

Yooper here!

< Message edited by TitaniumTrout -- 4/27/2020 5:34:24 PM >


_____________________________


(in reply to 1nutworld)
Post #: 4
RE: Adding unit - 4/27/2020 6:32:10 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: TitaniumTrout

Oops, my bad, you need to flip the brace and the enclosure.

ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002"})

All functions start with a round bracket ( and must end with a round bracket ). Most of the time you see a curly bracket (brace) as well. In some cases you will see braces nested inside as well for tables.

Yooper here!


Spent many Winter days and nights killing brain cells while at Northern Michigan University as a young adult. Didn't do much learning in class, though.

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to TitaniumTrout)
Post #: 5
RE: Adding unit - 4/27/2020 6:35:56 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: TitaniumTrout

ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002"})

All functions start with a round bracket ( and must end with a round bracket ). Most of the time you see a curly bracket (brace) as well. In some cases you will see braces nested inside as well for tables.




>> ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002"})
ScenEdit_AddUnit 0 : ,Missing 'DBID'

I betcha we get this one figured out and it works perfectly! after numerous attempts.


_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to TitaniumTrout)
Post #: 6
RE: Adding unit - 4/27/2020 8:19:44 PM   
TitaniumTrout


Posts: 355
Joined: 10/20/2014
From: Michigan
Status: offline
Well, in this case you add unit using the DBID, which is a unique identifier. You can find that in the Database Viewer.



ScenEdit_AddUnit({type="air", side="USN", name="Plane", dbid=1160, loadoutid=12354, latitude="29.297778", longitude="90.911944", altitude="5000 ft", heading=0})

The GUID is useful once the unit has been placed as it is unique to that exact unit. You'd use that one if you were querying using ScenEdit_GetUnit.

Glad to hear you enjoyed NMU. I wouldn't worry about not learning much up there, it doesn't seem anyone up there did. (Kidding, I'm an MTU grad)


_____________________________


(in reply to 1nutworld)
Post #: 7
RE: Adding unit - 4/27/2020 9:28:14 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: TitaniumTrout

..... it doesn't seem anyone up there did. (Kidding, I'm an MTU grad)



I learned how to stay warm, via lubrication...and MTU? I'm sorry!

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to TitaniumTrout)
Post #: 8
RE: Adding unit - 4/27/2020 9:50:43 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline
I'm still having issues, as all the examples that have been used either with your examples, and those on the page http://commandlua.github.io/ are using aircraft which require loadouts, altitude, etc. but I am apparently "coding stupid" and can't get the specific data in the correct place, or format or whatever.

This particular string also came back with errors.

ScenEdit_AddUnit({type ='ship', dbid =2587, side ='USN', Lat="14.9097337722778",Lon="119.90650177002"})


ScenEdit_AddUnit 0 : ,Unable to create new unit
>> ScenEdit_AddUnit({type ='ship', dbid =2587, side ='USN', Lat="14.9097337722778",Lon="119.90650177002"})

ScenEdit_AddUnit 0 : ,Missing 'Name


_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to 1nutworld)
Post #: 9
RE: Adding unit - 4/27/2020 10:27:05 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline
Well, yay!! for me

I finally did get to add the CORRECT unit, to the CORRECT side, in the CORRECT place, with the CORRECT name and CORRECT DBID, but of course it didn't come with the particular A/C loadout that wanted to have assigned to it...being a carrier.

I then tried to "get unit" using the very unit specific GUID, that I copied and pasted from having it in a notepad and now As far as I can see, putting that in the lua script did nothing.

ScenEdit_GetUnit({name='USS Theodore Roosevelt (CVN-71) Nimitz', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14'})

but also didn't give me errors

The GUID= guid='7947f1af-15aa-42dd-81e1-6943a6a44e14'

IS the A/C loadout that I wish to have assigned to the carrier.

Sorry for being completely dumb on this....as I am teaching myself how to use the LUA functions and it is very much trial and error.

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to 1nutworld)
Post #: 10
RE: Adding unit - 4/27/2020 11:01:53 PM   
TitaniumTrout


Posts: 355
Joined: 10/20/2014
From: Michigan
Status: offline
Okay, once you've gotten it, you need to do something with it.

local unit = ScenEdit_GetUnit({guid='7947f1af-15aa-42dd-81e1-6943a6a44e14'})
print(unit)

That will show in the lua console.

You can also query individual bits, so

print(unit.name)
print(unit.guid)
print(unit.throttle)

It's helpful to preface it with what you're looking at so :

print("Unit name is "..unit.name)

Also check out the Wiki, there's a decent section on the Lua goodies.

https://weaponsrelease.com/index.php/CMO_Main_Page#Editor


_____________________________


(in reply to 1nutworld)
Post #: 11
RE: Adding unit - 4/28/2020 12:29:23 AM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: TitaniumTrout

Okay, once you've gotten it, you need to do something with it.

local unit = ScenEdit_GetUnit({guid='7947f1af-15aa-42dd-81e1-6943a6a44e14'})
print(unit)

That will show in the lua console.

You can also query individual bits, so

print(unit.name)
print(unit.guid)
print(unit.throttle)

It's helpful to preface it with what you're looking at so :

print("Unit name is "..unit.name)

Also check out the Wiki, there's a decent section on the Lua goodies.

https://weaponsrelease.com/index.php/CMO_Main_Page#Editor




Thank you for your help, and MOSTLY patience. NOW...stupid question time. "Print" isn't actually sending to a device to print off 4 words...or whatever, correct? It's a language command?

With this particular GUID I want to add in a specifically named and numbered loadout of aircraft onto the carrier (that's why I was hoping to use that very Unit GUID information)

Isn't that the purpose of having that very specific GUID that got copied from the information from the scenario editor?

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to TitaniumTrout)
Post #: 12
RE: Adding unit - 4/28/2020 1:50:52 AM   
TitaniumTrout


Posts: 355
Joined: 10/20/2014
From: Michigan
Status: offline
Print is a generic term for sending an output to a console. It will not pop up a message or even appear in the message log. It's strictly for debugging.

I'm not as familiar with adding aircraft to a carrier using Lua, maybe someone else can chime in?

_____________________________


(in reply to 1nutworld)
Post #: 13
RE: Adding unit - 4/28/2020 3:05:56 AM   
KnightHawk75

 

Posts: 1351
Joined: 11/15/2018
Status: offline
Either add a base = 'HostNamehere or Host Guidhere' parameter during add, or if doing it after the fact or to an existing unit, call ScenEdit_HostUnitToParent.


local c, u,retval;
c = ScenEdit_AddUnit({type = 'Ship', name = 'MyCarrier', loadoutid = 0,
    heading = 0, dbid = 2370, side = 'Blue', Latitude="S4.50.00",Longitude="W5.00.00",
    autodetectable="false",holdfire="true",proficiency=4,speed=0});
u = ScenEdit_AddUnit({type = 'Aircraft', name = 'F-35 single', loadoutid = 10098,
    heading = 0, dbid = 824, side = 'Blue', Latitude="N00.50.00",Longitude="E0.50.00",
    altitude="0 ft",autodetectable="false",holdfire="true",proficiency=4,speed=350,
    base=c.guid}); -- <<--- base= parameter

--or exclude base= parameters above in unit creation and after creation use..
--retval = ScenEdit_HostUnitToParent({HostedUnitNameOrID=u.guid,SelectedHostNameOrID=c.guid})
--if retval == true then print(string.format('Successfully inserted %s into %s',u.name,c.name)); end
c=nil;u=nil;retval=nil;


< Message edited by KnightHawk75 -- 4/28/2020 3:09:22 AM >

(in reply to TitaniumTrout)
Post #: 14
RE: Adding unit - 4/28/2020 3:02:18 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: TitaniumTrout

Print is a generic term for sending an output to a console. It will not pop up a message or even appear in the message log. It's strictly for debugging.



So, more or less I understood the command properly, go me!


quote:

ORIGINAL: TitaniumTrout

I'm not as familiar with adding aircraft to a carrier using Lua, maybe someone else can chime in?


That's a fair answer and I appreciate the candidness of it. Again, thanks for your help in this bud! You've really been a big help.

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to TitaniumTrout)
Post #: 15
RE: Adding unit - 4/28/2020 3:11:49 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: KnightHawk75

Either add a base = 'HostNamehere or Host Guidhere' parameter during add, or if doing it after the fact or to an existing unit, call ScenEdit_HostUnitToParent.


local c, u,retval;
c = ScenEdit_AddUnit({type = 'Ship', name = 'MyCarrier', loadoutid = 0,
    heading = 0, dbid = 2370, side = 'Blue', Latitude="S4.50.00",Longitude="W5.00.00",
    autodetectable="false",holdfire="true",proficiency=4,speed=0});
u = ScenEdit_AddUnit({type = 'Aircraft', name = 'F-35 single', loadoutid = 10098,
    heading = 0, dbid = 824, side = 'Blue', Latitude="N00.50.00",Longitude="E0.50.00",
    altitude="0 ft",autodetectable="false",holdfire="true",proficiency=4,speed=350,
    base=c.guid}); -- <<--- base= parameter

--or exclude base= parameters above in unit creation and after creation use..
--retval = ScenEdit_HostUnitToParent({HostedUnitNameOrID=u.guid,SelectedHostNameOrID=c.guid})
--if retval == true then print(string.format('Successfully inserted %s into %s',u.name,c.name)); end
c=nil;u=nil;retval=nil;




There are aspects of that scripting that I understand, and much that I don't. But one of the things I see in the script that caught my attention is in the 'My carrier' portion of the script, a loadout id

Does that mean that somehow if I take the time to create a blank scenario, and add in the specific carrier I wish to add, like USS Eisenhower, and then add furthermore add in the Carrier Air Wing, with the properly assigned aircraft to the wing, and "name them" F-14, "Ghostrider #1"; etc.

That I can take that info and create this data and make it a "loadout ID" that will automatically add that to the carrier using Lua?

OR

Would the easier thing be to do all of the above manually, and save it as an INI file to import/export

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to KnightHawk75)
Post #: 16
RE: Adding unit - 4/28/2020 3:12:38 PM   
1nutworld


Posts: 350
Joined: 4/13/2014
Status: offline

quote:

ORIGINAL: KnightHawk75

Either add a base = 'HostNamehere or Host Guidhere' parameter during add, or if doing it after the fact or to an existing unit, call ScenEdit_HostUnitToParent.


local c, u,retval;
c = ScenEdit_AddUnit({type = 'Ship', name = 'MyCarrier', loadoutid = 0,
    heading = 0, dbid = 2370, side = 'Blue', Latitude="S4.50.00",Longitude="W5.00.00",
    autodetectable="false",holdfire="true",proficiency=4,speed=0});
u = ScenEdit_AddUnit({type = 'Aircraft', name = 'F-35 single', loadoutid = 10098,
    heading = 0, dbid = 824, side = 'Blue', Latitude="N00.50.00",Longitude="E0.50.00",
    altitude="0 ft",autodetectable="false",holdfire="true",proficiency=4,speed=350,
    base=c.guid}); -- <<--- base= parameter

--or exclude base= parameters above in unit creation and after creation use..
--retval = ScenEdit_HostUnitToParent({HostedUnitNameOrID=u.guid,SelectedHostNameOrID=c.guid})
--if retval == true then print(string.format('Successfully inserted %s into %s',u.name,c.name)); end
c=nil;u=nil;retval=nil;




Thanks for chiming in, by the way.

_____________________________

USS Dwight D. Eisenhower (CVN-69) 1990-1994.

(in reply to KnightHawk75)
Post #: 17
RE: Adding unit - 4/28/2020 5:00:08 PM   
KnightHawk75

 

Posts: 1351
Joined: 11/15/2018
Status: offline

quote:

ORIGINAL: 1nutworld


quote:

ORIGINAL: KnightHawk75

Either add a base = 'HostNamehere or Host Guidhere' parameter during add, or if doing it after the fact or to an existing unit, call ScenEdit_HostUnitToParent.


local c, u,retval;
c = ScenEdit_AddUnit({type = 'Ship', name = 'MyCarrier', loadoutid = 0,
    heading = 0, dbid = 2370, side = 'Blue', Latitude="S4.50.00",Longitude="W5.00.00",
    autodetectable="false",holdfire="true",proficiency=4,speed=0});
u = ScenEdit_AddUnit({type = 'Aircraft', name = 'F-35 single', loadoutid = 10098,
    heading = 0, dbid = 824, side = 'Blue', Latitude="N00.50.00",Longitude="E0.50.00",
    altitude="0 ft",autodetectable="false",holdfire="true",proficiency=4,speed=350,
    base=c.guid}); -- <<--- base= parameter

--or exclude base= parameters above in unit creation and after creation use..
--retval = ScenEdit_HostUnitToParent({HostedUnitNameOrID=u.guid,SelectedHostNameOrID=c.guid})
--if retval == true then print(string.format('Successfully inserted %s into %s',u.name,c.name)); end
c=nil;u=nil;retval=nil;




There are aspects of that scripting that I understand, and much that I don't. But one of the things I see in the script that caught my attention is in the 'My carrier' portion of the script, a loadout id

Does that mean that somehow if I take the time to create a blank scenario, and add in the specific carrier I wish to add, like USS Eisenhower, and then add furthermore add in the Carrier Air Wing, with the properly assigned aircraft to the wing, and "name them" F-14, "Ghostrider #1"; etc.

That I can take that info and create this data and make it a "loadout ID" that will automatically add that to the carrier using Lua?

OR

Would the easier thing be to do all of the above manually, and save it as an INI file to import/export

So you can't create an loadout id in the context that it's used during a AddUnit call, as those are from the database itself. Incidentally though you can stick loadouts that exist in the database on things they're not qualified to be on, like give a f-22 a b1-b lrasm loadout, I love this sometimes just for giggles.

It's definitely the 'or' part in most cases.
The cases where you might want to script the creation of it all would be where you need to generate things at runtime, maybe for deception, maybe due to player interaction (chose your airwing via special action), maybe unit count control, or simply just want\prefer too. I tend to prefer just to script stuff out once, say a BuildEisenhower script or function, save the snippet, and then all I have do when I want to create the entire thing with all fresh guids is copy and paste it, or more often just throw ScenEdit_RunScript('\\mysnippetfolder\\BuildEisenhower.lua') into the action.

(in reply to 1nutworld)
Post #: 18
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Adding unit 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.310