• 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+ How do I remove the monster?

liqeen

Active Member
Joined
Nov 26, 2014
Messages
149
Solutions
1
Reaction score
28
Location
Poland
Hello how do I remove the monster after the event of lever reset?
I want to remove the demon from x y z pos after 10 seconds (like in script) but I can't use doRemoveCreature function. Can someone help?

Code:
local pos = {x=1420,  y=2513,  z=6, 23657}
local wall = 23657
local level = 70
local seconds = 10
local event = 0

local wall2 = 23656
local pos2 = {x=1419,  y=2513,  z=6, 23656}

local wall3 = 23657
local pos3 = {x=1418,  y=2513,  z=6, 23657}

local wall4 = 23655
local pos4 = {x=1417,  y=2513,  z=6, 23655}

local wall5 = 23655
local pos5 = {x=1416,  y=2513,  z=6, 23655}

local wall6 = 23656
local pos6 = {x=1415,  y=2513,  z=6, 23656}



local function reset(leverPos)
        local lever = getTileItemById(leverPos, 9826).uid
    doTransformItem(lever, 9825)
    doCreateItem(wall, 1, pos)
    doCreateItem(wall2, 1, pos2)
    doCreateItem(wall3, 1, pos3)
    doCreateItem(wall4, 1, pos4)
    doCreateItem(wall5, 1, pos5)
    doCreateItem(wall6, 1, pos6)
        doPlayerSendTextMessage(cid,21,"The pass has been closed!")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)


          if item.itemid == 9825 and getPlayerLevel(cid) >= level then
                doRemoveItem(getTileItemById(pos,wall).uid)
                doRemoveItem(getTileItemById(pos2,wall2).uid)
                doRemoveItem(getTileItemById(pos3,wall3).uid)
                doRemoveItem(getTileItemById(pos4,wall4).uid)
                doRemoveItem(getTileItemById(pos5,wall5).uid)
                doRemoveItem(getTileItemById(pos6,wall6).uid)
                Game.createMonster('Demon', Position(1414, 2514, 6))
                doPlayerSendTextMessage(cid,21,"You have opened the pass, Beware!")
                event = addEvent(reset, seconds * 1000, getThingPos(item.uid))
        doTransformItem(item.uid,item.itemid+1)
    elseif item.itemid == 9826 and getPlayerLevel(cid) >= level then
        stopEvent(event)
        doPlayerSendTextMessage(cid,21,"You have closed the pass!")
        doTransformItem(item.uid,item.itemid-1)
        doCreateItem(wall, 1, pos)
        doCreateItem(wall2, 1, pos2)
        doCreateItem(wall3, 1, pos3)
        doCreateItem(wall4, 1, pos4)
        doCreateItem(wall5, 1, pos5)
        doCreateItem(wall6, 1, pos6)
            end
return true
end
 
Solution
Well I was trying but i dont get it, dont know how to properly execute the function mob:remove() where exatcly to put it to make it work
You can try this out. It's untested so let me know how it goes.
Lua:
local positions = {
    {x = 1420,  y = 2513,  z = 6, id = 23657},
    {x = 1419,  y = 2513,  z = 6, id = 23656},
    {x = 1418,  y = 2513,  z = 6, id = 23657},
    {x = 1417,  y = 2513,  z = 6, id = 23655},
    {x = 1416,  y = 2513,  z = 6, id = 23655},
    {x = 1415,  y = 2513,  z = 6, id = 23656}
}

local mob_position = Position(1414, 2514, 6)
local level_minimum = 70
local event_duration = 10
local event_uid = 0
local mob_uid = 0

local function resetWalls(lever_pos)
    for key, position in pairs(positions) do...
Hello how do I remove the monster after the event of lever reset?
I want to remove the demon from x y z pos after 10 seconds (like in script) but I can't use doRemoveCreature function. Can someone help?

Code:
local pos = {x=1420,  y=2513,  z=6, 23657}
local wall = 23657
local level = 70
local seconds = 10
local event = 0

local wall2 = 23656
local pos2 = {x=1419,  y=2513,  z=6, 23656}

local wall3 = 23657
local pos3 = {x=1418,  y=2513,  z=6, 23657}

local wall4 = 23655
local pos4 = {x=1417,  y=2513,  z=6, 23655}

local wall5 = 23655
local pos5 = {x=1416,  y=2513,  z=6, 23655}

