• 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+ Lever Wall in Addevent

Fabi Marzan

Well-Known Member
Joined
Aug 31, 2020
Messages
135
Solutions
6
Reaction score
66
Good, here I have a problem that is simple but I still don't understand, how to use else or elseif.

The fact is that when you hit the lever the wall appears and when you hit it again it disappears, here for now it's fine.

My idea is that if the person hits the lever, the wall disappears, but if the person doesn't hit again, the wall will automatically be placed... so an addEvent would have to be placed on it.

Lua:
local config = {
    wall_id = (1304),
    pos_wall = Position(1017, 996, 6),
}
    
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)   
    local tile = Tile(config.pos_wall)
    if tile then
        local stone = tile:getItemById(config.wall_id)
        if stone then
        stone:remove()
        config.pos_wall:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido removida.")
        Item(item.uid):transform(1946)
    else
        Game.createItem(config.wall_id, 1, config.pos_wall)
        config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido renovada.")
        Item(item.uid):transform(1945)
        end   
    end
    return true
end

Then I have tried to place the Addevent, but the thing is how can I know if the tile (id) is not there then the addevent is executed, I don't know if I am explaining myself.

I have tried like this:

Code:
local config = {
    wall_id = (1304),
    pos_wall = Position(1016, 996, 7),
}
    
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)   
    local tile = Tile(config.pos_wall)
    if tile then
        local stone = tile:getItemById(config.wall_id)
        if stone then
        stone:remove()
        config.pos_wall:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido removida.")
        Item(item.uid):transform(1946)
    else
        Game.createItem(config.wall_id, 1, config.pos_wall)
        config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido renovada.")
        Item(item.uid):transform(1945)
        end   
    end
    
    
    addEvent(function()
    local tile = Tile(config.pos_wall)
    if tile then
    Game.createItem(config.wall_id, 1, config.pos_wall)
    config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
    Item(item.uid):transform(1945)
    end
end, 1500)

    return true
end

But even so, if the stone is there, another stone reappears on top of it, so I don't know if I have to use an else or elseif or it has nothing to do with it?
 
Solution
Lua:
local config = {
    wall_id = (1304),
    pos_wall = Position(1016, 996, 7),
}
 
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local tile = Tile(config.pos_wall)
    if tile then
        local stone = tile:getItemById(config.wall_id)
        if stone then
        stone:remove()
        config.pos_wall:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido removida.")
        Item(item.uid):transform(1946)
    else
        Game.createItem(config.wall_id, 1, config.pos_wall)
        config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido renovada.")
        Item(item.uid):transform(1945)...
Lua:
local config = {
    wall_id = (1304),
    pos_wall = Position(1016, 996, 7),
}
 
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local tile = Tile(config.pos_wall)
    if tile then
        local stone = tile:getItemById(config.wall_id)
        if stone then
        stone:remove()
        config.pos_wall:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido removida.")
        Item(item.uid):transform(1946)
    else
        Game.createItem(config.wall_id, 1, config.pos_wall)
        config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido renovada.")
        Item(item.uid):transform(1945)
        end
    end
 
 
    addEvent(function()
    local tile = Tile(config.pos_wall)
    local stone = tile and tile:getItemById(config.wall_id)
    if not stone then
    Game.createItem(config.wall_id, 1, config.pos_wall)
    config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
    Item(item.uid):transform(1945)
    end
end, 1500)

    return true
end

Try this, doesnt know if works, starting in new tfs functions.
The problem in the function is that youre not checking if the stone exist or not, only the "tile", tile can be everything in the position.

This is the function that check if the stone id exist in the tile position - where tile is the position and getItemById is the item that you will check
Lua:
    local tile = Tile(POSITION)
        local stone = tile:getItemById(ITEMID)

So "if stone then" is like: If stone exist then do that

Or "if not stone then" is like: if stone doesnt exist then do that
 
Last edited:
Solution
Lua:
local config = {
    wall_id = (1304),
    pos_wall = Position(1016, 996, 7),
}
 
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local tile = Tile(config.pos_wall)
    if tile then
        local stone = tile:getItemById(config.wall_id)
        if stone then
        stone:remove()
        config.pos_wall:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido removida.")
        Item(item.uid):transform(1946)
    else
        Game.createItem(config.wall_id, 1, config.pos_wall)
        config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "La stone ha sido renovada.")
        Item(item.uid):transform(1945)
        end
    end
 
 
    addEvent(function()
    local tile = Tile(config.pos_wall)
    local stone = tile and tile:getItemById(config.wall_id)
    if not stone then
    Game.createItem(config.wall_id, 1, config.pos_wall)
    config.pos_wall:sendMagicEffect(CONST_ME_TELEPORT)
    Item(item.uid):transform(1945)
    end
end, 1500)

    return true
end

Try this, doesnt know if works, starting in new tfs functions.
The problem in the function is that youre not checking if the stone exist or not, only the "tile", tile can be everything in the position.

This is the function that check if the stone id exist in the tile position - where tile is the position and getItemById is the item that you will check
Lua:
    local tile = Tile(POSITION)
        local stone = tile:getItemById(ITEMID)

So "if stone then" is like: If stone exist then do that

Or "if not stone then" is like: if stone doesnt exist then do that
Oh thanks, I understand. Thank you very much.
 
Back
Top