Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

How to use Lua Script to mark a contact hostile?

 
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 >> How to use Lua Script to mark a contact hostile? Page: [1]
Login
Message << Older Topic   Newer Topic >>
How to use Lua Script to mark a contact hostile? - 5/25/2018 3:55:11 AM   
gf85

 

Posts: 7
Joined: 5/24/2018
Status: offline
Greeting, this is my first post here and I am new to CMNAO and Lua script, so sorry for dumb question.

I am learning to make a scenario, as seen in the picture, I am trying to simulate a Myanmar aircraft (Contact Attack #11) violate Chinese airspace. In my plan, an event should fire later changing the posture btw the two sides: "Myanmar" and "PLAAF" to hostile and hopefully, two J-7 that chasing the contact will initiate an attack.

But then I find it doesn't work well. After event fired the posture btw Myanmar and PLAAF do become hostile (Myanmar facilities do turn red), but the contact remains unfriendly. Then I find out it's because of the contact's side is not yet identified by PLAAF, remain unknown, so it wasn't marked hostile immediately after the event fired.

My question is can I manually get the contact's side for PLAAF or directly assign the contact as hostile though Lua script? I have looked for a while but can't find a handy function that seems to fit my need. Thanks!







Attachment (1)

< Message edited by gf85 -- 5/25/2018 3:56:58 AM >
Post #: 1
RE: How to use Lua Script to mark a contact hostile? - 5/25/2018 5:54:13 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
My experience with this is limited but check these out:

https://commandlua.github.io/index.html#ScenEdit_UnitX (to get the unit that fired the event)

https://commandlua.github.io/index.html#Unit (use ascontact to get the contact table....)

https://commandlua.github.io/index.html#Contact (you can't set classificationlevel but you can set posture it looks like)

Use Lua console to examine the data and test out setting it.

(in reply to gf85)
Post #: 2
RE: How to use Lua Script to mark a contact hostile? - 5/25/2018 6:15:34 AM   
gf85

 

Posts: 7
Joined: 5/24/2018
Status: offline
Thanks for NimrodX's answer, but I still don't know how to figure it out

I do have the unit's ID (it's added through scenario editor, not by code),
I have tried to set the unit's autodetectable = true but doesn't work

ScenEdit_SetUnit ({side="Tatmadaw", unitname="Recon AC", autodetectable= true})

and I can't find a function that can set the property of contact...

(in reply to NimrodX)
Post #: 3
RE: How to use Lua Script to mark a contact hostile? - 5/25/2018 11:38:49 AM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
gf85

I am in now way, shape or forum the Lua expert. But I think I can help with this one.

My 'GoTo' guide to help is here: http://commandlua.github.io/

by running through the functions you can find:

ScenEdit_SetUnitSide (sidedesc)
Changes the side of a unit
Parameters:
sidedesc SideDescription The sides to change for the unit. Group will change attached units

The page is very well hyperlinked so you can follow up on some of the syntax

B

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to gf85)
Post #: 4
RE: How to use Lua Script to mark a contact hostile? - 5/26/2018 5:07:34 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline

quote:

ORIGINAL: gf85

Thanks for NimrodX's answer, but I still don't know how to figure it out

I do have the unit's ID (it's added through scenario editor, not by code),
I have tried to set the unit's autodetectable = true but doesn't work

ScenEdit_SetUnit ({side="Tatmadaw", unitname="Recon AC", autodetectable= true})

and I can't find a function that can set the property of contact...


Ok, basically the problem is this:

There's a "Unit" and there's a "Contact". These are different tables.

A Unit is a table that describes what the unit physically is in reality according to the universe. There's only one Unit for a unit.

A Contact is what a specific side *thinks* the unit is. So there's actually more than one Contact for the same unit. If we have sides A, B, and C then Unit X will have three Contacts, one for "what side A thinks X is", one for "what side B thinks X is", and one for "what side C thinks X is".

So there will be a unit called X. Then there will be a Contact for what side PLAAF thinks X is and totally separate table for what every other side thinks X is.

