How to use Lua Script to mark a contact hostile? (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


gf85 -> How to use Lua Script to mark a contact hostile? (5/25/2018 3:55:11 AM)

Greeting, this is my first post here and I am new to CMNAO and Lua script, so sorry for dumb question.[:D]

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!




[image]local://upfiles/59706/0D7A1C84078A4D5C8186E5615FEA8B56.jpg[/image]




NimrodX -> RE: How to use Lua Script to mark a contact hostile? (5/25/2018 5:54:13 AM)

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.




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

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...




Gunner98 -> RE: How to use Lua Script to mark a contact hostile? (5/25/2018 11:38:49 AM)

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




NimrodX -> RE: How to use Lua Script to mark a contact hostile? (5/26/2018 5:07:34 AM)


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.




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

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.




NimrodX -> RE: How to use Lua Script to mark a contact hostile? (5/27/2018 5:43:18 AM)

It's also possible to make an exclusion zone which doesn't require any code at all, but this isn't really ideal.




gf85 -> RE: How to use Lua Script to mark a contact hostile? (5/28/2018 12:31:20 AM)

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[:D]




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

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! [sm=happy0065.gif]




NimrodX -> RE: How to use Lua Script to mark a contact hostile? (5/29/2018 10:08:56 AM)

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.




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

Nevermind, I get the right function anyway.[;)]
And thanks for the help I can make it now.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.796875