Jump to content

Recommended Posts

Posted (edited)

Hi guys,

 

I am a developer (mostly C#) and I recently jumped in DCS scripting, LUA and MOOSE. I am fluent with writing scripts, but I just need to get used to that new API. I have a question about coordinates.

 

I am doing a test where boat A and boat B are moving toward each other. I want message "collision" to show up when both boat are within 200 meters of each other.

 

1. How can I get the coordinate of a unit. I see the class UNIT, GROUP and COORDINATE in the moose doc, but can figure out what to use to get the coordinate from a specific unit.

 

2. Should I use a scheduler class and check out the distance at every ...let's say ... 5 seconds? I do not want to use a "continuous" trigger within the DCS mission editor. Actually, is there a way to have a continuous trigger in DCS that check something at specific time interval without using a scheduler in moose? If not, I am under the impression that code is executed in very close loop in a "continuous" trigger.

 

By the way, we should propose to DCS to have a new field in their CONTINUOUS trigger named "Interval" where you could put in seconds the interval between execution.

 

Thanks guys

Edited by Frag
Posted

1. Unit.getPosition

 

2. Use a switched condition that cycles a flag on and off. Mission start, flag on (1); switched condition, time since flag (1,5), do script (whatever) + flag off (1) + flag on (1)

 

Pretty easy to work around the absence of built in scheduling for continuous actions using the above method but it would be convenient. Continuous actions are executed once/second by default just FYI.

Posted (edited)
Hi guys,

 

I am doing a test where boat A and boat B are moving toward each other. I want message "collision" to show up when both boat are within 200 meters of each other.

 

1. How can I get the coordinate of a unit. I see the class UNIT, GROUP and COORDINATE in the moose doc, but can figure out what to use to get the coordinate from a specific unit.

 

 

Hi there

 

There's no way of targeting individual units directly in the current DCS scripting engine. Groups, however, can be targeted individually.

So, what you need to do is create groups composed of a single unit, that way you'll be able to target them (ie. 2 groups, one boat in each of them).

 

EDIT:

Mmm...looks like I was mistaken there. Targeting individual units seems to be possible to some extent (messages can't be sent to individual units, though, that's where my confusion came from).

In MOOSE, you can get unit coordinates using:

UNIT:GetCoordinate()

 

Check the MOOSE documentation for UNIT functionalities.

 

As for creating trigger zones linked to individual units in MOOSE, use this:

ZONE\_UNIT:New(ZoneName, ZoneUNIT, Radius, Offset)

 

Finally, you can use this in order to check for the presence of units within a zone:

UNIT:IsInZone(Zone)

 

 

 

As for getting group coordinates in MOOSE, you can use:

GROUP:GetCoordinate()

 

Check the MOOSE documentation for GROUP and CONTROLLABLE functionalities (both apply to groups).

 

In order to get the distance between the coordinates, you can use:

COORDINATE:Get2DDistance(TargetCoordinate)

 

Check the MOOSE documentation for COORDINATE functionalities.

 

As for the message trigger, I'd use a simple distance check within a scheduler (which could be programmed to stop once the distance check returns "true").

 

The thing that you need to decide is the message recipient(s), though.

Will it be a message for all, for coalition or for a group(s)?

 

Hope this helps

 

PS: An alternative method would be to create a 200m trigger zone around either of the boats (the zone would move with the boat it's attached to), then use GROUP:IsCompletelyInZone(Zone) inside the same kind of scheduler, in order to check for the presence of the other boat.

Check the MOOSE documentation for ZONE functionalities.

Edited by Hardcard
Posted

Scripted this very same application.

 

PlayerGrp = GROUP:FindByName( " P51 Escort" ) -- first group
BombGrp1 = GROUP:FindByName( "Bomb Grp1" )  --  second group to get distance from

-- Simple get distance

SCHEDULER:New( nil, 
 function()
       
     PlyrCoord = PlayerGrp:GetCoordinate()  -- Get Player group coordinate
     BmbrCoord = BombGrp1:GetCoordinate()
     PlyrDist = BmbrCoord:Get2DDistance( PlyrCoord ) -- Distance in meters

 end, {}, 0, 10 -- Starts schedule at time 0, repeats every 10 sec.
 )
 
-- Example of complex use.
 
 Atk1Sked = SCHEDULER:New( nil, 
 function()
              
     PlyrCoord = PlayerGrp:GetCoordinate()  -- Get Player group coordinate
     BmbrCoord = BombGrp1:GetCoordinate()
     PlyrDist = BmbrCoord:Get2DDistance( PlyrCoord )
     
    if PlyrDist <= 10000 then  -- Send bearing and range text if distance <= 10,000 meters

       DistNM = PlyrDist * .540 -- Returns distance in meters
       PlyrVector = BmbrCoord:GetDirectionVec3( PlyrCoord )  --Returns vector in Vec3 to Player
       PlyrBearing = BmbrCoord:GetAngleRadians( PlyrVector ) -- Returns bearing Bomber to Player
       PlayerBR = BmbrCoord:GetBRText( PlyrBearing, DistNM, SETTINGS:SetImperial() )  -- Returns bearing, distance text
       WelcomeMsg = "Colt 1, Springfield 3. Got you visual, bearing ".. PlayerBR .." NM"
       MessagePlayer = MESSAGE:New( WelcomeMsg, 15, nil ):ToAll()

    end
       end, {}, 0, 10
  )

 

 

Ran into a problem getting valid results when I tried to use this basic script to report enemy fighters chasing and closing to selected distance on B24 bombers in WWII scenario.

Posted

2. Use a switched condition that cycles a flag on and off. Mission start, flag on (1); switched condition, time since flag (1,5), do script (whatever) + flag off (1) + flag on (1)

 

You can actually just use flag increase as the lone trigger action to act as a repeating timer because the time since flag condition is based upon when the flag value is changed.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted

Thanks for all the answers guys. I realized that looking directly at the moose code answers a lot of my questions instead of searching in the documentation.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...