Your browser does not support JavaScript or its disabled!
Please turn it on, or be aware that some features on this website will not work correctly.
397
Use Lever on Item Drop #77
This will use a lever to the left of player if an item is dropped at the set location.
1.41kb | 43 lines.
local itemFloor = 1781
local itemPos = { x = 1003, y = 991, z = 7 }
local levers = { 2772, 2773 } -- lever to use  (if you can use the lever if its left or right, put both id's)

--------
-- use this or below
--------
macro(100, "Use Lever", function()
    local leverPos = pos()
    leverPos.x = leverPos.x - 1   -- x-1 is left of player x+1 == right of player
    local lever = g_map.getTile(leverPos)
    local item = g_map.getTile(itemPos)
    if not item or not lever then return false end

    local itemTop = item:getTopUseThing()
    local leverTop = lever:getTopUseThing()
    if not itemTop or not leverTop then return false end
    if itemTop:getId() == itemFloor then
        if table.contains(levers, leverTop:getId()) then
            delay(1000)
            g_game.use(leverTop)
        end
    end
end)
--------
-- or --
--------
macro(100, "Use Lever", function()
    local tile = g_map.getTile(itemPos)
    if not tile then return false end
    if isOnTile(itemFloor, tile) then
        local leverPos = pos()
        leverPos.x = leverPos.x - 1   -- x-1 is left of player x+1 == right of player
        local lever = g_map.getTile(leverPos)
        if not lever then return false end

        local leverTop = lever:getTopUseThing()
        if leverTop and table.contains(levers, leverTop:getId()) then
            delay(1000)
            g_game.use(leverTop)
        end
    end
end)

27 Dec 2021