Forged Alliance Forever Forged Alliance Forever Forums 2018-03-20T18:33:50+02:00 /feed.php?f=53&t=16007 2018-03-20T18:33:50+02:00 2018-03-20T18:33:50+02:00 /viewtopic.php?t=16007&p=161875#p161875 <![CDATA[Re: What is the right command to make a unit damage itself?]]>
You can specify unit categories (from bp.Categories in unit blueprints) :

Code:
local units = unit:GetAIBrain():GetUnitsAroundPoint(categories.COMMAND + categories.SUBCOMMANDER, unit:GetPosition(), 25, 'Enemy')
for _, instigator in units do
   instigator:AdjustHealth(instigator, -30)
end

Statistics: Posted by Franck83 — 20 Mar 2018, 18:33


]]>
2018-03-20T17:55:20+02:00 2018-03-20T17:55:20+02:00 /viewtopic.php?t=16007&p=161872#p161872 <![CDATA[Re: What is the right command to make a unit damage itself?]]>
Franck83 wrote:
@speed2 I deleted the line 58, then no error is reported, but no damage happens still. I feel so confused :?


in Unit.lua, i'm using this method that impact directly the health. Give it a try.

Code:
instigator:AdjustHealth(instigator, - DamageAmount)



Great! :lol: this command does work! Thanks for your help!

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 DAMAGEAREAName
   local location
   local px, py, pz
   local rect
   local units
   local health
   local preAdjHealth

function HealthAdjustor(self)
    while true do
      for k = 1, 1 do
        DAMAGEAREAName = 'DAMAGEAREA_' .. k
        location = ScenarioUtils.MarkerToPosition(DAMAGEAREAName)
        px, py, pz = unpack(location)
        rect = Rect(px-25, pz-25, px+25, pz+25)
        units = GetUnitsInRect(rect)
      end
      for _, instigator in units do
        if VDist3(instigator:GetPosition(), location) <= 25 then
        health = instigator:GetHealth()
        instigator:AdjustHealth(instigator, -30)
        end
      end

        WaitSeconds(10)
    end
end

Statistics: Posted by Ghoustaq — 20 Mar 2018, 17:55


]]>
2018-03-19T23:20:51+02:00 2018-03-19T23:20:51+02:00 /viewtopic.php?t=16007&p=161854#p161854 <![CDATA[Re: What is the right command to make a unit damage itself?]]>

@speed2 I deleted the line 58, then no error is reported, but no damage happens still. I feel so confused :?


in Unit.lua, i'm using this method that impact directly the health. Give it a try.

Code:
instigator:AdjustHealth(instigator, - DamageAmount)

Statistics: Posted by Franck83 — 19 Mar 2018, 23:20


]]>
2018-03-19T19:36:13+02:00 2018-03-19T19:36:13+02:00 /viewtopic.php?t=16007&p=161851#p161851 <![CDATA[Re: What is the right command to make a unit damage itself?]]>
also scatis and trebuchet do minor damage to themself (1-5 dmg per shot or so)

maybe napalm units can burn themself as well... ( but i could not do it so i don't remember)

Edit: also billy nuke

Statistics: Posted by ZLO_RD — 19 Mar 2018, 19:36


]]>
2018-03-19T19:16:29+02:00 2018-03-19T19:16:29+02:00 /viewtopic.php?t=16007&p=161849#p161849 <![CDATA[Re: What is the right command to make a unit damage itself?]]>

Statistics: Posted by Ghoustaq — 19 Mar 2018, 19:16


]]>
2018-03-19T19:00:02+02:00 2018-03-19T19:00:02+02:00 /viewtopic.php?t=16007&p=161847#p161847 <![CDATA[Re: What is the right command to make a unit damage itself?]]>
Thank you, I have defined "location" now. but the new error comes.