local wall6 = 23656
local pos6 = {x=1415,  y=2513,  z=6, 23656}



local function reset(leverPos)
        local lever = getTileItemById(leverPos, 9826).uid
    doTransformItem(lever, 9825)
    doCreateItem(wall, 1, pos)
    doCreateItem(wall2, 1, pos2)
    doCreateItem(wall3, 1, pos3)
    doCreateItem(wall4, 1, pos4)
    doCreateItem(wall5, 1, pos5)
    doCreateItem(wall6, 1, pos6)
        doPlayerSendTextMessage(cid,21,"The pass has been closed!")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)


          if item.itemid == 9825 and getPlayerLevel(cid) >= level then
                doRemoveItem(getTileItemById(pos,wall).uid)
                doRemoveItem(getTileItemById(pos2,wall2).uid)
                doRemoveItem(getTileItemById(pos3,wall3).uid)
                doRemoveItem(getTileItemById(pos4,wall4).uid)
                doRemoveItem(getTileItemById(pos5,wall5).uid)
                doRemoveItem(getTileItemById(pos6,wall6).uid)
                Game.createMonster('Demon', Position(1414, 2514, 6))
                doPlayerSendTextMessage(cid,21,"You have opened the pass, Beware!")
                event = addEvent(reset, seconds * 1000, getThingPos(item.uid))
        doTransformItem(item.uid,item.itemid+1)
    elseif item.itemid == 9826 and getPlayerLevel(cid) >= level then
        stopEvent(event)
        doPlayerSendTextMessage(cid,21,"You have closed the pass!")
        doTransformItem(item.uid,item.itemid-1)
        doCreateItem(wall, 1, pos)
        doCreateItem(wall2, 1, pos2)
        doCreateItem(wall3, 1, pos3)
        doCreateItem(wall4, 1, pos4)
        doCreateItem(wall5, 1, pos5)
        doCreateItem(wall6, 1, pos6)
            end
return true
end
You can't get it from the position cause the demon will have likely moved. You need to use the creatures uid, so I would do something like:
Lua:
local mob = Game.createMonster('Demon', Position(1414, 2514, 6))
-- Save the uid somewhere that can be used later
config.mob_uid = mob.uid
-- Later in event function pick up uid
local mob = Creature(config.mob_uid)
if mob then
    mob:remove()
end
Hope that makes sense.
 
You can't get it from the position cause the demon will have likely moved. You need to use the creatures uid, so I would do something like:
Lua:
local mob = Game.createMonster('Demon', Position(1414, 2514, 6))
-- Save the uid somewhere that can be used later
config.mob_uid = mob.uid
-- Later in event function pick up uid
local mob = Creature(config.mob_uid)
if mob then
    mob:remove()
end
Hope that makes sense.
Well I was trying but i dont get it, dont know how to properly execute the function mob:remove() where exatcly to put it to make it work
 
Well I was trying but i dont get it, dont know how to properly execute the function mob:remove() where exatcly to put it to make it work
You can try this out. It's untested so let me know how it goes.
Lua:
local positions = {
    {x = 1420,  y = 2513,  z = 6, id = 23657},
    {x = 1419,  y = 2513,  z = 6, id = 23656},
    {x = 1418,  y = 2513,  z = 6, id = 23657},
    {x = 1417,  y = 2513,  z = 6, id = 23655},
    {x = 1416,  y = 2513,  z = 6, id = 23655},
    {x = 1415,  y = 2513,  z = 6, id = 23656}
}

local mob_position = Position(1414, 2514, 6)
local level_minimum = 70
local event_duration = 10
local event_uid = 0
local mob_uid = 0

local function resetWalls(lever_pos)
    for key, position in pairs(positions) do
        Game.createItem(position.id, 1, Position(position.x, position.y, position.z))
    end

    local mob = Creature(mob_uid)
    if mob and mob:getName() == "Demon" then
        mob:remove()
    end
    mob_uid = 0

    local tile = Tile(lever_pos)
    if tile then
        local lever = tile:getItemById(9826)
        if lever then
            lever:transform(9825)
        end
    end
    event_uid = 0
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getLevel() < 70 then
        return false
    end

    if item.itemid == 9825 then
        for key, position in pairs(positions) do
            local tile = Tile(position.x, position.y, position.z)
            if tile then
                local wall = tile:getItemById(position.id)
                if wall then
                    wall:remove()
                end
            end
        end

        local mob = Game.createMonster("Demon", mob_position, false, true)
        if mob then
            mob_uid = mob.uid
        end

        event_uid = addEvent(resetWalls, event_duration * 1000, toPosition)
        item:transform(9826)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have opened the pass. Beware!")
    elseif item.itemid == 9826 then
        stopEvent(event_uid)
        resetWalls(toPosition)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The pass has been closed!")
    end
    return true
