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

Respawn if getWorldTime() TFS 1.5 downgrade

Azerty

Active Member
Joined
Apr 15, 2022
Messages
307
Solutions
4
Reaction score
31
Good morning, I made this script for the midnight panther respawn only during the night, in game time, but I would like the panther to be removed after a certain time, in this case at 06:00 at dawn. Can anyone help me?

Lua:
local config = {
    bossName = "Midnight Panther",
    bossPos = Position(32841, 32706, 7),
}   

function onThink(creature, interval)
--    for i = 1, #t do
        if getWorldTime() >= 0400 then
            Game.createMonster(config.bossName, config.bossPos, true, true)
            elseif getWorldTime() >= 0600 then
                creature:remove()
        end
    return true
end
 
Try this:

Lua:
local config = {
    bossName = "Midnight Panther",
    bossPos = Position(32841, 32706, 7),
    spawnTime = "00:00", -- midnight
    removeTime = "06:00", -- 6am
}

function onThink(interval, lastExecution)
    local currentTime = os.date("%H:%M") -- get current server time in format HH:MM
    if currentTime == config.spawnTime then
        local boss = Game.createMonster(config.bossName, config.bossPos, true, true)
        if boss then
            print(config.bossName .. " has spawned!")
        else
            print("Failed to spawn " .. config.bossName .. ".")
        end
    elseif currentTime == config.removeTime then
        local creature = Creature(config.bossName)
        if creature then
            creature:remove()
            print(config.bossName .. " has been removed!")
        else
            print(config.bossName .. " not found to be removed.")
        end
    end
    return true
end

local interval = 5 * 60 * 1000 -- 5 minutes
local eventId = addEvent(onThink, interval)
 
Last edited:
Try this:

Lua:
local config = {
    bossName = "Midnight Panther",
    bossPos = Position(32841, 32706, 7),
    spawnTime = "00:00", -- midnight
    removeTime = "06:00", -- 6am
}

function onThink(creature, interval)
    local currentTime = os.date("%H:%M") -- get current server time in format HH:MM
    if currentTime == config.spawnTime then
        Game.createMonster(config.bossName, config.bossPos, true, true)
    elseif currentTime == config.removeTime then
        creature:remove()
    end
    return true
end
I think u need to set who is the creature before removing

Try
Lua:
local boss = Game.createMonster(..)

and

Lua:
boss:remove()
 
I think u need to set who is the creature before removing

Try
Lua:
local boss = Game.createMonster(..)

and

Lua:
boss:remove()
I've updated my previous post with the corrected code. Although, I want to mention that I haven't had a chance to test it myself and I only wrote it based on the documentation available.
 
Back
Top