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

[TFS 1.3] [Globalevent] Random boss in room

Marco Oliveira

Well-Known Member
Joined
Jan 5, 2019
Messages
76
Solutions
3
Reaction score
77
Location
Minas Gerais - Brazil
GitHub
omarcopires
Twitch
omarcopires
I made this script for a boss room that I created with the help of a friend, we ended up not using it on the server. I hope it's useful to someone.

Lua:
local bossConfigurations = {
    [1] = {bossName = "Foreman Kneebiter"},
    [2] = {
        bossName = "The Frog Prince",
        summons = {
            {name = "Green Frog", amount = 30}
        }
    },
    [3] = {
        bossName = "Ghazbaran",
        summons = {
            {name = "Deathslicer", amount = 25},
            {name = "Juggernaut", amount = 10},
            {name = "Fury", amount = 20},
            {name = "Demon", amount = 30}
        }
    }
}

local bossRoom = {
    centerPosition = Position(1000, 1000, 7),
    spawnRange = {from = Position(1000, 1000, 7), to = Position(1000, 1000, 7)},
    spawnArea = {x = 20, y = 20}
}

local function getRandomSpawnPosition(fromPosition, toPosition)
    return Position(math.random(fromPosition.x,  toPosition.x), math.random(fromPosition.y,  toPosition.y), math.random(fromPosition.z,  toPosition.z))
end