end
 
Last edited:
Solution
You can try this out. It's untested so let me know how it goes.
Lua:
local positions = {
    {x = 1420,  y = 2513,  z = 6, id = 23657},
    {x = 1419,  y = 2513,  z = 6, id = 23656},
    {x = 1418,  y = 2513,  z = 6, id = 23657},
    {x = 1417,  y = 2513,  z = 6, id = 23655},
    {x = 1416,  y = 2513,  z = 6, id = 23655},
    {x = 1415,  y = 2513,  z = 6, id = 23656}
}

local mob_position = Position(1414, 2514, 6)
local level_minimum = 70
local event_duration = 10
local event_uid = 0
local mob_uid = 0

local function resetWalls(lever_pos)
    for key, position in pairs(positions) do
        Game.createItem(position.id, 1, Position(position.x, position.y, position.z))
    end

    local mob = Creature(mob_uid)
    if mob and mob:getName() == "Demon" then
        mob:remove()
    end

    local tile = Tile(lever_pos)
    if tile then
        local lever = tile:getItemById(9826)
        if lever then
            lever:transform(9825)
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getLevel() < 70 then
        return false
    end

    if item.itemid == 9825 then
        for key, position in pairs(positions) do
            local tile = Tile(position.x, position.y, position.z)
            if tile then
                local wall = tile:getItemById(position.id)
                if wall then
                    wall:remove()
                end
            end
        end

        local mob = Game.createMonster("Demon", mob_position, false, true)
        if mob then
            mob_uid = mob.uid
        end

        event_uid = addEvent(resetWalls, event_duration * 1000, toPosition)
        item:transform(9826)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have opened the pass. Beware!")
    elseif item.itemid == 9826 then
        stopEvent(event_uid)
        event_uid = 0
        resetWalls(toPosition)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The pass has been closed!")
    end
    return true
end
you can also pass the monster id through that function and use it inside it :p (maybe?)
 
you can also pass the monster id through that function and use it inside it :p (maybe?)
For sure, I was going to do that but since he has the option to switch the lever back manually I had to cancel the addEvent and start it from there instead and I don't have the creatures uid at that point.
 
You can try this out. It's untested so let me know how it goes.
Lua:
local positions = {
    {x = 1420,  y = 2513,  z = 6, id = 23657},
    {x = 1419,  y = 2513,  z = 6, id = 23656},
    {x = 1418,  y = 2513,  z = 6, id = 23657},
    {x = 1417,  y = 2513,  z = 6, id = 23655},
    {x = 1416,  y = 2513,  z = 6, id = 23655},
    {x = 1415,  y = 2513,  z = 6, id = 23656}
}

local mob_position = Position(1414, 2514, 6)
local level_minimum = 70
local event_duration = 10
local event_uid = 0
local mob_uid = 0

local function resetWalls(lever_pos)
    for key, position in pairs(positions) do
        Game.createItem(position.id, 1, Position(position.x, position.y, position.z))
    end

    local mob = Creature(mob_uid)
    if mob and mob:getName() == "Demon" then
        mob:remove()
    end
    mob_uid = 0

    local tile = Tile(lever_pos)
    if tile then
        local lever = tile:getItemById(9826)
        if lever then
            lever:transform(9825)
        end
    end
    event_uid = 0
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getLevel() < 70 then
        return false
    end

    if item.itemid == 9825 then
        for key, position in pairs(positions) do
            local tile = Tile(position.x, position.y, position.z)
            if tile then
                local wall = tile:getItemById(position.id)
                if wall then
                    wall:remove()
                end
            end
        end

        local mob = Game.createMonster("Demon", mob_position, false, true)
        if mob then
            mob_uid = mob.uid
        end

        event_uid = addEvent(resetWalls, event_duration * 1000, toPosition)
        item:transform(9826)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have opened the pass. Beware!")
    elseif item.itemid == 9826 then
        stopEvent(event_uid)
        resetWalls(toPosition)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The pass has been closed!")
    end
    return true
end
Works perfect, thanks!
 
Back
Top