• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts onHealthChange

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
I have some problems when the player is using imbu the damage that is reflected in the boss he is receiving the damage + the healing of the imbu

: attempt to index local 'attacker' (a nil value

and I'm getting this error in the log


edit
if the player is attacking the boss and uses exura vita for example the cure is sent to the boss

Lua:
local config = {
    {
   bossName = "The Pale Worm",
   bossPosition = Position(33805, 31505, 14)
    }
}

local function doCombat(creature, boss, combatType, damage)
    doTargetCombatHealth(creature, boss, combatType, -damage, -damage, CONST_ME_NONE, ORIGIN_SPELL)

end

local ThePaleWormReceiveDmg1 = CreatureEvent("ThePaleWormReceiveDmg")

function ThePaleWormReceiveDmg1.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)


    for _, info in pairs(config) do
        local foundBoss = Monster(info.foundBoss)
        if foundBoss then
            doCombat(attacker:getId(), foundBoss, primaryType, primaryDamage)
            doCombat(attacker:getId(), foundBoss, secondaryType, secondaryDamage)
           
        else
            local spectators =
             Game.getSpectators(info.bossPosition, false, false, 14, 14, 14, 14)
           
            for __, spectator in pairs(spectators) do
                if spectator ~= creature then
                    if spectator:getName() == info.bossName then
                             
                        doCombat(attacker:getId(), spectator, primaryType, primaryDamage)
                        doCombat(attacker:getId(), spectator, secondaryType, secondaryDamage)
                       
                        info.foundBoss = spectator:getId()
                        break
                    end

                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
ThePaleWormReceiveDmg1:register()
 
Last edited:

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,243
Solutions
71
Reaction score
570
Location
Hell
Lua:
local config = {
    {
        bossName = "The Pale Worm",
        bossPosition = Position(33805, 31505, 14)
    }
}

local function doCombat(creature, boss, combatType, damage)
    doTargetCombatHealth(creature, boss, combatType, -damage, -damage, CONST_ME_NONE, ORIGIN_SPELL)
end

local ThePaleWormReceiveDmg1 = CreatureEvent("ThePaleWormReceiveDmg")
function ThePaleWormReceiveDmg1.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    
    for _, info in pairs(config) do
        local foundBoss = Monster(info.foundBoss)
        if foundBoss then
            doCombat(attacker:getId(), foundBoss, primaryType, primaryDamage)
            doCombat(attacker:getId(), foundBoss, secondaryType, secondaryDamage)
        else
            local spectators = Game.getSpectators(info.bossPosition, false, false, 14, 14, 14, 14)
            for __, spectator in pairs(spectators) do
                if spectator ~= creature then
                    if spectator:getName() == info.bossName then
                        doCombat(attacker:getId(), spectator, primaryType, primaryDamage)
                        doCombat(attacker:getId(), spectator, secondaryType, secondaryDamage)
                        info.foundBoss = spectator:getId()
                        break
                    end
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

ThePaleWormReceiveDmg1:register()
 
OP
OP
A

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
Lua:
local config = {
    {
        bossName = "The Pale Worm",
        bossPosition = Position(33805, 31505, 14)
    }
}

local function doCombat(creature, boss, combatType, damage)
    doTargetCombatHealth(creature, boss, combatType, -damage, -damage, CONST_ME_NONE, ORIGIN_SPELL)
end

local ThePaleWormReceiveDmg1 = CreatureEvent("ThePaleWormReceiveDmg")
function ThePaleWormReceiveDmg1.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
  
    for _, info in pairs(config) do
        local foundBoss = Monster(info.foundBoss)
        if foundBoss then
            doCombat(attacker:getId(), foundBoss, primaryType, primaryDamage)
            doCombat(attacker:getId(), foundBoss, secondaryType, secondaryDamage)
        else
            local spectators = Game.getSpectators(info.bossPosition, false, false, 14, 14, 14, 14)
            for __, spectator in pairs(spectators) do
                if spectator ~= creature then
                    if spectator:getName() == info.bossName then
                        doCombat(attacker:getId(), spectator, primaryType, primaryDamage)
                        doCombat(attacker:getId(), spectator, secondaryType, secondaryDamage)
                        info.foundBoss = spectator:getId()
                        break
                    end
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

