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.
160
Cut Webs/Wooden Bars #43
Searches around a player for webs/wooden bars and repeat cuts the first found until broken.
1.01kb | 32 lines.
local spider_web = { 182,183,2295,2296 }
local spider_web_cut = { 188,189,3145 } -- unused

UI.Button("Cut Web Example", function()
    cutWeb(pos())
end)
local web_tile = null
cut_macro = macro(1000, function()
    if not web_tile then return end
    local topThing = web_tile:getTopUseThing()
    if not topThing then return false end
    if table.find(spider_web, topThing:getId()) then
        useWith(3308, topThing)
    else
        cut_macro:setOff()
    end
end)
cut_macro:setOff()
function cutWeb(position)
    local dirs = { { 0, 1 },  { -1, 0 }, { 1, 0 }, { 1, -1 } ,{ -1, 1 },  { 1, 1 }, { -1, -1 }, { 0, -1 }}
    for i = 1, #dirs do
        local tile = g_map.getTile({ x = position.x - dirs[i][1], y = position.y - dirs[i][2], z = position.z })
        if tile then
            local topThing = tile:getTopUseThing()
            if topThing and table.find(spider_web, topThing:getId()) then
                web_tile = tile
                cut_macro:setOn()
                return
            end
        end
    end
end

01 Jul 2021