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.
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:
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?
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?