Forged Alliance Forever Forged Alliance Forever Forums 2018-04-10T16:50:33+02:00 /feed.php?f=53&t=16072 2018-04-10T16:50:33+02:00 2018-04-10T16:50:33+02:00 /viewtopic.php?t=16072&p=162523#p162523 <![CDATA[Re: BuffArea_1 doesn't work. what's wrong?]]>
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:
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:

Statistics: Posted by Ghoustaq — 10 Apr 2018, 16:50


]]>
2018-04-10T01:42:44+02:00 2018-04-10T01:42:44+02:00 /viewtopic.php?t=16072&p=162520#p162520 <![CDATA[Re: BuffArea_1 doesn't work. what's wrong?]]>
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:
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

Statistics: Posted by Uveso — 10 Apr 2018, 01:42


]]>
2018-04-09T17:53:57+02:00 2018-04-09T17:53:57+02:00 /viewtopic.php?t=16072&p=162511#p162511 <![CDATA[Re: BuffArea_1 doesn't work. what's wrong?]]>
I simplified my code, then all these buffareas works, although I gave up defining 'unitsA' and 'unitsB'.

I wonder why defining unitsA and unitsB or not will make such a distinct difference?

In my original method, I tried to make that if unitsA and unitsB belong to the same army, the mobile units in unitsA will gain HP, if not, they will lose HP.

Code:
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')

function OnPopulate()
    ScenarioUtils.InitializeArmies()   

   


local BuffAreaName
local location
local px, py, pz
local rect
local entities
local unitsA
local unitsB
local health
local preAdjHealth
local delta
local ArmyBrain

local self = import('/lua/sim/Entity.lua').Entity()

        for k = 1, 3 do
            BuffAreaName = 'BuffArea_' .. k
            location = ScenarioUtils.MarkerToPosition(BuffAreaName)           
            ForkThread(HealthAdjustor, self, location)

        end
end
HealthAdjustor = function(self, location)
    local px, py, pz = unpack(location)
    local rect = Rect(px-11, pz-11, px+11, pz+11)
    local entities
    while true do
        entities = GetUnitsInRect(rect)
        if entities ~= nil then
            for _, instigator in entities do
                if VDist3(instigator:GetPosition(), location) <= 8 then
                        health = instigator:GetHealth()
                        delta = health*0.05
                        instigator:AdjustHealth(instigator, -delta)
                else
                        instigator:AdjustHealth(instigator, delta)
                end
            end
        end

        WaitSeconds(10)
    end
end

function OnStart(self)
end

Statistics: Posted by Ghoustaq — 09 Apr 2018, 17:53


]]>
2018-04-08T20:08:37+02:00 2018-04-08T20:08:37+02:00 /viewtopic.php?t=16072&p=162503#p162503 <![CDATA[Re: BuffArea_1 doesn't work. what's wrong?]]>
Ghoustaq wrote:
@speed2

what does this mean?

Code:
WARNING: Error running OnRelease script in <deleted object>: ...liance\gamedata\lua.scd\lua\ui\game\construction.lua(832): Game object has been destroyed
         stack traceback:
            [C]: in function `SetAlpha'
            ...liance\gamedata\lua.scd\lua\ui\game\construction.lua(832): in function `OnRolloverEvent'
            ...d alliance\gamedata\mohodata.scd\lua\maui\button.lua(131): in function <...d alliance\gamedata\mohodata.scd\lua\maui\button.lua:122>


That's some error from the UI, specifically from the construction bar. Not related to the map script. Unless you're modding the UI, you don't need to care about it, nothing game breaking.

Statistics: Posted by speed2 — 08 Apr 2018, 20:08


]]>
2018-04-08T18:57:36+02:00 2018-04-08T18:57:36+02:00 /viewtopic.php?t=16072&p=162500#p162500 <![CDATA[Re: BuffArea_1 doesn't work. what's wrong?]]>
what does this mean?

Code:
WARNING: Error running OnRelease script in <deleted object>: ...liance\gamedata\lua.scd\lua\ui\game\construction.lua(832): Game object has been destroyed
         stack traceback:
            [C]: in function `SetAlpha'
            ...liance\gamedata\lua.scd\lua\ui\game\construction.lua(832): in function `OnRolloverEvent'
            ...d alliance\gamedata\mohodata.scd\lua\maui\button.lua(131): in function <...d alliance\gamedata\mohodata.scd\lua\maui\button.lua:122>

Statistics: Posted by Ghoustaq — 08 Apr 2018, 18:57


]]>
2018-04-07T08:52:51+02:00 2018-04-07T08:52:51+02:00 /viewtopic.php?t=16072&p=162456#p162456 <![CDATA[Re: BuffArea_2 doesn't work. what's wrong?]]>
Ghoustaq wrote:
Uveso wrote:Hello Ghoustaq,

got this error:
Code:
WARNING: Error running lua script: ...data\faforever\repo\fa\lua\sim\scenarioutilities.lua(101): ERROR: Invalid marker name- BuffArea_1


I can't check the function without the map / mapmarker.


yes, it seems only the last buffarea works no matter how many buffareas exist on the map.

So I cleaned the indentation to make it more readable and this is the result: (no code was changed, just white space) https://pastebin.com/t6sjjxsT

The reason why only the last area works should be visible now. You loop through the 3 areas to set the locals, and after that loop you work with them.
By the end of the for k = 1, 3 do loop, only the last variables are saved.

Statistics: Posted by speed2 — 07 Apr 2018, 08:52


]]>
2018-04-07T08:27:03+02:00 2018-04-07T08:27:03+02:00 /viewtopic.php?t=16072&p=162455#p162455 <![CDATA[Re: BuffArea_1 doesn't work. what's wrong?]]>
Here is my map.Please check it when you are free. ;) BUFFAREA_TEST1.rar

Statistics: Posted by Ghoustaq — 07 Apr 2018, 08:27


]]>
2018-04-06T15:40:46+02:00 2018-04-06T15:40:46+02:00 /viewtopic.php?t=16072&p=162438#p162438 <![CDATA[Re: BuffArea_2 doesn't work. what's wrong?]]>
Ghoustaq wrote:
yes, it seems only the last buffarea works no matter how many buffareas exist on the map.


no :)

Markers are just stored in a simple table/array.
Maybe you messed up the array index or something else.

This should/can work.

If you like, zip the actual map and post or upload it.
Let me play around with it.
I am sure it's just a typo or something like that.

[Edit] But not today! I will play the whole night Mechwarrior online :D

Statistics: Posted by Uveso — 06 Apr 2018, 15:40


]]>
2018-04-06T15:00:35+02:00 2018-04-06T15:00:35+02:00 /viewtopic.php?t=16072&p=162437#p162437 <![CDATA[Re: BuffArea_2 doesn't work. what's wrong?]]>
Uveso wrote:
Hello Ghoustaq,

got this error:
Code:
WARNING: Error running lua script: ...data\faforever\repo\fa\lua\sim\scenarioutilities.lua(101): ERROR: Invalid marker name- BuffArea_1


I can't check the function without the map / mapmarker.


yes, it seems only the last buffarea works no matter how many buffareas exist on the map.

Statistics: Posted by Ghoustaq — 06 Apr 2018, 15:00


]]>
2018-04-06T00:43:59+02:00 2018-04-06T00:43:59+02:00 /viewtopic.php?t=16072&p=162423#p162423 <![CDATA[Re: BuffArea_2 doesn't work. what's wrong?]]>
got this error:
Code:
WARNING: Error running lua script: ...data\faforever\repo\fa\lua\sim\scenarioutilities.lua(101): ERROR: Invalid marker name- BuffArea_1


I can't check the function without the map / mapmarker.

Statistics: Posted by Uveso — 06 Apr 2018, 00:43


]]>
2018-04-06T14:41:12+02:00 2018-04-05T19:58:52+02:00 /viewtopic.php?t=16072&p=162418#p162418 <![CDATA[BuffArea_1 doesn't work. what's wrong?]]>
The problem is why Buffarea_2 works and BuffArea_1 doesn't work

Here is my script code.

Code:
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')

function OnPopulate()
   ScenarioUtils.InitializeArmies()   
end

function OnStart(self)

   ForkThread(HealthAdjustor)
end

   local BuffAreaName
   local location
   local px, py, pz
   local rect
   local entities
   local unitsA
   local unitsB
   local health
   local preAdjHealth
   local delta
   local ArmyBrain
function HealthAdjustor(self)
    while true do
      for k = 1, 2 do
        BuffAreaName = 'BuffArea_' .. k
        location = ScenarioUtils.MarkerToPosition(BuffAreaName)
        px, py, pz = unpack(location)
        rect = Rect(px-11, pz-11, px+11, pz+11)
        entities = GetUnitsInRect(rect)
          if entities then
           unitsA = EntityCategoryFilterDown(categories.MOBILE, entities)
           unitsB = EntityCategoryFilterDown(categories.HYDROCARBON + categories.MASSEXTRACTION, entities)
          end
      end

      if unitsB ~= nil then
         if table.getn(unitsB) >= 1 then
            for _, supplier in unitsB do
            ArmyBrain = supplier:GetAIBrain()
                   end
            end
            for _, instigator in unitsA do
                if VDist3(instigator:GetPosition(), location) <= 8 then
                    if instigator:GetAIBrain()~= ArmyBrain then
                       health = instigator:GetHealth()
                       delta = health*0.05
                       instigator:AdjustHealth(instigator, -delta)
                    else
                       instigator:AdjustHealth(instigator, delta)
                    end
                end
            end
         end

        WaitSeconds(10)
    end
end

Statistics: Posted by Ghoustaq — 05 Apr 2018, 19:58


]]>