• 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 Boss mechanic

Wilku93

Member
Joined
Jul 7, 2024
Messages
35
Reaction score
9
GitHub
Wilku93
Hi! I have TFS 1.4.2 :)

I'm in the process of creating a boss script but I have a problem with two things, maybe someone can help me with this.

The first mechanic that I don't know how to set up is:

The boss changes mechanics every certain amount of hp (where in the next mechanic he stops using the previous one)

For example:
100-75% hp only attacks

74-50% hp starts using some attack
49-25% hp stops using this attack and does something else, e.g. summons monsters
....

Additionally, every phase change the boss "screams" Phase 1, Phase 2, Phase 3...


The second mechanic is that a boss, e.g. from 49% to 25% HP, summons 5 monsters (e.g. GSs) in random locations around him at once. If one is killed, another one will be summoned immediately (5 max). This will continue until the phase ends (24% and less)

I will be grateful for help :)
 
Solution
You can do it in few different ways.

1. In monster xml file, Young Troll in this example, add script="troll_evolve.lua" in the line with name, for example after manacost="0".
Then create a folder named "scripts" inside "monster" folder, if you dont have it already.
Then create script troll_evolve.lua and place this code:
LUA:
function onThink(creature)
    addEvent(function(cid)
        local creature = Creature(cid)
        if not creature then
            return
        end
        local hp = (creature:getHealth()/creature:getMaxHealth())*100

        if hp < 80 and hp > 50 then
            creature:say("Something, something, something smells", TALKTYPE_ORANGE_1)
            local pos = creature:getPosition()...
You can do it in few different ways.

1. In monster xml file, Young Troll in this example, add script="troll_evolve.lua" in the line with name, for example after manacost="0".
Then create a folder named "scripts" inside "monster" folder, if you dont have it already.
Then create script troll_evolve.lua and place this code:
LUA:
function onThink(creature)
    addEvent(function(cid)
        local creature = Creature(cid)
        if not creature then
            return
        end
        local hp = (creature:getHealth()/creature:getMaxHealth())*100

        if hp < 80 and hp > 50 then
            creature:say("Something, something, something smells", TALKTYPE_ORANGE_1)
            local pos = creature:getPosition()
            pos:sendMagicEffect(CONST_ME_POFF)
            if creature then
                creature:remove()
            end
            local summon = Game.createMonster("Troll", pos, false, true)

            if summon and summon:isMonster() then
                summon:addHealth(-3000)
            end

            if not summon then
                return
            end
        end

    return true
    end, 3000, creature:getId())
end
It has a downside where you have to set the HP of the new creature, so I don't like this solution. It can also get buggy when boss has small amout of HP. You can try to improve it or fix it anyway.
Advantage is that you can change the wole monster, which sometimes might be needed.

2. Usually a better way is to create a spells for that monster, and just activate certain spell when the boss has specified amount of health. For example:
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setFormula(COMBAT_FORMULA_DAMAGE, -1000, 0, -1000, 0)

local condition = Condition(CONDITION_PARALYZE)
condition:setParameter(CONDITION_PARAM_TICKS, 1000)
condition:setFormula(5, 0, 0, 0)
combat:addCondition(condition)

local spell = Spell("instant")

function spell.onCastSpell(creature, variant)
    if creature:getHealth() <= (creature:getMaxHealth() * 0.5) then
        return combat:execute(creature, variant)
    end
    return true
end

spell:name("troll spell")
spell:words("###9999")
spell:isAggressive(true)
spell:blockWalls(true)
spell:needLearn(true)
spell:needDirection(false)
spell:register()

And just play when the attack can be triggered: if creature:getHealth() <= (creature:getMaxHealth() * 0.5) then this means it will trigger this attack when its health is below or equal 50%.
 
Last edited:
Solution
Back
Top