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

RevScripts Auto Spawner

Svira

Active Member
Joined
Jan 27, 2008
Messages
263
Solutions
11
Reaction score
35
The problem is that after a few BOSS the script stops and doesn't create any more monsters without error.

The boss name cannot be defined because it is fetched from the table, there are more than 50 of them

Part of choise boss:
Lua:
local boss = configBosses[bossIndex]
    local bossName = boss.bossName
    Game.createMonster(bossName, configRoom.centerRoom, true, true)

part onKill:
Lua:
 local BossDeath = CreatureEvent('BossDeath')

function BossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    local playerPosition = creature:getPosition()
    local topLeftCorner = Position(976, 59, 6)
    local bottomRightCorner = Position(990, 73, 6)

    if playerPosition:isInRange(topLeftCorner, bottomRightCorner) then
        Game.broadcastMessage(creature:getName() .. ' has been killed. The boss room was cleaned and the boss was spawned in few sec.', MESSAGE_EVENT_ADVANCE)
        addEvent(startBossRoom, 3000)
        else
        end
    return true
end
BossDeath:register()

No engine error
 
Solution
none is registered checks killed creature in arena and config
just after a few boss stops resp another
onDeath is only triggered if the monster's .xml file has the trigger for onDeath. (or it's been registered via onSpawn or from a script.)

Otherwise, you need to trigger it via onKill, which can be attached to the player.

So my guess, is some of your bosses have the onDeath properly implemented, and some others do not..
Which is why you're getting inconsistent results. Sometimes 2 deaths, sometimes 8 deaths.

So your 2 options are manually going into each of those boss's monster.xml files and adding the onDeath trigger
Or editing the script to apply the onDeath trigger when the boss is spawned.

Here's the latter.

Lua:
local...
can you share startBossRoom
Yes, but without monsterlist:


Lua:
local configRoom = {
    centerRoom = Position(983, 66, 6),
    fromPos = Position(976, 59, 6),
    toPos = Position(990, 73, 6),
    rangeX = 7,
    rangeY = 7
}

local configBosses = {
    [1] = {
        bossName = "Aftershock",
    },
    [2] = {
        bossName = "Arachir the Ancient One",
    }
    --more monsters here
}

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, 50)
    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 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()

-- local bossRoom = GlobalEvent("Random Boss Room")

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

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

 local changeboss = GlobalEvent("changeboss")

 function changeboss.onThink(cid, interval)
     if last_interval == nil then last_interval= os.clock() end

       if (os.clock() - last_interval) > 150 then       
         startBossRoom()
        
         last_interval= os.clock()
         return true
     end
        
   return true
 end
  changeboss:interval(1000)
 changeboss:register()
 
 local BossDeath = CreatureEvent('BossDeath')

function BossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    local playerPosition = creature:getPosition()
    local topLeftCorner = Position(976, 59, 6)
    local bottomRightCorner = Position(990, 73, 6)
    
    if playerPosition:isInRange(topLeftCorner, bottomRightCorner) then
        Game.broadcastMessage(creature:getName() .. ' has been killed. The boss room was cleaned and the boss was spawned in few sec.', MESSAGE_EVENT_ADVANCE)
        addEvent(startBossRoom, 3000)
        else
        end
    return true
end
BossDeath:register()



-- local BOSS_POSaa = {x = 983, y = 66, z = 6} -- boss spawn 983, 66, 6
-- local roomaa = {fromx = 976, tox = 990, fromy = 59, toy = 73, z = 6}
 