WARNING: Error running lua script: ...reme commander forged alliance\maps\11\11_script.lua(27): stack overflow
stack traceback:
...reme commander forged alliance\maps\11\11_script.lua(27): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function `Damage'
...reme commander forged alliance\maps\11\11_script.lua(58): in function <...reme commander forged alliance\maps\11\11_script.lua:25>


What does it mean?

line 25: Damage = function(instigator, location, target, amount, damageType)
line 27: local px, py, pz = unpack(location)
line 58: Damage(instigator, location, 25, 1, 'Force', false, false)


the whole codes here

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

function OnPopulate()
   ScenarioUtils.InitializeArmies()





local self = import('/lua/sim/Entity.lua').Entity()
   for k = 1, 1 do
    local DAMAGEAREAName = 'DAMAGEAREA_' .. k
    local location = ScenarioUtils.MarkerToPosition(DAMAGEAREAName)



 
      ForkThread(Damage, self, location)
      end
end



Damage = function(instigator, location, target, amount, damageType)

    local px, py, pz = unpack(location)
    local army = ListArmies()
    local amount = 30
    local damageAllies = true
    local damageSelf = true
    local damageType = 'Reclaimed'
    local rect = Rect(px-25, pz-25, px+25, pz+25)
    local units = GetUnitsInRect(rect) or {}
    for _, u in units do
        if VDist3(u:GetPosition(), location) <= 25 then
           continue
        end
        if instigator == u then
            if damageSelf then
                local vector = import('/lua/utilities.lua').GetDirectionVector(location, u:GetPosition())
                -- need this ugliness due to Damage() refuse to damage when instigator == u
                instigator:Damage(instigator, u, 30, vector, 'Reclaimed')
            end
        elseif damageAllies or not IsAlly(army, u:GetArmy()) then
            instigator:Damage(instigator, u, 30, 'Reclaimed')
        end
    end

    local reclaim = GetReclaimablesInRect(rect) or {}
    for _, r in reclaim do
        if IsProp(r) and VDist3(r:GetPosition(), location) <= 25 then
            Damage(instigator, location, r, 30, 'Reclaimed')
        end
    end

     -- Get rid of trees
     Damage(instigator, location, 25, 1, 'Force', false, false)
end

function OnStart(self)
end

Statistics: Posted by Ghoustaq — 19 Mar 2018, 19:00


]]>
2018-03-18T22:49:08+02:00 2018-03-18T22:49:08+02:00 /viewtopic.php?t=16007&p=161826#p161826 <![CDATA[Re: What is the right command to make a unit damage itself?]]>
Ghoustaq wrote:
Damage(instigator, target, amount, damageType) ?

or

Entity:Kill(instigator,type,excessDamageRatio)?


I am not clear about the exact effects of these two commands.

The below is my case to use "Damage" command in a mapscript. Of course, it's not work yet. I mean no damage happens. :?

Does anybody can fix it? I will be thankful :)

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

function OnPopulate()
   ScenarioUtils.InitializeArmies()
   ScenarioFramework.SetPlayableArea('AREA_1', false)



local oldDamageArea = DamageArea

local self = import('/lua/sim/Entity.lua').Entity()
   for k = 1, 1 do
      local DAMAGEAREAName = 'DAMAGEAREA_' .. k
      local location = ScenarioUtils.MarkerToPosition(DAMAGEAREAName)
           
      ForkThread(Damage, self)
      end
end



Damage = function(instigator, target, amount, damageType)
    local px, py, pz = unpack(location)
    local army = ListArmies()
    local rect = Rect(px-radius, pz-radius, px+radius, pz+radius)
    local units = GetUnitsInRect(rect) or {}
    local amount = 30
    local damageAllies = true
    local damageSelf = true
    local radius = 25
    local damageType = 'Reclaimed'
    local target = units
    for _, u in units do
        if VDist3(u:GetPosition(), location) <= radius then
           continue
        end
        if instigator == u then
            if damageSelf then
                local vector = import('/lua/utilities.lua').GetDirectionVector(location, u:GetPosition())
                -- need this ugliness due to Damage() refuse to damage when instigator == u
                instigator:Damage(instigator, u, 30, vector, 'Reclaimed')
            end
        elseif damageAllies or not IsAlly(army, u:GetArmy()) then
            instigator:Damage(instigator, u, 30, 'Reclaimed')
        end
    end

    local reclaim = GetReclaimablesInRect(rect) or {}
    for _, r in reclaim do
        if IsProp(r) and VDist3(r:GetPosition(), location) <= radius then
            Damage(instigator, location, r, 30, 'Reclaimed')
        end
    end

     -- Get rid of trees
     oldDamageArea(instigator, location, radius, 1, 'Reclaimed', false, false)
    end


function OnStart(self)
end


And the error reported in the Moho log

    WARNING: Error running lua script: ...reme commander forged alliance\maps\11\11_script.lua(24): access to nonexistent global variable "location"
    stack traceback:
    [C]: in function `error'
    ...alliance\gamedata\mohodata.scd\lua\system\config.lua(53): in function <...alliance\gamedata\mohodata.scd\lua\system\config.lua:52>
    ...reme commander forged alliance\maps\11\11_script.lua(24): in function <...reme commander forged alliance\maps\11\11_script.lua:23>


