Getting Side ID from Lua

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

User avatar
wqc12345
Posts: 176
Joined: Mon Dec 07, 2015 2:56 pm
Location: San Francisco, CA

Getting Side ID from Lua

Post by wqc12345 »

I have a basic lua question.

For most of the CMANO methods, you can reference the side by it's ID, instead of the name string. How does one get the ID for the side? Is there a dumb all ID's for the side method that one can use in Lua to get this value? We have ID's for weapons, facilities, etc.. but no way to get the ID for the side? I'm curious if someone figured this out? or if there is a lua method that does this for us?

It's faster to reference the side by it's DB ID, but currently, the only way I can do this is to reference the side name via name string.

Thanks
Rory Noonan
Posts: 2419
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Getting Side ID from Lua

Post by Rory Noonan »

I'm not aware of a 'side id'; as far as I know the only way to reference a side is using the side name string or one of the functions that returns that string.

If you wanted to simplify your coding a bit, you could assign a variable for that side name:

Code: Select all

S1 = United States

or you could get the player side automatically (so they could be either side and the code will still work):

Code: Select all

S1 = ScenEdit_PlayerSide()

Either way you could then use the variable 'S1' (or whatever you like) rather than type in 'United States' or the player's side each time you need to reference it.

There is also 'PlayerSide' which stands in for the players side much like the code above.

There is a 'GUID' for each unit that is reportedly faster to use, and can be used for different units with the same displayed name. The easiest way to find a GUID for a unit is to right click it in the editor, go to 'Editor' > 'Copy ID to clipboard'. Then you can paste the GUID into your code.
Image
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

Looking for the Lua method to set/change a side. For example, from one friendly side to another based on time or other events. Thanks.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

thewood1
Posts: 6832
Joined: Sun Nov 27, 2005 6:24 pm

RE: Getting Side ID from Lua

Post by thewood1 »

from Boolagan's wiki...

ScenEdit_SetUnitSide

http://commandlua.github.io/#ScenEdit_SetUnit

Its down the page a ways.

You are like puss filled boil on nice of ass of bikini model. You are nasty to everybody but then try to sweeten things up with a nice post somewhere else. That's nice but you're still a boil on a beautiful thing! - BDukes
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

Thank you, did check that out before asking. I was looking to change or set the entire side not just a single unit within a given side. The OP asked about getting the player's side, which can be done. I was wondering if you could set the side via Lua.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

thewood1
Posts: 6832
Joined: Sun Nov 27, 2005 6:24 pm

RE: Getting Side ID from Lua

Post by thewood1 »

Why would you change an entire side and not just change posture?
You are like puss filled boil on nice of ass of bikini model. You are nasty to everybody but then try to sweeten things up with a nice post somewhere else. That's nice but you're still a boil on a beautiful thing! - BDukes
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

So you can break the friendly OOB down into several sides which the player controls depending on events that transpire. The player controls units grouped under on a single side even if they are all set to friendly. So a friendly NATO OOB could be split into sides for a) USN and b) French AF and c) Turkish ground forces (an example) and the player receives control of one those 3 friendly sides depending on how the scenario unfolds. They would lose control of the side they had. Certainly not going to be a widely used technique. But interesting to look at. Control could be passed around based on a timer, but that might be too confusing to the player. You can use ScenEdit_SetUnitSide but you will have to change each unit individually. I think anyway. A global way to switch sides would be a big help.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

User avatar
michaelm75au
Posts: 11889
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Getting Side ID from Lua

Post by michaelm75au »

The Live#2 scenarios work like you described. Some units that start out under AI control, are given over to the player to use based on events occurring.
Michael
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

I was also thinking that a designer could pass control to a side with NO units to simulate loss of overall command for a period of time. Say some "electron pulse gizmo" of the future goes off and knocks out the command network for a period of time. The player would have to plan ahead for that event making sure their AC don't run out of fuel for example.

But that begs the question. How was control passed? Maybe the units were not numerous and ScenEdit_SetUnitSide was not too tedious.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

thewood1
Posts: 6832
Joined: Sun Nov 27, 2005 6:24 pm

RE: Getting Side ID from Lua

Post by thewood1 »

I look at this as one of those things that looks interesting, but hope the devs don't spend to much time on. It can be worked around with a few different techniques.
You are like puss filled boil on nice of ass of bikini model. You are nasty to everybody but then try to sweeten things up with a nice post somewhere else. That's nice but you're still a boil on a beautiful thing! - BDukes
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

I agree and if the gang has any work arounds please let us know. Maybe the developers have an undocumented technique that Live #2 used. Usually if an API function can be retrieved it can be set, unless setting it programically wrecks havoc on something in the hands of the user. [:-]I will poke a bit more and see what can be done as is.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

Rory Noonan
Posts: 2419
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Getting Side ID from Lua

Post by Rory Noonan »

I just opened up the Live #2 scenario and had a look at some of the switching events.

The code is there, it's elegant and it seems pretty easy to write.

I don't want to post it because there's obviously issues with paying to access.

However I'm sure it's ok if I say that there is no special functions called, and that the code basically checks whether units are alive, and then if so changes side, if not moves on to the next unit.

If you don't own Live #2 it's probably worth the few dollars just to get an elegant, simple example of how to code this [:)]
Image
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