Couple quick edits.
Lua:
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:
  
    -- suggested edit, so the table size isn't manually limited to 50
    -- local bossIndex = math.random(1, 50)
    local bossIndex = math.random(#configBosses)
  
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
  
    -- suggested edit, to confirm boss has spawned.
    -- Game.createMonster(bossName, configRoom.centerRoom, true, true)
  
    local spawnedCreature = Game.createMonster(bossName, configRoom.centerRoom, true, true)
    if spawnedCreature then
        print("Boss Spawned.")
    else
        print("Boss (" .. bossName .. ") was unable to Spawn.")
        addEvent(startBossRoom, 3000) -- retry in 3 seconds
        return true
    end
  
    -- 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
Lua:
local last_interval -- adding this because it was missing. With it missing this variable was Global, and could be changed by another script possibly.

local changeboss = GlobalEvent("changeboss")

function changeboss.onThink(cid, interval)
    if last_interval == nil then last_interval= os.clock() end
  
    if (os.clock() - last_interval) > 150 then     
        startBossRoom()
        last_interval= os.clock()
    end
      
    return true
end

changeboss:interval(1000)
changeboss:register()
 
Couple quick edits.
Lua:
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:
 
    -- suggested edit, so the table size isn't manually limited to 50
    -- local bossIndex = math.random(1, 50)
    local bossIndex = math.random(#configBosses)
 
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
 
    -- suggested edit, to confirm boss has spawned.
    -- Game.createMonster(bossName, configRoom.centerRoom, true, true)
 
    local spawnedCreature = Game.createMonster(bossName, configRoom.centerRoom, true, true)
    if spawnedCreature then
        print("Boss Spawned.")
    else
        print("Boss (" .. bossName .. ") was unable to Spawn.")
        addEvent(startBossRoom, 3000) -- retry in 3 seconds
        return true
    end
 
    -- 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
Lua:
local last_interval -- adding this because it was missing. With it missing this variable was Global, and could be changed by another script possibly.

local changeboss = GlobalEvent("changeboss")

function changeboss.onThink(cid, interval)
    if last_interval == nil then last_interval= os.clock() end
 
    if (os.clock() - last_interval) > 150 then    
        startBossRoom()
        last_interval= os.clock()
    end
     
    return true
end

changeboss:interval(1000)
changeboss:register()

Scripts stop without:
Lua:
        print("Boss (" .. bossName .. ") was unable to Spawn.")
 
Scripts stop without:
Lua:
        print("Boss (" .. bossName .. ") was unable to Spawn.")
What script is stopping?

The onThink?
The startBossRoom?
The talkaction?
the OnDeath?

Tell us what you're doing to stop it from working.
 
What script is stopping?

The onThink?
The startBossRoom?
The talkaction?
the OnDeath?

Tell us what you're doing to stop it from working.
OnDeath

the script works normally, it beats the bosses and suddenly stops, it doesn't display the message that the boss has been killed and there will be another one soon. sometimes it happens after 2 bosses sometimes after 8 no matter what bosses. they just stop orsp
 
OnDeath

the script works normally, it beats the bosses and suddenly stops, it doesn't display the message that the boss has been killed and there will be another one soon. sometimes it happens after 2 bosses sometimes after 8 no matter what bosses. they just stop orsp

So the boss dies but never spawns again?

Do all these bosses have the onDeath script attached to them?
BossDeath
 
none is registered checks killed creature in arena and config
just after a few boss stops resp another
 
none is registered checks killed creature in arena and config
just after a few boss stops resp another
onDeath is only triggered if the monster's .xml file has the trigger for onDeath. (or it's been registered via onSpawn or from a script.)

Otherwise, you need to trigger it via onKill, which can be attached to the player.

So my guess, is some of your bosses have the onDeath properly implemented, and some others do not..
Which is why you're getting inconsistent results. Sometimes 2 deaths, sometimes 8 deaths.

So your 2 options are manually going into each of those boss's monster.xml files and adding the onDeath trigger
Or editing the script to apply the onDeath trigger when the boss is spawned.

Here's the latter.

Lua:
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(#configBosses)
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
   
    local spawnedCreature = Game.createMonster(bossName, configRoom.centerRoom, true, true)
    if spawnedCreature then
        print("Boss Spawned.")
        -- add onDeath trigger
        spawnedCreature:registerEvent("BossDeath")
    else
        print("Boss (" .. bossName .. ") was unable to Spawn.")
        addEvent(startBossRoom, 3000) -- retry in 3 seconds
        return true
    end
   
    -- 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

-- Edit
third option is to swap it from onDeath to onKill. 🤷‍♂️
 
Last edited:
Solution
onDeath is only triggered if the monster's .xml file has the trigger for onDeath. (or it's been registered via onSpawn or from a script.)

Otherwise, you need to trigger it via onKill, which can be attached to the player.

So my guess, is some of your bosses have the onDeath properly implemented, and some others do not..
Which is why you're getting inconsistent results. Sometimes 2 deaths, sometimes 8 deaths.

So your 2 options are manually going into each of those boss's monster.xml files and adding the onDeath trigger
Or editing the script to apply the onDeath trigger when the boss is spawned.

Here's the latter.

Lua:
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(#configBosses)
    local boss = configBosses[bossIndex]
    local bossName = boss.bossName
 
    local spawnedCreature = Game.createMonster(bossName, configRoom.centerRoom, true, true)
    if spawnedCreature then
        print("Boss Spawned.")
        -- add onDeath trigger
        spawnedCreature:registerEvent("BossDeath")
    else
        print("Boss (" .. bossName .. ") was unable to Spawn.")
        addEvent(startBossRoom, 3000) -- retry in 3 seconds
        return true
    end
 
    -- 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

-- Edit
third option is to swap it from onDeath to onKill. 🤷‍♂️

For several hours the script did not stop, I hope this has already fixed the problem. Thank you very much for your help!

#edit
I can't mark a post as "best answer" - problem solved
 
Back
Top