Jump to content

Recommended Posts

Posted

Hi there,

 

is it possible to have a script that counts all units from a faction (red) and displays to all players following message?:

 

"X units destroyed. X enemy units remaining"

 

It should be displayed all 5 minutes.

Posted (edited)
function getCount()
   local count = 0
   for _, group in pairs(coalition.getGroups(coalition.side.RED)) do
       for _, unit in pairs(group:getUnits()) do
           if unit:isActive() and unit:getLife() >= 1 then
               count = count + 1
           end
       end
   end
   return count
end
function showCounts()
   local remaining = getCount()
   local destroyed = start - remaining
   trigger.action.outText(string.format("%i units destroyed. %i units remaining.", destroyed, remaining), 10, true)
   if remaining > 0 then
       timer.scheduleFunction(showCounts, {}, timer.getTime() + 300)
   end
end
start = getCount()
showCounts()

This will show all players the count of red units in the game every five minutes.

Edited by Chump
Posted (edited)

Hello Chump,

 

thank you alot again.

 

I have put it into a once trigger on mission start and i get the following result:

 

-2 units destroyed. 250 units remaining.

 

The counter itself is working. i destroyed 3 units and it was at 1 units destroyed. 247 units remaining.

 

Edit:

 

i fixed it. I delayed the starting point of the script for several seconds and now it shows the right amount.

 

Thanks again :)

Edited by Darkreaver1980
Posted
Would it be possible to have the same but adding a zone as an additional condition

(ie: number to unit destroyed in X zone)

 

The easiest way I know of is to use MiST (https://forums.eagle.ru/showthread.php?t=98616). Try this (displays number of red units in countZone):

assert(mist ~= nil, "MiST must be loaded prior to execution of this script!")
function getCount()
   return #mist.getUnitsInZones(mist.makeUnitTable({"[red]"}), {"countZone"})
end
function showCounts()
   local remaining = getCount()
   local destroyed = start - remaining
   trigger.action.outText(string.format("%i units destroyed. %i units remaining.", destroyed, remaining), 10, true)
   if remaining > 0 then
       timer.scheduleFunction(showCounts, {}, timer.getTime() + 300)
   end
end
start = getCount()
showCounts()

  • Recently Browsing   0 members

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