Thanks for the tip. Should make for interesting reading for sure. Good you didn't post the code. I wouldn't either. Will take a look and discuss generically, if need be. I was going through the scripts for scenarios I have trying not to spoil the FOW for myself.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

User avatar
michaelm75au
Posts: 11889
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Getting Side ID from Lua

Post by michaelm75au »

Here is a sample of how the Lua would work. It changes the side of a number of aircraft from 'Germany' to 'NATO':
for i=1,16 do -- scan thru numbers 1 to 16
if ScenEdit_GetUnit({Side='Germany', Name="Red Dog #"..i,}) ~= nil then -- unit # exists
ScenEdit_SetUnitSide({Side='Germany', Name="Red Dog#"..i, newside='NATO'}) -- change side
end
end
Michael
User avatar
kevinkins
Posts: 2223
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Side ID from Lua

Post by kevinkins »

The example above helped a lot. Thank you.
“The study of history lies at the foundation of all sound military conclusions and practice.”
― Alfred Thayer Mahan

Parel803
Posts: 603
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: Getting Side ID from Lua

Post by Parel803 »

The example works great. I changed control of the ASW helo to the controlling unit (from mother ship), I did that via a special action. Could I make that special action in a way that when it is activated it also makes a new special action for the controlling unit with the possibility to change side again, back to the side of the mother ship?
I hope this makes sense.
KnightHawk75
Posts: 1552
Joined: Thu Nov 15, 2018 7:24 pm

RE: Getting Side ID from Lua

Post by KnightHawk75 »

ORIGINAL: Parel803

The example works great. I changed control of the ASW helo to the controlling unit (from mother ship), I did that via a special action. Could I make that special action in a way that when it is activated it also makes a new special action for the controlling unit with the possibility to change side again, back to the side of the mother ship?
I hope this makes sense.

Yes you can. What you'd do is create the 2nd special action to flip it back but mark it inactive so that it does not show to the player. Then in code of first at the end you flip the inactive state of the other on and the active state on the first inactive (or if it's not repeatable that'll happen anyway) That way the two never show at the same time.
Also if you wanted, in the 2nd flip the first back to active if you wanted to allow constant flip flopping, assuming you change the repeatable setting to true.

The way you do that at the tail end of the first is ScenEdit_SetSpecialAction({ActionNameOrID="MySecondSA",IsActive=true})

Parel803
Posts: 603
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: Getting Side ID from Lua

Post by Parel803 »

KnightHawk, great, thank you for you're time and answer.
best regards
Parel803
Posts: 603
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: Getting Side ID from Lua

Post by Parel803 »

Goodmorning,
A follow up question if I may.

Made two Special Actions, one to hand over my helo to another side and one to take her back.
Used the InputBox from earlier lessons by KH. If used that in both SA's, so I check which side has control over my helo and put that in the InputBox.
My question is; would it be possible to make the second SA (take back control) in a manner that it doesn't matter which side has control, I take control back (switch het to my side)?

The scen is in the last beta. The lua is the take back part with the InputBox:
If there are stupidities in it, please let me know

function HeloHandOverReturn(RUnit)
ScenEdit_SetUnitSide({Side=RUnit, Name='Bird #1', newside='HOLL'})
end

function GetNumberFromUser(displaytext,minnum,maxnum,errornum)
local retval = ScenEdit_InputBox(displaytext);
if (retval ~=nil) and retval ~="" then -- "" is a user pressing cancel.
retval = tonumber(retval); --attempt convert.
if retval ==nil then return errornum; end -- not point to continue if it failed.
else
return errornum; --was already nil or emptystring.
end
if retval >= minnum and retval <= maxnum then return retval; end --valid so return the number.
return errornum; -- if we get here it was a number but was out of range.-- failed validation
end

local function Question()
local trycount,retval = 0,0;
while (retval == 0) do
if trycount > 4 then retval = 'TRMP'; break; --default to a dbid.
else
trycount = trycount+1;
retval = GetNumberFromUser('1: RDAM \r2: TRMP',1,2,0);
end
--reuse and change retval to the chosen distance based on selection
if retval == 1 then retval = 'RDAM';--if the selection was valid and #1. {name='RDAM', guid='P7ML9T-0HMGF4ULQP4EM'}
elseif retval==2 then retval = 'TRMP';-- if the selection was valid and #2. {name='TRMP', guid='P7ML9T-0HMGF4ULQP4H0'}
end
end
return retval;
end

HeloHandOverReturn(Question())


best regards GJ
Attachments
Test SA HandoverControl2.zip
(15.34 KiB) Not downloaded yet
KnightHawk75
Posts: 1552
Joined: Thu Nov 15, 2018 7:24 pm

Re: Getting Side ID from Lua

Post by KnightHawk75 »

My question is; would it be possible to make the second SA (take back control) in a manner that it doesn't matter which side has control, I take control back (switch het to my side)?
I may be missing something but to do that wouldn't you just call SetUnitSide without any questions/input boxing and just set the new side to whatever the current player side is? Again I might be missing something about your question.

ScenEdit_SetUnitSide({guid=unitWrapper.guid, newside=ScenEdit_PlayerSide()})
Post Reply

Return to “Lua Legion”