I'm pretty sure I know how to code this but it would save me some time if you could upload your scenario file as you have it now so that I can just open the event editor and have everything else set up already. I don't think there's any function for this, you just need to grab the Contact table for PLAAF's "view" of the Unit and set the table member by key using the table[key] = "xxx" syntax sort of like this:

local contact = ScenEdit_GetContact({side="United States", guid="c4114322-900c-428d-a3e3-0af701e81a7a"})
contact["posture"] = "hostile"

Anyway, post or PM me your scenario file and I can show you.

(in reply to gf85)
Post #: 5
RE: How to use Lua Script to mark a contact hostile? - 5/27/2018 5:26:12 AM   
Rory Noonan

 

Posts: 2816
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
Hey gf85,

As I understand it the problem you're running into is that an aircraft that is marked unfriendly (presumably by an exclusion zone) is not being fired on after its side turns hostile, which is because there is no positive ID.

It seems like a simple solution would be to change the RoE for the side you want to do the shooting to 'FREE' to allow them to attack without making a positive ID.

Give that a try and let us know how it goes.


If that doesn't work, you're definitely on the right track with the autodetect idea. Some sample code is below, try changing the values to suit your scenario:
quote:


ScenEdit_SetUnit({name='P-3B Orion AEW', guid='27f595a4-14b5-49aa-968c-cf59048f8e73',autodetectable=true})

A quick way to get the name and GUID of a unit is to click it and press Ctrl+C; that will put the data on the clipboard ( {name='P-3B Orion AEW', guid='27f595a4-14b5-49aa-968c-cf59048f8e73'} in the above example was collected by this method)

Also be aware that autodetection can take up to a minute to take effect.

_____________________________


(in reply to NimrodX)
Post #: 6
RE: How to use Lua Script to mark a contact hostile? - 5/27/2018 5:43:18 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
It's also possible to make an exclusion zone which doesn't require any code at all, but this isn't really ideal.

(in reply to Rory Noonan)
Post #: 7
RE: How to use Lua Script to mark a contact hostile? - 5/28/2018 12:31:20 AM   
gf85

 

Posts: 7
Joined: 5/24/2018
Status: offline
Thank you for NimrodX, Gunner98, and moderator kindly reply.

Sorry for late reply, I will try the suggest code later.
Sure I have read Gunner98's guide, it's help me a lot.
Attached with my scenario any(still very beginning though)
I possibly will have to ask more dumb question later on

Attachment (1)

(in reply to gf85)
Post #: 8
RE: How to use Lua Script to mark a contact hostile? - 5/28/2018 9:16:08 AM   
gf85

 

Posts: 7
Joined: 5/24/2018
Status: offline
autodetectable works but as apache85 said it takes some time to take effect.
Then I tried NimrodX's code and it works, only have to change the line contact["posture"] = "H", "hostile" seems not work.
Thanks!

(in reply to gf85)
Post #: 9
RE: How to use Lua Script to mark a contact hostile? - 5/29/2018 10:08:56 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
Oops, sorry for the misinfo there. I think the documentation kind of lied to me, or maybe "Hostile" or 3 or something works in some cases or not others. Anyway, here's what I was talking about:

quote:


-- We might not know what unit it is! But we can find it easily with this.
local contact = ScenEdit_UnitC()
print(contact)
-- No matter what it is, now it will be considered hostile.
contact.posture = 'H'

local msg = string.format([[Your tell your pilots: "I don't care what this %s is! I order you to consider it hostile considering where you found it!"]], contact)

ScenEdit_SpecialMessage("PLAAF", msg)


If you do it like that you can change what unit will trigger it simply by editing the event trigger to specify a vague range of contacts or a specific unit without even editing the code.

The attached file will quickly result in an ID and posture change once it is unpaused.

Attachment (1)

(in reply to gf85)
Post #: 10
RE: How to use Lua Script to mark a contact hostile? - 5/31/2018 2:35:38 AM   
gf85

 

Posts: 7
Joined: 5/24/2018
Status: offline
Nevermind, I get the right function anyway.
And thanks for the help I can make it now.

(in reply to NimrodX)
Post #: 11
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> How to use Lua Script to mark a contact hostile? 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.968