Good afternoon, I made this lever script that when using it, it returns to its original position in a few seconds and the MagicWall reappears. However, if there is a player or a monster in the MagicWall SQM, it returns an error and the lever locks, only returning when the server restarts. Does anyone know how do I make it so that when the MagicWall appears, the player or monster will be pushed to the SQM from the north direction?
Lua:
local doorPosition = Position(33075, 32591, 3)
local function revertCarrotAndLever(position, carrotPosition)
local leverItem = Tile(position):getItemById(1946)
if leverItem then
leverItem:transform(1945)
end
local carrotItem = Tile(carrotPosition):getItemById(104)
if carrotItem then
Game.createItem(1498, 1, doorPosition)
--carrotItem:remove()
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid == 1945 then
if getPlayerItemCount(player, 13118) >= 1 then
local tile = doorPosition:getTile()
if tile then
local MagicWall = tile:getItemById(1498)
if MagicWall then
MagicWall:remove()
doorPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You paved the way!')
item:transform(1946)
--Game.createItem(1498, 1, doorPosition)
addEvent(revertCarrotAndLever, 10 * 1000, toPosition, doorPosition)
end
end
local doorItem = Tile(doorPosition):getItemById(1498)
if doorItem then
--Game.createItem(1498, 1, doorPosition)
doorItem:transform(104)
end
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You do not have the Chayenne\'s magical key!')
doTargetCombatHealth(0, player, COMBAT_FIREDAMAGE, -200, -200, CONST_ME_HITBYFIRE)
end
elseif item.itemid == 1946 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You need to wait few seconds to use again.')
return true
end
end