Jump to content

Recommended Posts

Posted

Hi

 

I am building a training mission which a lot of units in. 4 x Ka-50s, 4 x A-10Cs, 4 x Su-25Ts ...

All of those units have an unique name, such ad Ka-50_CAS1, A-10C_AFAC etc..

 

I need to send a message to all player when any of those group is in a zone, the message is "xxx is in zone A", such as "Ka-50_CAS1 is in zone A"

 

Below is how I do this:

Create a trigger zone and name it "Zone A",

Create a trigger, name it Trg_Ka-50_CAS1, and set the condition is Ka-50_CAS1 is in Zone A, the action is Send message to All("Ka-50_CAS1 is in Zone A").

 

Sure it should work perfectly.

 

Unfortunately there are 12 units and 6 zones, so I need to create 12*6=72 triggers, as a programmer this is not how we resolve an issue.

 

How can I use a lua script to simplify this work.

 

Below is pseudo code

 

trgZoneList[] = {zoneA, zoneB, zoneC, zoneD, zoneE, zoneF};
unitList[]={ka50Cas1, ka50Cas2, ka50Cas3, ka50Cas4, ...}

for (i=0; i<len(trgZoneList); i++)
{
   for (j=0; j<len(unitList); j++)
  {
       if (unitIsInZone(trgZoneList[i], unitList[j]))
       {
           sendMessage(unitList[j].name+" is in zone "+"trgZoneList[i]");
       }
  }
}

 

How can I convert this to lua code and use it in the trigger?

 

Thanks

I7-6700K OC 4.9G, 896G SSD, 32G RAM @ 2400MHz, NH-D15 cooling system,TM Hotas Warthog,Saitek Pro Flight Rudder Pedals,TrackIr 5, BOSE M2

Posted

Good thinking and a perfect use case to get yourself acquainted with Lua and the Simulator Scripting Engine. :thumbup:

 

Possibly the single most invaluable resource is the Hoggit Wiki, which is more up to date than ED's SSE documentation: Simulator Scripting Engine Documentation.

 

Of course that expects you to be able to understand and write Lua already.

 

IMO a very good introduction is the Lua Directory.

 

Finally, allow me a little bit of self promotion: Tutorial: Introduction to Lua scripting :smartass:

Posted

You can use MOOSE for that. There is already an example mission which does basically what you want.

 

-- Name: ZON-510 - Send message if Clients fly the first time in the Polygon Zones
-- Author: Wingthor and FlightControl
-- Date Created: 20 January 2017
--
-- # Situation:
--
-- There are a couple of player slots of Su-25Ts, that need to fly through two poly zones. 
-- Once a player flies through a poly zone, a message will be sent. But only once. If he flies back through the same zone,
-- nothing is displayed anymore. Unless he logs off and rejoins the mission.
--
-- # Test cases:
-- 
-- 

-- MOOSE wraps each Group alive in the mission into a GROUP class object. The GROUP class object is a wrapper object, wrapping
-- the Group object from DCS and adding methods to it.
-- Get the GROUP wrapper objects that were created by MOOSE at mission startup, by using the GROUP:FindByName() method.
-- The Group name is the parameter to be searched for.
-- Note that late activated groups are also "alive" and have a corresponding GROUP object in the running mission.
PolyZoneGroup1 = GROUP:FindByName("PolyZone1")
PolyZoneGroup2 = GROUP:FindByName("PolyZone2")

-- Create 2 Polygon objects, using the ZONE_POLYGON:New constructor.
-- The first parameter gives a name to the zone, the second is the GROUP object that defines the zone form.
PolyZone1 = ZONE_POLYGON:New( "PolyZone1", PolyZoneGroup1 )
PolyZone2 = ZONE_POLYGON:New( "PolyZone2", PolyZoneGroup2 )

-- Create a SET of Moose CLIENT wrapper objects. At mission startup, a SET of Moose client wrapper objects is created.
-- Note that CLIENT objects don't necessarily need to be alive!!! 
-- So this set contains EVERY RED coalition client defined within the mission.
RedClients = SET_CLIENT:New():FilterCoalitions("red"):FilterStart()



