Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Getting Side ID from Lua

 
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 >> Getting Side ID from Lua Page: [1]
Login
Message << Older Topic   Newer Topic >>
Getting Side ID from Lua - 6/20/2016 8:00:14 PM   
wqc12345


Posts: 250
Joined: 12/7/2015
From: San Francisco, CA
Status: offline
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
Post #: 1
RE: Getting Side ID from Lua - 6/21/2016 12:45:48 AM   
Rory Noonan

 

Posts: 2780
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
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:

S1 = United States


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

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.

< Message edited by apache85 -- 6/21/2016 2:17:12 AM >

(in reply to wqc12345)
Post #: 2
RE: Getting Side ID from Lua - 9/4/2016 12:38:50 AM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
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.

(in reply to Rory Noonan)
Post #: 3
RE: Getting Side ID from Lua - 9/4/2016 2:13:44 AM   
thewood1

 

Posts: 5896
Joined: 11/27/2005
Status: offline
from Boolagan's wiki...

ScenEdit_SetUnitSide

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

Its down the page a ways.



< Message edited by thewood1 -- 9/4/2016 2:16:08 AM >

(in reply to kevinkins)
Post #: 4
RE: Getting Side ID from Lua - 9/4/2016 2:45:59 AM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
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.

(in reply to thewood1)
Post #: 5
RE: Getting Side ID from Lua - 9/4/2016 4:00:28 AM   
thewood1

 

Posts: 5896
Joined: 11/27/2005
Status: offline
Why would you change an entire side and not just change posture?

(in reply to kevinkins)
Post #: 6
RE: Getting Side ID from Lua - 9/4/2016 5:08:22 AM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
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.

< Message edited by kevinkin -- 9/4/2016 5:23:35 AM >

(in reply to thewood1)
Post #: 7
RE: Getting Side ID from Lua - 9/4/2016 5:45:23 AM   
michaelm75au


Posts: 13257
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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

(in reply to kevinkins)
Post #: 8
RE: Getting Side ID from Lua - 9/4/2016 6:08:24 AM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
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.

(in reply to michaelm75au)
Post #: 9
RE: Getting Side ID from Lua - 9/4/2016 12:54:09 PM   
thewood1

 

Posts: 5896
Joined: 11/27/2005
Status: offline
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.

(in reply to kevinkins)
Post #: 10
RE: Getting Side ID from Lua - 9/4/2016 1:09:48 PM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
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.

(in reply to thewood1)
Post #: 11
RE: Getting Side ID from Lua - 9/4/2016 1:29:49 PM   
Rory Noonan

 

Posts: 2780
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
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

(in reply to kevinkins)
Post #: 12
RE: Getting Side ID from Lua - 9/4/2016 2:08:33 PM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
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.

(in reply to Rory Noonan)
Post #: 13
RE: Getting Side ID from Lua - 9/4/2016 2:25:51 PM   
michaelm75au


Posts: 13257
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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

(in reply to kevinkins)
Post #: 14
RE: Getting Side ID from Lua - 9/4/2016 5:01:43 PM   
kevinkins


Posts: 2194
Joined: 3/8/2006
Status: offline
The example above helped a lot. Thank you.

(in reply to michaelm75au)
Post #: 15
RE: Getting Side ID from Lua - 4/23/2020 6:36:18 PM   
Parel803

 

Posts: 387
Joined: 10/10/2019
From: Netherlands
Status: offline
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.

_____________________________


(in reply to kevinkins)
Post #: 16
RE: Getting Side ID from Lua - 4/25/2020 2:25:26 AM   
KnightHawk75

 

Posts: 1040
Joined: 11/15/2018
Status: online
quote:

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



< Message edited by KnightHawk75 -- 4/25/2020 2:26:52 AM >

(in reply to Parel803)
Post #: 17
RE: Getting Side ID from Lua - 4/25/2020 8:08:28 AM   
Parel803

 

Posts: 387
Joined: 10/10/2019
From: Netherlands
Status: offline
KnightHawk, great, thank you for you're time and answer.
best regards

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