Adding unit
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Adding unit
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!
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.
- TitaniumTrout
- Posts: 472
- Joined: Mon Oct 20, 2014 9:06 am
- Location: Michigan
RE: Adding unit
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")}
This would be the correct usage.
ScenEdit_AddUnit({type ='surface', guid='7947f1af-15aa-42dd-81e1-6943a6a44e14', side ='USN', Lat="14.9097337722778",Lon="119.90650177002")}
CMO WIKI - https://wiki.weaponsrelease.com
RE: Adding unit
>> 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!
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.
- TitaniumTrout
- Posts: 472
- Joined: Mon Oct 20, 2014 9:06 am
- Location: Michigan
RE: Adding unit
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!
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!
CMO WIKI - https://wiki.weaponsrelease.com
RE: Adding unit
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.
RE: Adding unit
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.
- TitaniumTrout
- Posts: 472
- Joined: Mon Oct 20, 2014 9:06 am
- Location: Michigan
RE: Adding unit
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)
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)
CMO WIKI - https://wiki.weaponsrelease.com
RE: Adding unit
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! [:D]
USS Dwight D. Eisenhower (CVN-69) 1990-1994.
RE: Adding unit
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
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.
RE: Adding unit
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.
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.
- TitaniumTrout
- Posts: 472
- Joined: Mon Oct 20, 2014 9:06 am
- Location: Michigan
RE: Adding unit
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/CM ... age#Editor
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/CM ... age#Editor
CMO WIKI - https://wiki.weaponsrelease.com
RE: Adding unit
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/CM ... age#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.
- TitaniumTrout
- Posts: 472
- Joined: Mon Oct 20, 2014 9:06 am
- Location: Michigan
RE: Adding unit
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?
I'm not as familiar with adding aircraft to a carrier using Lua, maybe someone else can chime in?
CMO WIKI - https://wiki.weaponsrelease.com
-
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Adding unit
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.
Code: Select all
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;
RE: Adding unit
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!
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.
RE: Adding unit
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.
Code: Select all
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.
RE: Adding unit
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.
Code: Select all
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.
-
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Adding unit
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.ORIGINAL: 1nutworld
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.
Code: Select all
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
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.