RedClients:ForEachClient( 
 function( MooseClient )
 
   -- Here we register the state of the client in which step he is in.
   -- We set the state of the client "ZoneStep" to 0, indicating that he is not out of the first zone.
   local function ResetClientForZone( MooseClient )
     BASE:E("Reset")
     MooseClient:SetState( MooseClient, "ZoneStep", "0" )
   end
   
   BASE:E( { "Alive Init", Client = MooseClient } )
   MooseClient:Alive( ResetClientForZone )
 end
)

Scheduler, SchedulerID = SCHEDULER:New( nil, 
 function ()
   
   RedClients:ForEachClientInZone( PolyZone1, 
     function( MooseClient )
       BASE:E( { Client = MooseClient, State = MooseClient:GetState( MooseClient, "ZoneStep" ) } )
       if MooseClient:GetState( MooseClient, "ZoneStep" ) == "0" then
         MooseClient:SetState( MooseClient, "ZoneStep", "1" )
         MESSAGE:New("Lorem Ipsum", 15, "Pilot Update" ):ToClient( MooseClient )
       end
     end
     )

   RedClients:ForEachClientNotInZone( PolyZone1, 
     function( MooseClient )
       BASE:E( { Client = MooseClient, State = MooseClient:GetState( MooseClient, "ZoneStep" ) } )
       if MooseClient:GetState( MooseClient, "ZoneStep" ) == "1" then
         MooseClient:SetState( MooseClient, "ZoneStep", "2" )
         MESSAGE:New("Ipsum Ipsum", 15, "Pilot Update" ):ToClient( MooseClient )
       end
     end
     )

   RedClients:ForEachClientInZone( PolyZone2, 
     function( MooseClient )
       BASE:E( { Client = MooseClient, State = MooseClient:GetState( MooseClient, "ZoneStep" ) } )
       if MooseClient:GetState( MooseClient, "ZoneStep" ) == "2" then
         MooseClient:SetState( MooseClient, "ZoneStep", "3" )
         MESSAGE:New("Lorem Lorem", 15, "Pilot Update" ):ToClient( MooseClient )
       end
     end
     )
   
 end, {}, 10, 1 
 )

 

You can download the mission file here https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/Release/ZON%20-%20Zones/ZON-510%20-%20Send%20message%20if%20Clients%20fly%20the%20first%20time%20in%20the%20Polygon%20Zones

 

It uses polygon zones, which are generalized zones, i.e. not just simple circles.

 

But you can replace them by normal trigger zones defined within the ME:

ZoneA=ZONE:New("Zone A")

where "Zone A" is the name of the trigger zone in the ME.

 

Note that the example is already a bit more complex. Because it takes care that a message is only send when the unit enters the zone the very first time. Maybe this is already what you want. Otherwise you can simplify the code a bit ;)

 

The number of clients is arbitrary btw. But you would need to include more zone similarly to what is already in the script.

 

Also the messages in the example are send only the the specific client. But there you can change it to something like Message:New("Message text",15):ToAll()

 

I must admit that I never really tested the mission myself. But it seems to be very close to what you want.

 

Hope it helps :)

A warrior's mission is to foster the success of others.

i9-12900K | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3

RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

Posted

Hi Yurgon

 

Thank you for your sharing.

I can read lua code but not good at it. the last time I use lua is write a wireshark parser for a private protocol.

 

Last 2 days I made 2 mistakes, and I couldn't even find those mistakes until last night. Finally the script is running perfectly

 

 

 

Hi funkyfranky,

 

 

I make a script based on the lua in the link. I have a new question now.

 

There are some static objects (fuel tanks), those tanks should be invisible or inactive when mission starts, When the condition is ture, I need to active those tanks, how?

 

The 3rd question is when the tank is destroyed, I need to know what kill it with which weapons.

 

There should be a function I can use, I am reading the Simulator Scripting Engine Documentation.

I7-6700K OC 4.9G, 896G SSD, 32G RAM @ 2400MHz, NH-D15 cooling system,TM Hotas Warthog,Saitek Pro Flight Rudder Pedals,TrackIr 5, BOSE M2

  • Recently Browsing   0 members

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