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

"Mini boss" Revscript

richardestro

New Member
Joined
Oct 23, 2023
Messages
15
Reaction score
1
Hey! Looking for some help, i found this revscript that summons a "stronger version" of a killed monster, for TFS 1.3.

Lua:
local spawnbosses = {
    ["Rotworm"] = {
        chance = 50,
        bossName = "Demon" -- i use Demon only for test
    },
    ["Dragon"] = {
        chance = 50,
        bossName = "Dragon Boss"
    }
}

local cSpawnBossWhenDie = CreatureEvent("SpawnBossWhenDie")
function cSpawnBossWhenDie.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local prop = spawnbosses[creature:getName()]
    if prop and math.random(100) <= prop.chance then
        Game.createMonster(prop.bossName, creature:getPosition())
    end
    return true
end
cSpawnBossWhenDie:register()

local ev = EventCallback
function ev.onTargetCombat(creature, target)
    if creature:isPlayer() and target:isMonster() and spawnbosses[target:getName()] then
        target:registerEvent("SpawnBossWhenDie")
    end
    return RETURNVALUE_NOERROR
end

I using TFS 1.3, but find out the revscript uses EventCallbacks, and my server isn't compatible with EventCallbacks, I want to know if this is a way to make this work without the EventCallback?
I found the revscript here in the post of @Sarah Wesker : Lua - [TFS 1.3] Free Scripting Service 📝 (https://otland.net/threads/tfs-1-3-free-scripting-service.274636/)
 
There are definitely more ways you can register events to monsters.

But you can put the EventCallback part here instead:

But change creature:isPlayer() to self:isPlayer() and remember to change enabled to 1 in events.xml for onTargetCombat, also perhaps just make the spawnbosses table global for now.
 
There are definitely more ways you can register events to monsters.

But you can put the EventCallback part here instead:

But change creature:isPlayer() to self:isPlayer() and remember to change enabled to 1 in events.xml for onTargetCombat, also perhaps just make the spawnbosses table global for now.
Did that, but sadly still nothing :(
 
I expeditiously developed a script that, upon defeating the primary monster, triggers the appearance of another miniboss. The miniboss's health is determined by a percentage agreement, which I have documented in the table.

Regarding the scenario where killing the monster leads to the spawning of another miniboss with varied damage, it is not achievable through LUA alone. Regrettably, it necessitates modifications to the source code. Nonetheless, the script is straightforward and effective.



miniboss.gif


data/scripts.
Lua:
local minibossConfig = {
    ["Rotworm"] = {
        minibossName = "Demon",
        chance = 50,
        healthMultiplier = 1.5
    },
    ["Dragon"] = {
        minibossName = "Dragon Boss",
        chance = 15,
        healthMultiplier = 2
    }
}

local function getRandomPositionAroundPlayer(player, radius)
    local playerPos = player:getPosition()
    local randX = math.random(-radius, radius)
    local randY = math.random(-radius, radius)
    local minibossPos = {x = playerPos.x + randX, y = playerPos.y + randY, z = playerPos.z}
    return minibossPos
end

local function cSpawnBossWhenDie(player, currentMonsterName)
    local minibossData = minibossConfig[currentMonsterName]
    if minibossData then
        local minibossName = minibossData.minibossName
        local shouldcSpawnBossWhenDie = math.random(100) <= minibossData.chance
        if shouldcSpawnBossWhenDie then
            local minibossPos = getRandomPositionAroundPlayer(player, 3)
            local newMiniboss = Game.createMonster(minibossName, minibossPos, false, true)
            if newMiniboss then
                local newHealth = newMiniboss:getMaxHealth() * minibossData.healthMultiplier
                newMiniboss:setMaxHealth(newHealth)
                newMiniboss:addHealth(newHealth - newMiniboss:getHealth())
                return true
            end
        else
        end
    end
    return false
end

local minibossesEvent = CreatureEvent("minibosses")
function minibossesEvent.onKill(player, target)
    local targetMonster = Monster(target:getId())
    if not targetMonster then
        return
    end
    
    local currentMonsterName = targetMonster:getName()
    local minibossSummoned = cSpawnBossWhenDie(player, currentMonsterName)
    if minibossSummoned then
        targetMonster:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONAREA)
    end
    
    return true
end
minibossesEvent:register()


local loginEvent = CreatureEvent("loginminibosses")
function loginEvent.onLogin(player)
    player:registerEvent("minibosses")
    return true
end
loginEvent:register()
 
Last edited:
Back
Top