Well the error says that on line 24 you're trying to use variable that doesnt exist (location). You dont have it defined in that function.

Else Damage(instigator, target, amount, damageType) should damage the unit, what's not clear about it?
Kill will damage it as well but well... kill it in the process, do kinda fatal damage.

Statistics: Posted by speed2 — 18 Mar 2018, 22:49


]]>
2018-03-19T11:29:15+02:00 2018-03-18T20:23:55+02:00 /viewtopic.php?t=16007&p=161819#p161819 <![CDATA[What is the right command to make a unit damage itself?]]>
or

Entity:Kill(instigator,type,excessDamageRatio)?


I am not clear about the exact effects of these two commands.

The below is my case to use "Damage" command in a mapscript. Of course, it's not work yet. I mean no damage happens. :?

Can anybody fix it? I will be thankful :)

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

function OnPopulate()
   ScenarioUtils.InitializeArmies()
   ScenarioFramework.SetPlayableArea('AREA_1', false)



local oldDamageArea = DamageArea

local self = import('/lua/sim/Entity.lua').Entity()
   for k = 1, 1 do
      local DAMAGEAREAName = 'DAMAGEAREA_' .. k
      local location = ScenarioUtils.MarkerToPosition(DAMAGEAREAName)
           
      ForkThread(Damage, self)
      end
end



Damage = function(instigator, target, amount, damageType)
    local px, py, pz = unpack(location)
    local army = ListArmies()
    local rect = Rect(px-radius, pz-radius, px+radius, pz+radius)
    local units = GetUnitsInRect(rect) or {}
    local amount = 30
    local damageAllies = true
    local damageSelf = true
    local radius = 25
    local damageType = 'Reclaimed'
    local target = units
    for _, u in units do
        if VDist3(u:GetPosition(), location) <= radius then
           continue
        end
        if instigator == u then
            if damageSelf then
                local vector = import('/lua/utilities.lua').GetDirectionVector(location, u:GetPosition())
                -- need this ugliness due to Damage() refuse to damage when instigator == u
                instigator:Damage(instigator, u, 30, vector, 'Reclaimed')
            end
        elseif damageAllies or not IsAlly(army, u:GetArmy()) then
            instigator:Damage(instigator, u, 30, 'Reclaimed')
        end
    end

    local reclaim = GetReclaimablesInRect(rect) or {}
    for _, r in reclaim do
        if IsProp(r) and VDist3(r:GetPosition(), location) <= radius then
            Damage(instigator, location, r, 30, 'Reclaimed')
        end
    end

     -- Get rid of trees
     oldDamageArea(instigator, location, radius, 1, 'Reclaimed', false, false)
    end


function OnStart(self)
end


And the error reported in the Moho log

    WARNING: Error running lua script: ...reme commander forged alliance\maps\11\11_script.lua(24): access to nonexistent global variable "location"
    stack traceback:
    [C]: in function `error'
    ...alliance\gamedata\mohodata.scd\lua\system\config.lua(53): in function <...alliance\gamedata\mohodata.scd\lua\system\config.lua:52>
    ...reme commander forged alliance\maps\11\11_script.lua(24): in function <...reme commander forged alliance\maps\11\11_script.lua:23>

Statistics: Posted by Ghoustaq — 18 Mar 2018, 20:23


]]>