ThePaleWormReceiveDmg1:register()
Hello, I didn't have the error on the console anymore.
Could you ask me a question using an elemental weapon?
Only the physical damage is reflected. The elemental damage is not sure what you could do?
 
Last edited:
OP
OP
A

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
Forgive my ignorance for I am unable to decode the language of gods.
What are you saying lord capone? xD
player is using the soulcrusher item only 'physical' damage is taken elemental damage the boss is not taking

edit--
@Snavy

456 damage ok
511 damage elemental no ok
imagem_2021-02-16_153120.png
 
Last edited:

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,243
Solutions
71
Reaction score
570
Location
Hell
I don't understand what you are saying.

player is using the soulcrusher item only 'physical' damage is taken elemental damage the boss is not taking
Is the weapon supposed to deal "elemental damage" addition to the physical damage to the boss you are attacking?

The picture you sent; Which one is boss, which one is player?


Skärmavbild 2021-02-17 kl. 16.54.44.png
 
OP
OP
A

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
I don't understand what you are saying.


Is the weapon supposed to deal "elemental damage" addition to the physical damage to the boss you are attacking?

The picture you sent; Which one is boss, which one is player?
I'm not making a mess kk looking at my code the boss has 'ThePaleWormReceiveDmg' all damage from the monster that is suffering from this event will be reflected in the boss that is in the 'bossName' the problem is that the damage caused by weapons that have an element is not reflecting properly. same as in the example photo mob is attacked and the reflected damage is only physical
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,035
Solutions
102
Reaction score
1,086
Location
London
GitHub
MillhioreBT
;)
Lua:
local config = {
    {
   bossName = "Test Monk",
   bossPosition = Position(33805, 31505, 14)
    }
}

local function doCombat(creature, boss, combatType, damage)
    doTargetCombatHealth(creature, boss, combatType, -damage, -damage, CONST_ME_NONE, ORIGIN_SPELL)
end

local ThePaleWormReceiveDmg1 = CreatureEvent("ThePaleWormReceiveDmg")
function ThePaleWormReceiveDmg1.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    for _, info in pairs(config) do
        local foundBoss = Monster(info.foundBoss)
        if foundBoss then
            doCombat(attacker:getId(), foundBoss, primaryType, primaryDamage)
            doCombat(attacker:getId(), foundBoss, secondaryType, secondaryDamage)
        else
            local spectators = Game.getSpectators(creature:getPosition(), false, false, 14, 14, 14, 14)
            for __, spectator in pairs(spectators) do
                if spectator ~= creature then
                    if spectator:getName() == info.bossName then
                        doCombat(attacker:getId(), spectator, primaryType, primaryDamage)
                        doCombat(attacker:getId(), spectator, secondaryType, secondaryDamage)
                        info.foundBoss = spectator
                        break
                    end

                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
ThePaleWormReceiveDmg1:register()
GIF 17-02-2021 06-41-40 p. m..gif
 
OP
OP
A

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
;)
Lua:
local config = {
    {
   bossName = "Test Monk",
   bossPosition = Position(33805, 31505, 14)
    }
}

local function doCombat(creature, boss, combatType, damage)
    doTargetCombatHealth(creature, boss, combatType, -damage, -damage, CONST_ME_NONE, ORIGIN_SPELL)
end

local ThePaleWormReceiveDmg1 = CreatureEvent("ThePaleWormReceiveDmg")
function ThePaleWormReceiveDmg1.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    for _, info in pairs(config) do
        local foundBoss = Monster(info.foundBoss)
        if foundBoss then
            doCombat(attacker:getId(), foundBoss, primaryType, primaryDamage)
            doCombat(attacker:getId(), foundBoss, secondaryType, secondaryDamage)
        else
            local spectators = Game.getSpectators(creature:getPosition(), false, false, 14, 14, 14, 14)
            for __, spectator in pairs(spectators) do
                if spectator ~= creature then
                    if spectator:getName() == info.bossName then
                        doCombat(attacker:getId(), spectator, primaryType, primaryDamage)
                        doCombat(attacker:getId(), spectator, secondaryType, secondaryDamage)
                        info.foundBoss = spectator
                        break
                    end

                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
