Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function ctld.countDroppedUnitsInZone does not count properly #121

Open
475fgdawger opened this issue Dec 13, 2024 · 1 comment
Open

function ctld.countDroppedUnitsInZone does not count properly #121

475fgdawger opened this issue Dec 13, 2024 · 1 comment
Assignees
Labels

Comments

@475fgdawger
Copy link

function ctld.countDroppedUnitsInZone does not count properly.

Dropping 8 troops resulted in a count of 72 (factor of 9)

Dropping 24 troops resulted in a count of 600 (factor of 25)

@475fgdawger
Copy link
Author

475fgdawger commented Dec 13, 2024

-- Use: ctld.countDroppedUnitsInZone("Zone Name", flagBlue, flagRed)
 function ctld.countDroppedUnitsInZone(_zone, _blueFlag, _redFlag)
     local _triggerZone = trigger.misc.getZone(_zone) -- trigger to use as reference position
 
     if _triggerZone == nil then
         trigger.action.outText("CTLD.lua ERROR: Cant find zone called " .. _zone, 10)
         return
     end
 
     local _zonePos = mist.utils.zoneToVec3(_zone)
 
     local _redCount = 0;
     local _blueCount = 0;
 
     local _allGroups = { ctld.droppedTroopsRED, ctld.droppedTroopsBLUE, ctld.droppedVehiclesRED, ctld
         .droppedVehiclesBLUE }
 
     for _, _extractGroups in pairs(_allGroups) do
         for _, _groupName in pairs(_extractGroups) do
             local _groupUnits = ctld.getGroup(_groupName)
 
             if #_groupUnits > 0 then
                 local _zonePos = mist.utils.zoneToVec3(_zone)
                 for _, _unit in pairs(_groupUnits) do
                     local _dist = ctld.getDistance(_unit:getPoint(), _zonePos)
 
                     if _dist <= _triggerZone.radius then
                         if (_unit:getCoalition() == 1) then
                             _redCount = _redCount + 1;
                         else
                             _blueCount = _blueCount + 1;
                         end
                     end
                 end
             end
         end
     end
 
 
     --set flag stuff
     trigger.action.setUserFlag(_blueFlag, _blueCount)
     trigger.action.setUserFlag(_redFlag, _redCount)
 
     --  env.info("Units in zone ".._blueCount.." ".._redCount)
 end

@davidp57 davidp57 self-assigned this Dec 17, 2024
@davidp57 davidp57 added the bug label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants