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 Ghoustaq — 10 Apr 2018, 16:50
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
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
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 speed2 — 08 Apr 2018, 20:08
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
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.
Statistics: Posted by speed2 — 07 Apr 2018, 08:52
Statistics: Posted by Ghoustaq — 07 Apr 2018, 08:27
Statistics: Posted by Uveso — 06 Apr 2018, 15:40
WARNING: Error running lua script: ...data\faforever\repo\fa\lua\sim\scenarioutilities.lua(101): ERROR: Invalid marker name- BuffArea_1
Statistics: Posted by Ghoustaq — 06 Apr 2018, 15:00
WARNING: Error running lua script: ...data\faforever\repo\fa\lua\sim\scenarioutilities.lua(101): ERROR: Invalid marker name- BuffArea_1
Statistics: Posted by Uveso — 06 Apr 2018, 00:43
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