Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Query sub 'Altitude' and set comms on/off

 
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 >> Query sub 'Altitude' and set comms on/off Page: [1]
Login
Message << Older Topic   Newer Topic >>
Query sub 'Altitude' and set comms on/off - 1/2/2022 6:11:41 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
So this should be simple, but for some reason I can't figure out where to start (querying a unit's 'altitude'). I assume (possibly a bad move) that below -40 m /-131 ft a sub would loose comms. So what I'm trying to do is to query this unit's...

{name='Kasan (K-561)', guid='XMJRWB-0HME8AIUVIKKH'}

...'Altitude" every 30 seconds and if they are above 40 m turn comms on and turn comms off below there. Where I'm stuck in particular is querying the unit's altitude.

< Message edited by BeirutDude -- 1/10/2022 11:16:10 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!
Post #: 1
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 6:29:09 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
I stand corrected I don't have turning off the comms because "outofcomms" is apparently a read only parameter???

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 2
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 7:37:41 PM   
musurca

 

Posts: 128
Joined: 7/16/2020
Status: offline
The read-only attributes can usually be set with ScenEdit_SetUnit(). Here's how I might do it (enclosing the calls to ScenEdit_Set/GetUnit in a pcall, to avoid any silent exceptions if something happens to Kasan):

-----
local kasan_guid = 'XMJRWB-0HME8AIUVIKKH'
local success, unit = pcall(ScenEdit_GetUnit, {guid=kasan_guid})
if unit then
    if unit.altitude < -40 then
        if unit.outofcomms == false then
            pcall(ScenEdit_SetUnit, {guid=kasan_guid, outofcomms=true})
        end
    else
        if unit.outofcomms == true then
            pcall(ScenEdit_SetUnit, {guid=kasan_guid, outofcomms=false})
        end
    end
end

----

But isn't this also essentially what the 'Realistic Sub Comms' setting does automatically?

(in reply to BeirutDude)
Post #: 3
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 8:01:24 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
quote:

But isn't this also essentially what the 'Realistic Sub Comms' setting does automatically?


So there is only one operational unit in the scenario, the sub controlled by the player. Then there are the satellites and the intel they provide. I'm looking to have the player (in the sub) able to look at the satellite info when their unit is above -40 m but have it unavailable to them below -40 m.

The game function you loose control of the submarine, I don't want that, just the loss of other data coming into the sub.

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to musurca)
Post #: 4
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 8:27:44 PM   
musurca

 

Posts: 128
Joined: 7/16/2020
Status: offline
Oh I see — in that case, you’d want to mark the satellite units out of comms, not the submarine.

If for whatever reason that’s not possible, you could instead put the satellite units on a separate side friendly to the player side so that they share contact information. When the sub descends below -40m, you’d change the side posture to neutral.

(in reply to BeirutDude)
Post #: 5
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 8:34:02 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline

quote:

ORIGINAL: musurca

Oh I see — in that case, you’d want to mark the satellite units out of comms, not the submarine.

If for whatever reason that’s not possible, you could instead put the satellite units on a separate side friendly to the player side so that they share contact information. When the sub descends below -40m, you’d change the side posture to neutral.


I like it! Thank you! simple is better!

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to musurca)
Post #: 6
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 9:20:16 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
musurca, Thanks for your help!!!!

I modified your code to this...

quote:


local kasan_guid = 'XMJRWB-0HME8AIUVIKKH'
local success, unit = pcall(ScenEdit_GetUnit, {guid=kasan_guid})
if unit then
if unit.altitude < -40 then
if unit.outofcomms == false then
ScenEdit_SetSidePosture("Russia","Satellites","F")
ScenEdit_SetSidePosture("Satellites","Russia","F")
end
else
if unit.outofcomms == true then
ScenEdit_SetSidePosture("Russia","Satellites","H")
ScenEdit_SetSidePosture("Satellites","Russia","H")
end
end
end


