Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit

 
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 >> The War Room >> Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua Script Question: Changing Weapons Doctrine based on... - 2/11/2017 11:07:47 PM   
Kitchens Sink

 

Posts: 402
Joined: 5/4/2014
Status: offline
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!
Post #: 1
RE: Lua Script Question: Changing Weapons Doctrine base... - 2/12/2017 12:06:38 AM   
michaelm75au


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

< Message edited by michaelm -- 2/12/2017 12:19:28 AM >


_____________________________

Michael

(in reply to Kitchens Sink)
Post #: 2
RE: Lua Script Question: Changing Weapons Doctrine base... - 2/12/2017 12:15:29 AM   
Kitchens Sink

 

Posts: 402
Joined: 5/4/2014
Status: offline
Great! Thanks for the help. I'll give it a shot.

(in reply to michaelm75au)
Post #: 3
RE: Lua Script Question: Changing Weapons Doctrine base... - 2/12/2017 1:01:29 AM   
michaelm75au


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

_____________________________

Michael

(in reply to Kitchens Sink)
Post #: 4
RE: Lua Script Question: Changing Weapons Doctrine base... - 2/12/2017 12:00:05 PM   
Kitchens Sink

 

Posts: 402
Joined: 5/4/2014
Status: offline
Thanks for your work on this Michael, much appreciated.

(in reply to michaelm75au)
Post #: 5
RE: Lua Script Question: Changing Weapons Doctrine base... - 2/12/2017 1:14:37 PM   
Kitchens Sink

 

Posts: 402
Joined: 5/4/2014
Status: offline
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.

(in reply to Kitchens Sink)
Post #: 6
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> The War Room >> Lua Script Question: Changing Weapons Doctrine based on Distance to enemy unit 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