• 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!

Lua Spell for monster to heal a specific boss

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hey, I would like a spell for a specific monster to use from time to time to heal a specific boss when they are close to each other.
 
Solution
Haven't tested, but should be what you're looking for.


Code:
local combat = Combat()

local config ={
    bossName = "Demon" -- Boss name here
}
function onCastSpell(creature, variant)

    local spectators = Game.getSpectators(creature:getPosition(), false, false, 7, 7, 7, 7) -- (7,7,7,7) is how many tiles away it will detect creatures.
    if #spectators > 0 then
        for i = 1, #spectators do
            if spectators[i]:getName() == config.bossName then
                local boss = spectators[i]
                local bossMaxHp = boss:getMaxHealth()
                creature:getPosition():sendDistanceEffect(boss:getPosition(), CONST_ANI_SMALLHOLY)
                boss:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)...
Try with this script.

Lua:
local config = {
    level = 70,
    magicLevel = 40,
    targetName = "Specific Boss Name"
}
local combat = Combat()
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setArea(createCombatArea(AREA_CIRCLE6X6))
function onTargetCreature(creature, target)
    if target:isPlayer() then
        return false
    end

    if target:getName() == config.targetName then
        local min = (config.level / 5) + (config.magicLevel * 4.6) + 30
        local max = (config.level / 5) + (config.magicLevel * 9.6) + 125
        doTargetCombatHealth(creature, target, COMBAT_HEALING, min, max, CONST_ME_MAGIC_BLUE)
        creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

It's tested and it works :)
Just change config.targetName to whatever name you have on your boss, register the custom spell in spells.xml and give it to your specific monster in the specific_monster_name.xml file
 
local config = { level = 70, magicLevel = 40, targetName = "Specific Boss Name" } local combat = Combat() combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE) combat:setArea(createCombatArea(AREA_CIRCLE6X6)) function onTargetCreature(creature, target) if target:isPlayer() then return false end if target:getName() == config.targetName then local min = (config.level / 5) + (config.magicLevel * 4.6) + 30 local max = (config.level / 5) + (config.magicLevel * 9.6) + 125 doTargetCombatHealth(creature, target, COMBAT_HEALING, min, max, CONST_ME_MAGIC_BLUE) creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) end return true end combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature") function onCastSpell(creature, variant) return combat:execute(creature, variant) end
It didn't work for me, don't know why.

Spells.xml
<instant name="bosshealer" words="###161" aggressive="1" needtarget="1" blockwalls="1" needlearn="1" script="monster/bosshealer.lua" />

Monster.xml
<attack name="bosshealer" interval="1000" chance="90" target="0" min="300" max="500">
<attribute key="areaEffect" value="redspark" />
</attack>

No errors on TFS
 
It didn't work for me, don't know why.

Spells.xml


Monster.xml


No errors on TFS
Not entirely sure why it wouldn't work. It might be that you have written target, max and min values + attributes. I don't think you should have that. This is how I have it setup:

XML:
<attack name="bosshealer" interval="2000" chance="100" />
XML:
<instant name="bosshealer" words="###60" aggressive="1" blockwalls="1" needtarget="0" needlearn="1" script="monster/bosshealer.lua" />
 
Not entirely sure why it wouldn't work. It might be that you have written target, max and min values + attributes. I don't think you should have that. This is how I have it setup:

XML:
<attack name="bosshealer" interval="2000" chance="100" />
XML:
<instant name="bosshealer" words="###60" aggressive="1" blockwalls="1" needtarget="0" needlearn="1" script="monster/bosshealer.lua" />
I've tried like this and the same resullt, no errors on TFS, but no healing done.
 
Haven't tested, but should be what you're looking for.


Code:
local combat = Combat()

local config ={
    bossName = "Demon" -- Boss name here
}
function onCastSpell(creature, variant)

    local spectators = Game.getSpectators(creature:getPosition(), false, false, 7, 7, 7, 7) -- (7,7,7,7) is how many tiles away it will detect creatures.
    if #spectators > 0 then
        for i = 1, #spectators do
            if spectators[i]:getName() == config.bossName then
                local boss = spectators[i]
                local bossMaxHp = boss:getMaxHealth()
                creature:getPosition():sendDistanceEffect(boss:getPosition(), CONST_ANI_SMALLHOLY)
                boss:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
                local minHeal = bossMaxHp * 0.02
                local maxHeal = bossMaxHp * 0.05
                addEvent(doTargetCombatHealth, 0, creature:getId(), boss:getId(), COMBAT_HOLYDAMAGE, minHeal, maxHeal, CONST_ME_HOLYAREA)
                break
            end
        end
    end
    return true
end
 
Solution
I've tried like this and the same resullt, no errors on TFS, but no healing done.
Lua:
local config = {
    level = 70,
    magicLevel = 40,
    targetName = "Specific Boss Name"
}
local combat = Combat()
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setArea(createCombatArea(AREA_CIRCLE6X6))
function onTargetCreature(creature, target)
    if target:isPlayer() then
        return false
    end

    if target:getName() == config.targetName then
        local min = (config.level / 5) + (config.magicLevel * 4.6) + 30
        local max = (config.level / 5) + (config.magicLevel * 9.6) + 125
        doTargetCombatHealth(creature, target, COMBAT_HEALING, min, max, CONST_ME_MAGIC_BLUE)
        creature:getPosition():sendDistanceEffect(target:getPosition(), CONST_ANI_SMALLHOLY) -- Add this to see that it works
        creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

If that doesn't work then you must have missed something in syntax. Check TFS console output when you start the server to see that all your monsters and spells are being loaded etc. Sitrene's code might also work, but I would not want to run spells that instanciates Combat() and never executes it. Maybe lua trash collector gets rid of it, I don't really know. Also I have no idea what's up with that 0 delay event...
 
Last edited:
Back
Top