It doesn't fail in the Lua Console, but it also doesn't seem to be seeing Kasam's altitude.

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to musurca)
Post #: 7
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 9:54:13 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
It's finding the altitude as the print is giving -27 meters.

quote:

local unit = ScenEdit_GetUnit ({side="Russia", Name="Kasan (K-561)", guid='XMJRWB-0HME8AIUVIKKH'})
print(unit.altitude)
if unit.altitude > -40 then
if unit.altitude == false then
ScenEdit_SetSidePosture("Russia","Satellites","F")
ScenEdit_SetSidePosture("Satellites","Russia","F")
end
else
if unit.altitude == true then
ScenEdit_SetSidePosture("Russia","Satellites","H")
ScenEdit_SetSidePosture("Satellites","Russia","H")
end
end


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 8
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 10:44:10 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
Success!!!!!!!

musruca, THANK YOU for your help, you sent me in teh right direction!!!!

quote:


local unit = ScenEdit_GetUnit ({side="Russia", Name="Kasan (K-561)", guid='XMJRWB-0HME8AIUVIKKH'})
print(unit.altitude)
ldepth = unit.altitude
print(ldepth)
if ldepth < -41 then
ScenEdit_SetSidePosture("Russia","Satellites","N")
ScenEdit_SetSidePosture("Satellites","Russia","N")
end

if ldepth > -41 then
ScenEdit_SetSidePosture("Russia","Satellites","F")
ScenEdit_SetSidePosture("Satellites","Russia","F")
end


< Message edited by BeirutDude -- 1/2/2022 11:01:47 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 9
RE: Query sub 'Altitude' and set comms on/off - 1/2/2022 11:06:23 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline

quote:

ORIGINAL: musurca

The read-only attributes can usually be set with ScenEdit_SetUnit(). Here's how I might do it (enclosing the calls to ScenEdit_Set/GetUnit in a pcall, to avoid any silent exceptions if something happens to Kasan):

-----
local kasan_guid = 'XMJRWB-0HME8AIUVIKKH'
local success, unit = pcall(ScenEdit_GetUnit, {guid=kasan_guid})
if unit then
    if unit.altitude < -40 then
        if unit.outofcomms == false then
            pcall(ScenEdit_SetUnit, {guid=kasan_guid, outofcomms=true})
        end
    else
        if unit.outofcomms == true then
            pcall(ScenEdit_SetUnit, {guid=kasan_guid, outofcomms=false})
        end
    end
end

----

But isn't this also essentially what the 'Realistic Sub Comms' setting does automatically?

quote:

-----
local kasan_guid = 'XMJRWB-0HME8AIUVIKKH'
local success, unit = pcall(ScenEdit_GetUnit, {guid=kasan_guid})
if unit then
if unit.altitude < -40 then
if unit.outofcomms == false then
pcall(ScenEdit_SetUnit, {guid=kasan_guid, outofcomms=true})
end
else
if unit.outofcomms == true then
pcall(ScenEdit_SetUnit, {guid=kasan_guid, outofcomms=false})
end
end
end

----


BTW, how do you get the indentions in the message board/Forum post????

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to musurca)
Post #: 10
RE: Query sub 'Altitude' and set comms on/off - 1/3/2022 12:44:20 AM   
musurca

 

Posts: 128
Joined: 7/16/2020
Status: offline
Happy to help!

You can get the indentations by using the 'code' tag from the buttons above the text box. But actually I generally avoid it unless the code is very short-- longer segments break the layout on most browsers.

(in reply to BeirutDude)
Post #: 11
RE: Query sub 'Altitude' and set comms on/off - 1/6/2022 9:06:09 PM   
KnightHawk75

 

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

quote:

ORIGINAL: musurca

Happy to help!

You can get the indentations by using the 'code' tag from the buttons above the text box. But actually I generally avoid it unless the code is very short-- longer segments break the layout on most browsers.


