• 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 Only one boss can be present

Yalasari

Active Member
Joined
Jul 16, 2017
Messages
82
Solutions
8
Reaction score
46
Hello,

I have boss spawning script using globalevents, boss appears every 12 hour + random addtional time, and there's problem, if nobody will kill boss, duplicate will appear, then next one appears, next one ...
And i have problem how to pause this script if already boss is present. (in script, demon is only for explain purposes)
Lua:
local xrand = math.random(-2, 2)
local yrand = math.random(-2, 2)

local position = Position(930 + xrand, 1265 + yrand, 10)
local addtionalTime = math.random(0, 180) * 60 * 1000

local function spawnBoss()

    Game.createMonster("Demon", position)
   
    addtionalTime = math.random(0, 180) * 60 * 1000
   
    xrand = math.random(-2, 2)
    yrand = math.random(-2, 2)
   
    position = Position(930 + xrand, 1265 + yrand, 10)
   
    addEvent(spawnBoss, 12 * 60 * 60 * 1000 + addtionalTime)

end

function onTime(interval)

     addEvent(spawnBoss, addtionalTime)
     
     return true
     
end

Thanks in advance
 
Solution
Add a Global Storage at spawnboss function and make a check on ontime function

Lua:
local xrand = math.random(-2, 2)
local yrand = math.random(-2, 2)

local position = Position(930 + xrand, 1265 + yrand, 10)
local addtionalTime = math.random(0, 180) * 60 * 1000

local function spawnBoss()

    Game.createMonster("Demon", position)
 
    addtionalTime = math.random(0, 180) * 60 * 1000
 
    xrand = math.random(-2, 2)
    yrand = math.random(-2, 2)
 
    position = Position(930 + xrand, 1265 + yrand, 10)
 
    addEvent(spawnBoss, 12 * 60 * 60 * 1000 + addtionalTime)
    -- Add Global storage
end

function onTime(interval)
 -- if Global Storage == 1
     addEvent(spawnBoss, addtionalTime)
--end
     return true
   
end


Create a...
Add a Global Storage at spawnboss function and make a check on ontime function

Lua:
local xrand = math.random(-2, 2)
local yrand = math.random(-2, 2)

local position = Position(930 + xrand, 1265 + yrand, 10)
local addtionalTime = math.random(0, 180) * 60 * 1000

local function spawnBoss()

    Game.createMonster("Demon", position)
 
    addtionalTime = math.random(0, 180) * 60 * 1000
 
    xrand = math.random(-2, 2)
    yrand = math.random(-2, 2)
 
    position = Position(930 + xrand, 1265 + yrand, 10)
 
    addEvent(spawnBoss, 12 * 60 * 60 * 1000 + addtionalTime)
    -- Add Global storage
end

function onTime(interval)
 -- if Global Storage == 1
     addEvent(spawnBoss, addtionalTime)
--end
     return true
   
end


Create a creatureevent Script that sets Storage to 0 if Boss is killed (onDeath or onKill depends on tfs version)
 
Last edited:
Solution
Error line 15: attempt to call field 'getStorageValue' (a nil value)
Lua:
local bossname = "Demon"

local xpos = 930
local ypos = 1265
local zpos = 10

local xrand = math.random(-1, 1)
local yrand = math.random(-1, 1)

local position = Position(930 + xrand, 1265 + yrand, 10)
local addtionalTime = 10000 -- math.random(0, 180) * 60 * 1000

local function spawnBoss()

    if Game.getStorageVaule(66001) == nil or 0 then
  
        Game.createMonster(bossname, position)
      
        xrand = math.random(-1, 1)
        yrand = math.random(-1, 1)
  
        position = Position(xpos + xrand, ypos + yrand, zpos)
  
        addEvent(spawnBoss, 60000 - addtionalTime)
      
        Game.setStorageVaule(66001, 1)
      
        print("Boss \"" .. bossname .. "\" pojawil sie z odchylem koordynatow: x=" .. xrand .. " y=" .. yrand .. "") -- debug
  
    else
  
        print("Boss \"" .. bossname .. "\" aktualnie znajduje sie na mapie.") -- debug
  
    end

end

function onTime(interval)
  
     addEvent(spawnBoss, addtionalTime)
    
     return true
   
end

Code:
isBossPresent = 66001
 
Error line 15: attempt to call field 'getStorageValue' (a nil value)
Lua:
local bossname = "Demon"

local xpos = 930
local ypos = 1265
local zpos = 10

local xrand = math.random(-1, 1)
local yrand = math.random(-1, 1)

local position = Position(930 + xrand, 1265 + yrand, 10)
local addtionalTime = 10000 -- math.random(0, 180) * 60 * 1000

local function spawnBoss()

    if Game.getStorageVaule(66001) == nil or 0 then
 
        Game.createMonster(bossname, position)
     
        xrand = math.random(-1, 1)
        yrand = math.random(-1, 1)
 
        position = Position(xpos + xrand, ypos + yrand, zpos)
 
        addEvent(spawnBoss, 60000 - addtionalTime)
     
        Game.setStorageVaule(66001, 1)
     
        print("Boss \"" .. bossname .. "\" pojawil sie z odchylem koordynatow: x=" .. xrand .. " y=" .. yrand .. "") -- debug
 
    else
 
        print("Boss \"" .. bossname .. "\" aktualnie znajduje sie na mapie.") -- debug
 
    end

end

function onTime(interval)
 
     addEvent(spawnBoss, addtionalTime)
   
     return true
  
end

Code:
isBossPresent = 66001

What TFS version?
Do you have this code? forgottenserver/game.lua at master · otland/forgottenserver · GitHub
 
you'd still need a way to reset the storage value
you can do it by registering a death creatureevent to the boss to reset the global storage value
 
Back
Top