User changing unit name

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

User changing unit name

Post by nukkxx5058 »

Hi, what would happend to my script if the user changes an unit name that is used in the code ?
Will the lua code be somehow converted to the new name or will the script fail ?

for example:
if unit.name == "abc" then points = 500
end

thx
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: User changing unit name

Post by BDukes »

Lua will barf unless you've added some checks. Best bet is to not use the name. Use the unit.guid which players won't likely change.
Don't call it a comeback...
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: User changing unit name

Post by nukkxx5058 »

Ok, excellent !

But how do I find the GUID ? The only way I know is Editor\SBR\Generate Template
But then I don't know how to pick the right unit ?

For example, how do I find the guid for a given Inf plt (assuming the code below is the guid) ?
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7brsf>
<Unit_6pxd8k-0hltsesk7brt7>
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7brt7>
<Unit_6pxd8k-0hltsesk7brtv>
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7brtv>
<Unit_6pxd8k-0hltsesk7brun>
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7brun>
<Unit_6pxd8k-0hltsesk7brvf>
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7brvf>
<Unit_6pxd8k-0hltsesk7bs2p>
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7bs2p>
<Unit_6pxd8k-0hltsesk7bs3h>
<!--Inf Plt (Generic) (Inf Plt (Generic) [2272])-->
</Unit_6pxd8k-0hltsesk7bs3h>
<Unit_6pxd8k-0hltsesk7bs49>
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: User changing unit name

Post by BDukes »

Select unit. Press Ctrl+C hotkeys. You can then paste the result of that to Lua console or wherever. You'll get the unit name and GUID.

{name='PC 1002', guid='1T8G9D-0HMCBVMDIDV22'}

if unit.guid == "1T8G9D-0HMCBVMDIDV22" then points = 500

Programatically you can do a lot in Lua as well to pull these.

Mike
Don't call it a comeback...
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: User changing unit name

Post by nukkxx5058 »

ORIGINAL: BDukes

Select unit. Press Ctrl+C hotkeys. You can then paste the result of that to Lua console or wherever. You'll get the unit name and GUID.

{name='PC 1002', guid='1T8G9D-0HMCBVMDIDV22'}

if unit.guid == "1T8G9D-0HMCBVMDIDV22" then points = 500

Programatically you can do a lot in Lua as well to pull these.

Mike

Absolutely brillant ! Thank you !!
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: User changing unit name

Post by BDukes »

No problem. Have a nice holiday.

Mike
Don't call it a comeback...
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: User changing unit name

Post by nukkxx5058 »

And I have a connex question: where do I find the exact syntax for subtypes and classnames of a given unit (something equivalent to ctrl-c would be perfect).

To be used in code as here below:

[...]
elseif unit.subtype == "Multirole" then points = 30
end

THX
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: User changing unit name

Post by BDukes »

Well if you're getting into lua Knighthawks Visual Studio SDK is something you should look into. He's created a CMO library to find alot of this kind of stuff and merged with a good lua editor. I'm sure he will describe it much better than I.

https://www.matrixgames.com/forums/tm.asp?m=5069590

So from the library you can see the different subtypes. You might want to use aircraftsubtype

---@type table <string,integer> @names may not be one to one with strings due to spaces etc.
CMO__Constants.UnitAircraftCategory = {}
CMO__Constants.UnitAircraftCategory.None = 1001
CMO__Constants.UnitAircraftCategory.Fixed_Wing = 2001
CMO__Constants.UnitAircraftCategory.Fixed_Wing_CarrierCapable = 2002
CMO__Constants.UnitAircraftCategory.Helicopter = 2003
CMO__Constants.UnitAircraftCategory.Tiltrotor = 2004
CMO__Constants.UnitAircraftCategory.Airship = 2006
CMO__Constants.UnitAircraftCategory.Seaplane = 2007
CMO__Constants.UnitAircraftCategory.Amphibian = 2008

---@type table <string,integer> @names may not be one to one with strings due to spaces etc.
CMO__Constants.UnitAircraftSubType = {}
CMO__Constants.UnitAircraftSubType.None = 1001
CMO__Constants.UnitAircraftSubType.Fighter = 2001
CMO__Constants.UnitAircraftSubType.Multirole_FighterAttack = 2002
CMO__Constants.UnitAircraftSubType.Anti_Satellite_ASAT = 2101
CMO__Constants.UnitAircraftSubType.Airborne_LaserPlatform = 2102
CMO__Constants.UnitAircraftSubType.Attack = 3001
CMO__Constants.UnitAircraftSubType.WildWeasel = 3002
CMO__Constants.UnitAircraftSubType.Bomber = 3101
CMO__Constants.UnitAircraftSubType.Battlefield_AirInterdictionBAICAS = 3401
CMO__Constants.UnitAircraftSubType.Electronic_Warfare = 4001
CMO__Constants.UnitAircraftSubType.Airborne_Early_Warning = 4002
CMO__Constants.UnitAircraftSubType.Airborne_CommandPost = 4003
CMO__Constants.UnitAircraftSubType.Search_And_Rescue = 4101
CMO__Constants.UnitAircraftSubType.Mine_Sweeper = 4201
CMO__Constants.UnitAircraftSubType.AntiSubmarineWarfare = 6001
CMO__Constants.UnitAircraftSubType.Maritime_PatrolAircraft = 6002
CMO__Constants.UnitAircraftSubType.ForwardObserver = 7001
CMO__Constants.UnitAircraftSubType.AreaSurveillance = 7002
CMO__Constants.UnitAircraftSubType.Recon = 7003
CMO__Constants.UnitAircraftSubType.ElectronicIntelligence = 7004
CMO__Constants.UnitAircraftSubType.SignalsIntelligence= 7005
CMO__Constants.UnitAircraftSubType.Transport = 7101
CMO__Constants.UnitAircraftSubType.Cargo = 7201
CMO__Constants.UnitAircraftSubType.Commercial = 7301
CMO__Constants.UnitAircraftSubType.Civilian = 7302
CMO__Constants.UnitAircraftSubType.Utility = 7401
CMO__Constants.UnitAircraftSubType.NavalUtility = 7402
CMO__Constants.UnitAircraftSubType.Tanker_AirRefueling = 8001
CMO__Constants.UnitAircraftSubType.Trainer = 8101
CMO__Constants.UnitAircraftSubType.Target_Towing = 8102
CMO__Constants.UnitAircraftSubType.Target_Drone = 8103
CMO__Constants.UnitAircraftSubType.UAV = 8201
CMO__Constants.UnitAircraftSubType.UCAV = 8202
CMO__Constants.UnitAircraftSubType.Airship = 8901
CMO__Constants.UnitAircraftSubType.Aerostat = 8902

Don't call it a comeback...
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: User changing unit name

Post by nukkxx5058 »

OK, I will look that Knighthawks program. I already heard about it but at the time VS wasn't properly configured on my PC. Now it does work. So good you reminded it to me ! :-)

Thank you (and for the list of subtypes !)
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: User changing unit name

Post by KnightHawk75 »

You can get the list of sub-type string values from here:
http://commandlua.github.io/ (Search UnitAircraft or UnitFacility..etc on the page, and then press arrow next to sub-type.

Side note, for facilities of type/category 'mobile' (500X), mobile unit category on that webpage is subtype, for non-mobile ones if I recall sub-type will be nil, or duplicate the top level type I forget which it is atm);

Yes you can use the constants provided in my other VS Code package too, though I wouldn't bother if it's just a one-off sort of thing. ;)



Post Reply

Return to “Lua Legion”