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

Spawn boss if he is dead

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
I have a problem with this script, it creates a boss but a few times even if it isn't dead and then it stops working.

Additionally, how to make the boss appear after the server starts?

Code:
local boss_name = "Demodras" -- boss name
local boss_pos = {x = 1491, y = 1100, z = 15} -- boss spawn  
local pos_room = {fromx = 1503, tox = 1100, fromy = 1477, toy = 1075, z = 15} -- boss room

function onThink(interval, lastExecution)
local check_boss = 0
for x = pos_room.fromx, pos_room.tox do
for y = pos_room.fromy, pos_room.toy do
for z = pos_room.z, pos_room.z do

creatureaa = {x = x, y = y, z = z}
mob = getTopCreature(creatureaa).uid

    if getCreatureName(mob) == boss_name then
        check_boss = 1
    end
end
end
end

if check_boss == 1 then
end

if check_boss == 0 then
        Game.createMonster(boss_name, boss_pos)
end

return true
end
 
Solution
I have a problem with this script, it creates a boss but a few times even if it isn't dead and then it stops working.

Additionally, how to make the boss appear after the server starts?

Code:
local boss_name = "Demodras" -- boss name
local boss_pos = {x = 1491, y = 1100, z = 15} -- boss spawn 
local pos_room = {fromx = 1503, tox = 1100, fromy = 1477, toy = 1075, z = 15} -- boss room

function onThink(interval, lastExecution)
local check_boss = 0
for x = pos_room.fromx, pos_room.tox do
for y = pos_room.fromy, pos_room.toy do
for z = pos_room.z, pos_room.z do

creatureaa = {x = x, y = y, z = z}
mob = getTopCreature(creatureaa).uid

    if getCreatureName(mob) == boss_name then
        check_boss = 1
    end
end
end
end

if check_boss...
I have a problem with this script, it creates a boss but a few times even if it isn't dead and then it stops working.

Additionally, how to make the boss appear after the server starts?

Code:
local boss_name = "Demodras" -- boss name
local boss_pos = {x = 1491, y = 1100, z = 15} -- boss spawn 
local pos_room = {fromx = 1503, tox = 1100, fromy = 1477, toy = 1075, z = 15} -- boss room

function onThink(interval, lastExecution)
local check_boss = 0
for x = pos_room.fromx, pos_room.tox do
for y = pos_room.fromy, pos_room.toy do
for z = pos_room.z, pos_room.z do

creatureaa = {x = x, y = y, z = z}
mob = getTopCreature(creatureaa).uid

    if getCreatureName(mob) == boss_name then
        check_boss = 1
    end
end
end
end

if check_boss == 1 then
end

if check_boss == 0 then
        Game.createMonster(boss_name, boss_pos)
end

return true
end
View attachment bandicam 2021-09-16 14-06-40-111.mp4

XML:
<globalevent name="bossSpawner" interval="1000" script="bossSpawner.lua" />
Lua:
local config = {
    {bossName = "Demodras", spawnPosition = Position(245, 244, 7), respawnTimer = 10}, -- respawnTimer is in seconds. -> 60 * 60 * 1 <- would be an hour 
    {bossName = "Demodras", spawnPosition = Position(246, 244, 7), respawnTimer = 10},
    {bossName = "Demodras", spawnPosition = Position(247, 244, 7), respawnTimer = 10},
    {bossName = "Demodras", spawnPosition = Position(248, 244, 7), respawnTimer = 10},
    {bossName = "Demodras", spawnPosition = Position(249, 244, 7), respawnTimer = 10},
    {bossName = "Demodras", spawnPosition = Position(250, 244, 7), respawnTimer = 10},
}

local bosses = {}

function onThink(interval, lastExecution)
    for i = 1, #config do
    
        -- spawns bosses with first onThink
        if not bosses[i] then
            local creature = Game.createMonster(config[i].bossName, config[i].spawnPosition)
            local creatureId = creature:getId()
            bosses[i] = {creatureId, 0}
        end
        
        -- when boss is detected as dead
        local creature = Creature(bosses[i][1])
        if not creature then
        
            -- set respawn timer
            if bosses[i][2] == 0 then
                bosses[i][2] = os.time() + config[i].respawnTimer
            end
            
            -- respawn boss when timer elapses
            if bosses[i][2] < os.time() then
                creature = Game.createMonster(config[i].bossName, config[i].spawnPosition)
                local creatureId = creature:getId()
                bosses[i] = {creatureId, 0}
            end
        end
    end
    return true
end
 
Solution
IF you want them to spawn when the sserver starts, why don't you just add them to your spawns tile and set the respawn time to 10 seconds?
 
That works if it's a regular spawn, but what if you want a 5 hour delay?
make it 5 hours? lol

OP only said spawning them from startup and every 10 seconds by that script. If there's nothing special about it, just make them short spawn timers.

I think RME spawns go up to 3600 buy you can just edit the xml file to change them as well
 
IF you want them to spawn when the sserver starts, why don't you just add them to your spawns tile and set the respawn time to 10 seconds?

1. spawn can't be blocked
2. can adjust spawn rate without reloading the map
3. can do more magical lua things with spawn - sometimes when people ask for a script it is merely a component of a larger script or system they are making
 
Back
Top