BuffArea_1 doesn't work. what's wrong?

Interesting mapping tools and mapping help.

Moderator: Morax

Re: BuffArea_1 doesn't work. what's wrong?

Postby Ghoustaq » 10 Apr 2018, 16:50

Uveso wrote:Hello Ghoustaq,

you problem was simply to execute the 2nd code block after the 1st block looped over all 3 locations.
The 2nd block needs to be called every "for k = 1, 3 do", not after it.

I optimized the code and removed unneeded locals.
Also added some failchecks in case the triggerunit is destroyed.

Copy & paste ready script:
Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')

function OnPopulate()
    ScenarioUtils.InitializeArmies()   
    ForkThread(HealthAdjustor)
end

function HealthAdjustor(self)
    local location
    local entities
    local unitsA
    local unitsB
    local health
    local delta
    local ArmyBrain
    while true do
        for k = 1, 3 do
            location = ScenarioUtils.MarkerToPosition('BuffArea_' .. k)
            entities = GetUnitsInRect( Rect(location[1]-11, location[3]-11, location[1]+11, location[3]+11) )
            if entities then
                unitsA = EntityCategoryFilterDown(categories.MOBILE, entities)
                unitsB = EntityCategoryFilterDown(categories.HYDROCARBON + categories.MASSEXTRACTION, entities)
            end
            if unitsB then
                -- check first if the trigger unit is still present
                if unitsB[1] and not unitsB[1].Dead and not unitsB[1]:BeenDestroyed() then
                    ArmyBrain = unitsB[1]:GetAIBrain() -- unitsB[1] is the first unit inside the unitsB table
                    for _, instigator in unitsA do
                        if VDist3(instigator:GetPosition(), location) <= 8 then
                            health = instigator:GetHealth()
                            delta = health*0.05
                            if instigator:GetAIBrain()~= ArmyBrain then
                                instigator:AdjustHealth(instigator, -delta)
                            else
                                instigator:AdjustHealth(instigator, delta)
                            end
                        end
                    end
                end
            end
        end
        WaitTicks(10) -- waits 1 second. Can be reduced to 1 tick if needed
   end
end


@Uveso
Thank you indeed! :) You did a great job :D After solving this problem, I can go on mapping now :lol:
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Previous

Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest