Darkreaver1980 Posted December 26, 2017 Posted December 26, 2017 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.
Chump Posted December 26, 2017 Posted December 26, 2017 (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 December 27, 2017 by Chump
Darkreaver1980 Posted December 26, 2017 Author Posted December 26, 2017 Thanks alot! i pasted your code into a action "Run script" and it gave me an error:
Darkreaver1980 Posted December 27, 2017 Author Posted December 27, 2017 (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 December 27, 2017 by Darkreaver1980
cobragva Posted December 27, 2017 Posted December 27, 2017 great script. Would it be possible to have the same but adding a zone as an additional condition (ie: number to unit destroyed in X zone) tks best
Chump Posted December 27, 2017 Posted December 27, 2017 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()
Recommended Posts