function startBossRoom()
    -- Clear existing monsters
    local spectators = Game.getSpectators(bossRoom.centerPosition, false, false, bossRoom.spawnArea.x, bossRoom.spawnArea.x, bossRoom.spawnArea.y, bossRoom.spawnArea.y)
    for _, spectator in pairs(spectators) do
        if spectator:isMonster() then
            spectator:remove()
        end
    end

    -- Select a random boss from the available configs
    local bossIndex = math.random(#bossConfigurations)
    local boss = bossConfigurations[bossIndex]

    -- Spawn the selected boss
    if boss.bossName then
        local spawnedBoss = Game.createMonster(boss.bossName, bossRoom.centerPosition, true, true)
        if spawnedBoss then
            Game.broadcastMessage("The boss room was cleaned and the boss " ..boss.bossName.. " was spawned.", MESSAGE_EVENT_ADVANCE)
        else
            print("[Spawn Boss Room] Failed to spawn boss " ..boss.bossName.." in boss room.", MESSAGE_EVENT_ADVANCE)
        end
    else
        Game.broadcastMessage("The boss room was cleaned and only common monsters was spawned.", MESSAGE_EVENT_ADVANCE)
    end

    -- Spawn summons for the selected boss
    local summons = boss.summons
    if summons then
        for _, summon in pairs(summons) do
            local summonName = summon.name
            local summonAmount = summon.amount
            for i = 1, summonAmount do
                local randomPosition = getRandomSpawnPosition(bossRoom.spawnRange.from, bossRoom.spawnRange.to)
                local summonedMonster = Game.createMonster(summonName, randomPosition, true, true)
                if not summonedMonster then
                    print("[Spawn Boss Room] Failed to spawn summon " ..summonName.. " in boss room.")
                end
            end
        end
    end
end

local randomBossEvent = GlobalEvent("Random Boss Event")

function randomBossEvent.onTime(interval)
    if type(startBossRoom) == "function" then
        startBossRoom()
        print("[Spawn Boss Room] event has started.")
    else
        print("[Spawn Boss Room] startBossRoom function does not exist.")
    end
    return true
end

randomBossEvent:interval(math.random(3, 7) * 60 * 60 * 1000) -- Set the interval to 3/7 hours
randomBossEvent:register()

local talk = TalkAction("/startBoss")

function talk.onSay(player, words, param)
    -- Check if player has access to the command
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GAMEMASTER then
        return false
    end

    -- Check if the function "startBossRoom" exists
    if not startBossRoom then
        print("[Spawn Boss Room] startBossRoom does not exist.")
        return false
    end

    -- Call the startBossRoom function
    startBossRoom()
    player:sendTextMessage(MESSAGE_INFO_DESCR, "[Spawn Boss Room] event has started.")
    print("[Spawn Boss Room] event has started.")
    return false
end

talk:register()

You can restart the room using the /starBoss command
 
Last edited by a moderator:
Fiz esse script para uma sala de chefe que criei com a ajuda de um amigo, acabamos não usando no servidor. Espero que seja útil para alguém.

Lua:
local configRoom = {
    centerRoom = Posição(100, 100, 7),
    fromPos = Posição(100, 100, 7),
    toPos = Position(100, 100, 7),
    intervalo X = 20,
    intervaloY = 20
}

local configBosses = {
    [1] = {
        bossName = "Os muitos",
        convocar = {
            nome = "hidra",
            quantidade = 30
        },
    },

    [2] = {
        bossName = "Orshabaal",
        convocar = {
            nome = "Demônio",
            quantidade = 10
        },
    }
}

função local startBossRoom()
    especificações locais = Game.getSpectators(configRoom.centerRoom, false, false, configRoom.rangeX, configRoom.rangeX, configRoom.rangeY, configRoom.rangeY)
    para _, especificação em pares (especificações) faça
        if spec:isMonster() então
            spec:remover()
        fim
    fim

    -- Criar chefe:
    local bossIndex = math.random(1, 2)
    chefe local = configBosses[bossIndex]
    local bossName = boss.bossName
    Game.createMonster(bossName, configRoom.centerRoom, true, true)

    -- Criar Invocações:
    convocação local = boss.summon
    se convocar então
        local summonName = boss.summon.name
        local summonAmount = boss.summon.amount
        for i = 1, summonAmount do
            local randomPos = getRandomSpawnPosition(configRoom.fromPos, configRoom.toPos)
            Game.createMonster(summonName, randomPos, true, true)
        end
    end

    Game.broadcastMessage("The boss room was cleaned and the boss " .. bossName.. " was spawned.", MESSAGE_EVENT_ADVANCE)
end

local bossRoom = GlobalEvent("Random Boss Room")

function bossRoom.onTime(interval)
    startBossRoom()
    return true
end

bossRoom:interval(3 * 60 * 60 * 1000)
bossRoom:register()

local startBossRoomTalk = TalkAction("/startBoss")

function startBossRoomTalk.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    startBossRoom()
    return false
end

startBossRoomTalk:register()

Você pode reiniciar a sala usando o comando /starBoss

when I use the /startboss command, I get this error in the console

1649879685274.png
 
Lua:
local configRoom = {
    centerRoom = Position(100, 100, 7),
    fromPos = Position(100, 100, 7),
    toPos = Position(100, 100, 7),
    rangeX = 20,
    rangeY = 20
}

local configBosses = {
    [1] = {
        bossName = "The Many",
        summon = {
            name = "Hydra",
            amount = 30
        },
    },

    [2] = {
        bossName = "Orshabaal",
        summon = {
            name = "Demon",
            amount = 10
        },
    }
}

local function getRandomSpawnPosition(fromPos, toPos)
    return Position(math.random(fromPos.x,  toPos.x), math.random(fromPos.y,  toPos.y), math.random(fromPos.z,  toPos.z))
end

local function startBossRoom()
    local specs = Game.getSpectators(configRoom.centerRoom, false, false, configRoom.rangeX, configRoom.rangeX, configRoom.rangeY, configRoom.rangeY)
    for _, spec in pairs(specs) do
        if spec:isMonster() then
            spec:remove()
        end
    end

    -- Create Boss:
    local bossIndex = math.random(1, 2)
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
    Game.createMonster(bossName, configRoom.centerRoom, true, true)

    -- Create Summons:
    local summon = boss.summon
    if summon then
        local summonName = boss.summon.name
        local summonAmount = boss.summon.amount
        for i = 1, summonAmount do
            local randomPos = getRandomSpawnPosition(configRoom.fromPos, configRoom.toPos)
            Game.createMonster(summonName, randomPos, true, true)
        end
    end

    Game.broadcastMessage("The boss room was cleaned and the boss " .. bossName.. " was spawned.", MESSAGE_EVENT_ADVANCE)
end

local bossRoom = GlobalEvent("Random Boss Room")

function bossRoom.onTime(interval)
    startBossRoom()
    return true
end

bossRoom:interval(3 * 60 * 60 * 1000)
bossRoom:register()

local startBossRoomTalk = TalkAction("/startBoss")

function startBossRoomTalk.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    startBossRoom()
    return false
end

startBossRoomTalk:register()
 
Lua:
local configRoom = {
    centerRoom = Position(100, 100, 7),
    fromPos = Position(100, 100, 7),
    toPos = Position(100, 100, 7),
    rangeX = 20,
    rangeY = 20
}

local configBosses = {
    [1] = {
        bossName = "The Many",
        summon = {
            name = "Hydra",
            amount = 30
        },
    },

    [2] = {
        bossName = "Orshabaal",
        summon = {
            name = "Demon",
            amount = 10
        },
    }
}

local function getRandomSpawnPosition(fromPos, toPos)
    return Position(math.random(fromPos.x,  toPos.x), math.random(fromPos.y,  toPos.y), math.random(fromPos.z,  toPos.z))
end

local function startBossRoom()
    local specs = Game.getSpectators(configRoom.centerRoom, false, false, configRoom.rangeX, configRoom.rangeX, configRoom.rangeY, configRoom.rangeY)
    for _, spec in pairs(specs) do
        if spec:isMonster() then
            spec:remove()
        end
    end

    -- Create Boss:
    local bossIndex = math.random(1, 2)
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
    Game.createMonster(bossName, configRoom.centerRoom, true, true)

    -- Create Summons:
    local summon = boss.summon
    if summon then
        local summonName = boss.summon.name
        local summonAmount = boss.summon.amount
        for i = 1, summonAmount do
            local randomPos = getRandomSpawnPosition(configRoom.fromPos, configRoom.toPos)
            Game.createMonster(summonName, randomPos, true, true)
        end
    end

    Game.broadcastMessage("The boss room was cleaned and the boss " .. bossName.. " was spawned.", MESSAGE_EVENT_ADVANCE)
end

local bossRoom = GlobalEvent("Random Boss Room")

function bossRoom.onTime(interval)
    startBossRoom()
    return true
end

bossRoom:interval(3 * 60 * 60 * 1000)
bossRoom:register()

local startBossRoomTalk = TalkAction("/startBoss")

function startBossRoomTalk.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    startBossRoom()
    return false
end

startBossRoomTalk:register()
Good afternoon beauty? it worked fine, thank you very much.

I would like to know if it is possible to add another script when the boss is born, create a teleport at position X and send the player to position Y
 
Hello, could you adjust the code for when killing the selected boss, remove a wall in a chosen position so that the players have acess to the return portal and when the command is used again for a new event the wall reappears blocking the portal again? thanks for you help!!
 
use svargrond arena scripts or look at helmet of ancient bosses how they spawn teleport after death :p
 
Hello, could you adjust the code for when killing the selected boss, remove a wall in a chosen position so that the players have acess to the return portal and when the command is used again for a new event the wall reappears blocking the portal again? thanks for you help!!
Lua:
local configRoom = {
    centerRoom = Position(100, 100, 7),
    fromPos = Position(100, 100, 7),
    toPos = Position(100, 100, 7),
    rangeX = 20,
    rangeY = 20,
    wallPosition = Position(100, 100, 7),
    wallId = 1111
}

local configBosses = {
    [1] = {
        bossName = "The Many",
        summon = {
            name = "Hydra",
            amount = 30
        },
    },

    [2] = {
        bossName = "Orshabaal",
        summon = {
            name = "Demon",
            amount = 10
        },
    }
}

local function addRemoveWall(wallPosition, wallItemId, shouldWallExist)
    local tile = Tile(wallPosition)
    if not tile then
        print("Position set to a location that does not contain a tile.")
        return false
    end

    local wall = tile:getItemById(wallItemId)
    if shouldWallExist then
        if not wall then
            Game.createItem(wallItemId, 1, wallPosition)
        end
    else
        if wall then
            wall:remove()
        end
    end
end

local function getRandomSpawnPosition(fromPos, toPos)
    return Position(math.random(fromPos.x,  toPos.x), math.random(fromPos.y,  toPos.y), math.random(fromPos.z,  toPos.z))
end

local function startBossRoom()
    local specs = Game.getSpectators(configRoom.centerRoom, false, false, configRoom.rangeX, configRoom.rangeX, configRoom.rangeY, configRoom.rangeY)
    for _, spec in pairs(specs) do
        if spec:isMonster() then
            spec:remove()
        end
    end
  
    -- Create  Wall
    addRemoveWall(configRoom.wallPosition, configRoom.wallId, true)

    -- Create Boss:
    local bossIndex = math.random(#configBosses)
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
    local _boss = Game.createMonster(bossName, configRoom.centerRoom, true, true)
    _boss:registerEvent("onDeath_RandomBossRoom")
  

    -- Create Summons:
    local summon = boss.summon
    if summon then
        local summonName = boss.summon.name
        local summonAmount = boss.summon.amount
        for i = 1, summonAmount do
            local randomPos = getRandomSpawnPosition(configRoom.fromPos, configRoom.toPos)
            Game.createMonster(summonName, randomPos, true, true)
        end
    end

    Game.broadcastMessage("The boss room was cleaned and the boss " .. bossName.. " was spawned.", MESSAGE_EVENT_ADVANCE)
end


local creatureevent = CreatureEvent("onDeath_RandomBossRoom")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    addRemoveWall(configRoom.wallPosition, configRoom.wallId, false)
    return true
end

creatureevent:register()


local bossRoom = GlobalEvent("Random Boss Room")

function bossRoom.onTime(interval)
    startBossRoom()
    return true
end

bossRoom:interval(3 * 60 * 60 * 1000)
bossRoom:register()


local startBossRoomTalk = TalkAction("/startBoss")

function startBossRoomTalk.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    startBossRoom()
    return false
end

startBossRoomTalk:register()
 
Last edited:
Back
Top