ThePaleWormReceiveDmg1:register()
View attachment 55159
tested here the script didn't work the elemental damage is not being sent to the boss
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,035
Solutions
102
Reaction score
1,086
Location
London
GitHub
MillhioreBT
It must be a problem of its destruction, it smells to me that you are not using official TFS
so it is very likely that your problem is related to something else, and not the script
 
OP
OP
A

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
It must be a problem of its destruction, it smells to me that you are not using official TFS
so it is very likely that your problem is related to something else, and not the script
otserverbr
I checked the functions in both srcs are equal
onHealthChange same function
doTargetCombatHealth same function

I'll keep looking for just that
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,035
Solutions
102
Reaction score
1,086
Location
London
GitHub
MillhioreBT
check that the boss is not immune to this element, test with various weapons of different elements, test spells that make use of the secondary element of the weapon, can test the script on another engine, so you can feel confident that the script is not the problem
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,243
Solutions
71
Reaction score
570
Location
Hell
I'm not making a mess kk looking at my code the boss has 'ThePaleWormReceiveDmg' all damage from the monster that is suffering from this event will be reflected in the boss that is in the 'bossName' the problem is that the damage caused by weapons that have an element is not reflecting properly. same as in the example photo mob is attacked and the reflected damage is only physical

Boss at specific position attacked -> nearby monsters receive damage.
Boss at unspecified position attacked -> only boss itself receives dmg.
bossdmg.gif

Tested on TFS 1.3

<boss monster>.xml
XML:
    <script>
        <event name="bossDmg"/>
    </script>

bossDmg.lua
Lua:
local config = {
    dealDmgToAllSpectators = false,
    bosses = {
        {
            name = "Monk",
            position = Position(146, 389, 7)
        }
    }
}

local creatureevent = CreatureEvent("bossDmg")
function creatureevent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    for _, boss in pairs(config.bosses) do
        if creature:getPosition() ~= boss.position then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end

        local spectators = Game.getSpectators(creature:getPosition(), false, false, 14, 14, 14, 14)
        for __, spectator in pairs(spectators) do
            if spectator ~= creature and spectator:isPlayer() == false then
                if spectator:getName():lower() ~= boss.name:lower() then
                    doCombat(0, spectator, primaryType, primaryDamage)
                    doCombat(0, spectator, secondaryType, secondaryDamage)
                    if not config.dealDmgToAllSpectators then
                        break
                    end
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType

end

function doCombat(creature, boss, combatType, damage)
    doTargetCombatHealth(creature, boss, combatType, -damage, -damage, CONST_ME_NONE, ORIGIN_SPELL)
end

creatureevent:type('healthchange')
creatureevent:register()


-------
@Sarah Wesker
In the gif you sent, combat is dealt to the same monster
How did you manage to avoid call stack overflow ?
When I registered the event on monster A and didn't avoid dealing dmg to monsters of same name/type it would instantly call itself over and over until tfs crashed.
 
Last edited:

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,035
Solutions
102
Reaction score
1,086
Location
London
GitHub
MillhioreBT
Here is a version that works with multiple monsters in the same place and with the same registered event.

Lua:
local tempIgnore = {}
local monsters = {
    "Test Monk"
}

local ce = CreatureEvent("ThePaleWormReceiveDmg")
function ce.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local cid = creature:getId()
    if tempIgnore[cid] then
        tempIgnore[cid] = nil
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    local pTarget = attacker:getTarget()
    local spectators = Game.getSpectators(creature:getPosition(), false, false, 14, 14, 14, 14)
    for i, spectator in pairs(spectators) do
        if spectator ~= creature then
            for k, name in pairs(monsters) do
                if name == spectator:getName() then
                    tempIgnore[spectator:getId()] = true
                    doTargetCombatHealth(cid, spectator, primaryType, -primaryDamage, -primaryDamage, nil, origin)
                    doTargetCombatHealth(cid, spectator, secondaryType, -secondaryDamage, -secondaryDamage, nil, origin)
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
ce:register()

GIF 18-02-2021 07-13-23 a. m..gif
 
Top