Yup at about the 20 line barrier it get garbled, so about every 15/20 lines end the original code tag and insert a new one, it adds extra unavoidable spacing though, which while annoying is less so then no indentation most the time. ;)

(in reply to musurca)
Post #: 12
RE: Query sub 'Altitude' and set comms on/off - 1/10/2022 11:23:38 PM   
BeirutDude


Posts: 2625
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
I found this code in the Silent Service DLC and there is a part I don't understand...

quote:



x = ScenEdit_GetUnit({guid='c0e0b7a4-2ec7-4c75-add0-c53dead2fad8'})
if x.altitude < -21 then
ScenEdit_MsgBox('Satellite connection lost.', 6)
assets = {
{name='Kosmos 2221',guid='7861ff62-d7fd-405d-b768-8e9271bc414f'},
{name='Kosmos 2227',guid='0e7f4bc3-3185-4c6c-9403-de8aae1f43a6'},
{name='Kosmos 2237',guid='18cc2131-a9db-4a2c-a6ae-3e1637c66d3f'},
{name='Kosmos 2263',guid='1bdaacb3-94b9-45b0-9548-071973fb6689'},
{name='Kosmos 2263',guid='1bdaacb3-94b9-45b0-9548-071973fb6689'},
{name='Kosmos 2278',guid='f4c61907-6802-4fa3-83df-7433def6d8d8'},
{name='Kosmos 2297',guid='585ed1d5-920d-42be-b57c-2a83d5260bb5'},
{name='Kosmos 2333',guid='bdcf7c78-eb2b-4e84-ba7d-7f57129f1756'},
{name='Kosmos 2335',guid='b6b7296d-1684-47fc-9ac6-8c6c86f8d0bd'},
{name='Kosmos 2347',guid='0e012194-01b5-46fe-8b78-4abaf814b5fe'},
{name='Kosmos 2359',guid='98ba4ce3-6686-46ec-b21b-5081dfb9ac16'},
{name='Kosmos 2360',guid='9e968956-a328-491e-90c2-8052cdf25161'},
{name='FV Castro el Gato',guid='5d4c309d-0894-4bd8-b0e8-2f54c0d02c95'},
{name='FV Viktor Kot', guid='fcee49f9-5df5-451f-a721-9d763083e876'},
}
for i = 1,#assets do
unit = ScenEdit_GetUnit({guid=assets.guid})
if unit ~= nil then
ScenEdit_SetUnit({side='Russia',guid=assets.guid,OutOfComms=true})
end
end
ScenEdit_SetEvent('SatelliteCheck', {isactive=false})
end



I'm not familiar with a "for" statement what is this doing? "for i = 1,#assets do"
And this as well? " unit = ScenEdit_GetUnit({guid=assets.guid})"


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to KnightHawk75)
Post #: 13
RE: Query sub 'Altitude' and set comms on/off - 1/11/2022 5:46:00 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
quote:

ORIGINAL: BeirutDude

I found this code in the Silent Service DLC and there is a part I don't understand...
...

I'm not familiar with a "for" statement what is this doing? "for i = 1,#assets do"
And this as well? " unit = ScenEdit_GetUnit({guid=assets.guid})"


The for statement sets up a loop which exits based on the value of a variable here it's 'i' that will get auto incremented by default upon each loop.
for i = 1 (initial value of i is 1) to #assets (the count of or number of entries in the assets table) do.

So say #assets is 14... the statement says 'Do the following while i is between 1 and 14'
...does iteration based on i=1... gets to end starts over at top again with i=2...etc..etc.. till 15.


unit = ScenEdit_GetUnit({guid=assets.guid})
-- Get a unit wrapper for unit with the guid from the assets table ass and assign it to var unit. However I think that should read guid=assets.guid if it's to function right.










< Message edited by KnightHawk75 -- 1/11/2022 5:48:01 AM >

(in reply to BeirutDude)
Post #: 14
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Query sub 'Altitude' and set comms on/off 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.703