• 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!

Solved Lever script conversion to 1.2

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
the player is supposed to place item (5943) on alter & use lever to remove item, then teleport to pos.
As of right now, the teleport works. However the Item is not removed from pos & Msg does not work.

Code:
function doComparePositions(position, positionEx)
return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end

piece1pos = {x=1098, y=997, z=9, stackpos=2}
getpiece1 = getThingfromPos(piece1pos)

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then  
            if getpiece1.itemid == 5943 then
                if doComparePositions(getPlayerPosition(cid), {x = 1100, y = 996, z = 9}) then
                   doRemoveItem(getThingfromPos(getpiece1.uid))
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "MSG.")
                end
            end
                doTeleportThing(cid, {x = 1100, y = 992, z = 9})
    end
    return true
    end
 
Last edited:
As it is now the player is teleported regardless of whether there is an item on the altar or not. For one thing, the teleport is outside the if statement and for another you can not get the item when the script loads and use that to check. You should get the item that is there when the script executes.
Code:
local pos = {
    altar = Position({x=1098, y=997, z=9}),
    stand = Position({x = 1100, y = 996, z = 9}),
    teleportTo = Position({x = 1100, y = 992, z = 9})
}

function onUse(creature, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 and creature:isPlayer() then
        local topItem = Tile(pos.altar):getTopTopItem()
        if topItem.itemid == 5943 then
            if creature:getPosition():getDistance(pos.stand) == 0 then
                topItem:remove()
                creature:sendTextMessage(MESSAGE_INFO_DESCR, "MSG.")
                creature:teleportTo(pos.teleportTo)
            end
        end
    end
    return true
end
 
As it is now the player is teleported regardless of whether there is an item on the altar or not. For one thing, the teleport is outside the if statement and for another you can not get the item when the script loads and use that to check. You should get the item that is there when the script executes.
Code:
local pos = {
    altar = Position({x=1098, y=997, z=9}),
    stand = Position({x = 1100, y = 996, z = 9}),
    teleportTo = Position({x = 1100, y = 992, z = 9})
}

function onUse(creature, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 and creature:isPlayer() then
        local topItem = Tile(pos.altar):getTopTopItem()
        if topItem.itemid == 5943 then
            if creature:getPosition():getDistance(pos.stand) == 0 then
                topItem:remove()
                creature:sendTextMessage(MESSAGE_INFO_DESCR, "MSG.")
                creature:teleportTo(pos.teleportTo)
            end
        end
    end
    return true
end
Thank you for the assistance, however this script does not execute and no console errors.
 
local topItem = Tile(pos.altar):getTopTopItem()
if topItem.itemid == 5943 then
Something here is causing issues. Not sure as to what. If I remove this line & use lever, the alter is removed. I have tried setting a stackpos, but that doesn't resolve the issue.
 
Last edited:
Replace this line:
Code:
local topItem = Tile(pos.altar):getTopTopItem()
With this:
Code:
local topItem = Tile(pos.altar):getTopVisibleThing(creature)

I tested the script and Tile:getTopTopItem() and Tile:getTopDownItem() returns nil for some reason.
 
Back
Top