• 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.X+ Remove boss if not die in 10min

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
How i can remove boss if not die in 10min?
The msg says, a boss will be created in 5 minutes.... and execute

the error is in this function, i dont know how can i get the monster, to check if he died or not
LUA:
 addEvent(removeBoss, 15 * 60 * 1000)

here a full script
LUA:
function addBoss()
    Game.createMonster("Orshabaal", Position(33000, 33000, 7), false, true)
end

function removeBoss(cid)
local creature = Creature(cid)
    if creature then
        creature:remove()
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    Game.broadcastMessage("Boss will be created in 5 minutes!", MESSAGE_STATUS_WARNING)
    addEvent(addBoss, 5 * 60 * 1000)
    addEvent(removeBoss, 15 * 60 * 1000) -this function, how can i put the boss here?
    return true
end
 
Solution
Create a variable outside to hold the boss id so you can access it outside of addBoss. I took the liberty of adding code to check if the boss exists before creating it, to make sure players can't spam the item.
LUA:
local bossId = nil

function addBoss()
    local monster = Game.createMonster("Demon", Position(33000, 33000, 7), false, true)
    bossId = monster and monster:getId() or nil
end

function removeBoss()
    local monster = Monster(bossId)
    if monster then
        monster:remove()
    end
end

function bossExists()
    return Monster(bossId) and true or false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not bossExists() then
        Game.broadcastMessage("Boss will be created in...
LUA:
local boosId = 0
function addBoss()
    local boss = Game.createMonster("Orshabaal", Position(33000, 33000, 7), false, true)
    if boss then
        boosId = boss:getId()
    end
end

function removeBoss()
    local creature = Creature(boosId)
    boosId = 0
    if creature then
        creature:remove()
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if boosId == 0 then
        Game.broadcastMessage("Boss will be created in 5 minutes!", MESSAGE_STATUS_WARNING)
        addEvent(addBoss, 5 * 60 * 1000)
        addEvent(removeBoss, 15 * 60 * 1000)
    else
        ---player:sendCancelMessage("Your message.")
    end
    return true
end
 
Last edited:
Create a variable outside to hold the boss id so you can access it outside of addBoss. I took the liberty of adding code to check if the boss exists before creating it, to make sure players can't spam the item.
LUA:
local bossId = nil

function addBoss()
    local monster = Game.createMonster("Demon", Position(33000, 33000, 7), false, true)
    bossId = monster and monster:getId() or nil
end

function removeBoss()
    local monster = Monster(bossId)
    if monster then
        monster:remove()
    end
end

function bossExists()
    return Monster(bossId) and true or false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not bossExists() then
        Game.broadcastMessage("Boss will be created in 5 minutes!", MESSAGE_STATUS_WARNING)
        addEvent(addBoss, 5 * 60 * 1000)
        addEvent(removeBoss, 15 * 60 * 1000)
    else
        player:sendCancelMessage("The boss is already spawned!")
    end
    return true
end
 
Solution

Similar threads

Back
Top