Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> The War Room



Message


Kitchens Sink -> Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (2/11/2017 11:07:47 PM)

Hope some Lua gurus can help me.

I'm trying to change the Weapons Doctrine of a friendly Task Force from "Surface Weapons Hold" to "Surface Weapons Free", but only when a particular enemy surface vessel (part of an enemy Task Force) is within a certain distance from my TF (or a unit of my TF). I know that if the enemy unit is within 100nm, then his whole TF is within range and I can unload a large Anti-ship missile salvo at all the ships at one time, not shoot piecemeal as they come into range.

I know how to do the Weapons Doctrine change, but I am not sure how to set up the trigger or condition. What I have come up with so far is:

Trigger: Enemy "Unit A" is detected
Condition: ??
Action: ScenEdit_SetDoctrine({side="Me", mission="My TF Sea Control"}, {weapon_control_status_surface="0"})

So, how do I set up the Condition that enemy Unit A has to be within 100nm before the Doctrine is changed? Both TF's are moving, so I don't want to use Unit Enters Area because that could vary. Also changing the WRA missile firing distance wouldn't do what I want.

Thanks for any help!




michaelm75au -> RE: Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (2/12/2017 12:06:38 AM)

In SR7, you can now get a 'range to contact'. The condition would be something like this:
....
local answer = false
local con = ScenEdit_UnitX().ascontact[1].name
local u = ScenEdit_GetUnit({name='LST 4001 Osumi', guid='8269b881-20ce-4f2e-baa0-6823e46d55a4'})
local dist = u:rangetotarget( con)
if dist < 100 then
print('target in range (' .. dist ..'NM)')
answer=true
else
print('target not in range (' .. dist ..'NM)')
end
return answer
....




Kitchens Sink -> RE: Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (2/12/2017 12:15:29 AM)

Great! Thanks for the help. I'll give it a shot.




michaelm75au -> RE: Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (2/12/2017 1:01:29 AM)

I have tuned this some to be more useful as a condition. Note that I am using the contact generated by detecting this unit. You could 'cheat' and just use the UnitX (which is the actual real unit) to get the precise information about the triggering unit.

---
local x,y
local answer = false
-- unit base range on
local u = ScenEdit_GetUnit({name='LST 4001 Osumi', guid='8269b881-20ce-4f2e-baa0-6823e46d55a4'})
-- unit that triggered event
local contact = ScenEdit_UnitX()
-- this unit seen as a contact by others
local con = contact.ascontact
-- not generated as a contact yet
if #con ~= 0 then
-- listed as a contact by some side
-- what is the side id for the base unit
local side = ScenEdit_GetSideOptions({side=u.side}).guid
-- find the side's entry in the triggering unit's contact list
for x = 1, #con do
if con[x].side == side then
-- contact on my side
local mycontact = con[x].guid
-- distance between my base unit and the contact
local dist = u:rangetotarget( mycontact)
if dist < 100 then
print('target in range (' .. dist ..'NM)')
answer=true
else
print('target not in range (' .. dist ..'NM)')
end
end
end
end
return answer




Kitchens Sink -> RE: Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (2/12/2017 12:00:05 PM)

Thanks for your work on this Michael, much appreciated.




Kitchens Sink -> RE: Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit (2/12/2017 1:14:37 PM)

Just for general info, I thought up another way to do this:

I set up an semicircle-shaped area about 100nm out from my task force, and made the reference points comprising the area Fixed Bearing to the Task force Lead, so the area moves as my task force moves. Then I used "Unit Enters Area" as the Trigger, with no condition set.

Just another way to do the same thing I guess.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.451172