Jump to content

Recommended Posts

Posted (edited)

Fellow Lua Gods,

 

Respectfully request some assistance or help with a script I would like to use in my mission. This script would check a table of trigger zones that enemy targets exist and report to the member whether or not the area is Clear or if enemy's still exist. Im not looking for a number, just a "Area Clear" or "Area Unsecured". I cannot use the Transport scipt (CTTS.lua) for the countextracted() function because I am already using a different transport script. I am trying to get something similar to the HueyDrop Mission Status Report. Ive tried picking different functions from that mission and Im getting no where with it. Here is they script I am sampling from but all I get from all the zones that the area is clear. Any help would be greatly appreciated.

DropoffZones = {
   [1] = {
       Name = "Krasnodar-Center Airfield",
       ZoneName = "Airfield",
   },
   [2] = {
       Name = "City Headquarters",
       ZoneName = "City headquarters",
   },
   [3] = {
       Name = "Barracks",
       ZoneName = "Barracks",
   },
   [4] = {
       Name = "West Bridge",
       ZoneName = "Bridge 1",
   },
   [5] = {
       Name = "South Bridge",
       ZoneName = "Bridge 2",
   },
   [6] = {
       Name = "East Bridge",
       ZoneName = "Bridge 3",
   },
}
function FindNearestDropoffZone(unit, maxDistance)
   local minDist = maxDistance
   local minZone = nil
   local unitpos = unit:getPoint()

   for i=1,#DropoffZones do
       local zone = DropoffZones[i]
       local triggerZone = trigger.misc.getZone(zone.ZoneName)
       local dist = GetDistance(unitpos.x, unitpos.z, triggerZone.point.x, triggerZone.point.z)
       if dist < minDist then
           minDist = dist
           minZone = zone
       end
   end

   return minZone    
end
function StatusReport(arg, time)
   -- array of Group function coalition.getGroups(enum coalition.side coalition, enum Group.Category groupCategory or nil)
   -- array of Unit function Group.getUnits(Group self)
   -- enum country.id CoalitionObject.getCountry(CoalitionObject self)
   local zoneTable = {}
   local zoneFriendly = {}
   for i=1,#DropoffZones do
       zoneTable[DropoffZones[i].Name] = 0
       zoneFriendly[DropoffZones[i].Name] = 0
   end
   local groups = coalition.getGroups(coalition.side.RED, Group.Category.GROUND)
   for i=1,#groups do
       local group = groups[i]
       if group ~= nil then
           local units = group:getUnits()
           for j=1,#units do
               local unit = units[j]
               if unit ~= nil then
                   local country = unit:getCountry()
                   if country == 0 then       -- if RUSSIAN
                      local zone = FindNearestDropoffZone(unit, 5000)
                       if zone ~= nil then
                           zoneTable[zone.Name] = zoneTable[zone.Name] + 1
                       end
                   end
               end
           end
       end
   end

   local groups = coalition.getGroups(coalition.side.BLUE, Group.Category.GROUND)
   for i=1,#groups do
       local group = groups[i]
       if group ~= nil then
           local units = group:getUnits()
           for j=1,#units do
               local unit = units[j]
               if unit ~= nil then
                   local country = unit:getCountry()
                   if zone == 2 then --USA
                       local zone = FindNearestDropoffZone(unit, 5000)
                       if zone ~= nil then
                           zoneFriendly[zone.Name] = zoneFriendly[zone.Name] + 1
                       end
                   end
               end
           end
       end
   end
   local text = "MISSION STATUS  -  See mission briefing for details\n\n"
   for k,v in pairs(zoneTable) do
       if v > 0 then
           text = text .. tostring(k) .. ": " .. tostring(v) .. " Area unsecured.\n"
       else
           if zoneFriendly[k] > 0 then
               text = text .. tostring(k) .. ": Area cleared!\n"
           end
       end
   end


   trigger.action.outText(text, 20)

   return time + 45
end

do
   timer.scheduleFunction(StatusReport, nil, timer.getTime() + 45)
end
function UnitInZone(unit, zone)
   if unit:inAir() then
       return false
   end

   local triggerZone = trigger.misc.getZone(zone.ZoneName)
   local group = unit:getGroup()
   local groupid = group:getID()
   local unitpos = unit:getPoint()
   local xDiff = unitpos.x - triggerZone.point.x
   local yDiff = unitpos.z - triggerZone.point.z
   local dist = math.sqrt(xDiff * xDiff + yDiff * yDiff)

   if dist > triggerZone.radius then
       return false
   end

   return true
end

 

-Xillinx

Edited by Xillinx

[sIGPIC][/sIGPIC]

 

http://1stcavdiv.conceptbb.com/

Posted (edited)

So if I can ask one of my traditionally simple questions- I went to the wiki to see if there was a bit more elaboration on how such information can be used... but it's pretty basic. Tells you how to apply the function- which is the important part. What I'm wondering is how can I put this to use...

 

It creates a table of units that are within the zones... and I can imagine this would be helpful when people join a mission to announce what targets remain...

 

How do I broadcast this info at intervals of... say... every 30 minutes?

Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Posted
So if I can ask one of my traditionally simple questions- I went to the

How do I broadcast this info at intervals of... say... every 30 minutes?

 

Time schedule a recursive function. E.g.

 

function dummy()

... do something ...

delay = timer.getTime + 1800

timer.scheduleFunction(dummy,delay)

end

[sIGPIC]OK[/sIGPIC]

  • Recently Browsing   0 members

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