TFS 1.X+ How do I remove the monster?

liqeen

Member
Joined
Nov 26, 2014
Messages
55
Reaction score
3
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
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
701
Reaction score
427
Location
United States
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.
 
OP
L

liqeen

Member
Joined
Nov 26, 2014
Messages
55
Reaction score
3
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
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
701
Reaction score
427
Location
United States
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:

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,211
Reaction score
750
Location
Arica - Chile
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?)
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
701
Reaction score
427
Location
United States
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.
 
OP
L

liqeen

Member
Joined
Nov 26, 2014
Messages
55
Reaction score
3
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!
 
Top