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

TFS 1.X+ Scarabs on Free Area

bpm91

Advanced OT User
Joined
May 23, 2019
Messages
1,046
Solutions
7
Reaction score
180
Location
Brazil
YouTube
caruniawikibr
i would like to know how i could do when using shovel in the sand, just have scarab and scarab coin in premium areas, because the floor is the same id of premium area and free area.
tfs 1.5 7.72
 
Solution
you could add a rage script or you could copy sand sprite id and add a new one then replace it in the wareaas that you don't want to be able wont be hard.
you could add a rage script or you could copy sand sprite id and add a new one then replace it in the wareaas that you don't want to be able wont be hard.
 
Last edited:
Solution
Just do a range check..
LUA:
local premiumAreas = {
    {from = Position(1000, 1000, 7), to = Position(1000, 1000, 7)}, -- from = top left corner
    {from = Position(1000, 1000, 7), to = Position(1000, 1000, 7)}, -- to = bottom right corner
}
LUA:
local position = tile_you_are_shoveling_/_using

local premiumArea = false
for i = 1, #premiumAreas do
    if position:isInRange(premiumAreas[i].from, premiumAreas[i].to) then
        premiumArea = true
        break
    end
end

if premiumArea then
    -- premium area
else
    -- not premium area
end
 
sorry to up
LUA:
did this i still can dig scarab and things in thais for example, lend me a hand please and thanks
function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    local groundId = ground:getId()
    if table.contains(holes, groundId) then
        ground:transform(groundId + 1)
        ground:decay()

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 7932 then -- large hole
        target:transform(7933)
        target:decay()
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 20230 then -- swamp digging
        if (player:getStorageValue(PlayerStorageKeys.swampDigging)) <= os.time() then
            local chance = math.random(100)
            if chance >= 1 and chance <= 42 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a dead snake.")
                player:addItem(3077)
            elseif chance >= 43 and chance <= 79 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a small diamond.")
                player:addItem(2145)
            elseif chance >= 80 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a leech.")
                player:addItem(20138)
            end
            player:setStorageValue(PlayerStorageKeys.swampDigging, os.time() + 7 * 24 * 60 * 60)
            player:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS)
        end
    elseif table.contains(sandIds, groundId) then
              local posSand = {
                fromPos = Position(33018, 32894, 7),
                toPos = Position(33306, 32530, 7)
        }
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
            elseif randomValue <= 3 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createMonster("Scarab", toPosition)

        --elseif randomValue == 1 then
        --    Game.createItem(2159, 1, toPosition)
        --    player:addAchievementProgress("Gold Digger", 100)
        --elseif randomValue > 95 then
        --    Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end
 
sorry to up
LUA:
did this i still can dig scarab and things in thais for example, lend me a hand please and thanks
function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    local groundId = ground:getId()
    if table.contains(holes, groundId) then
        ground:transform(groundId + 1)
        ground:decay()

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 7932 then -- large hole
        target:transform(7933)
        target:decay()
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 20230 then -- swamp digging
        if (player:getStorageValue(PlayerStorageKeys.swampDigging)) <= os.time() then
            local chance = math.random(100)
            if chance >= 1 and chance <= 42 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a dead snake.")
                player:addItem(3077)
            elseif chance >= 43 and chance <= 79 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a small diamond.")
                player:addItem(2145)
            elseif chance >= 80 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a leech.")
                player:addItem(20138)
            end
            player:setStorageValue(PlayerStorageKeys.swampDigging, os.time() + 7 * 24 * 60 * 60)
            player:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS)
        end
    elseif table.contains(sandIds, groundId) then
              local posSand = {
                fromPos = Position(33018, 32894, 7),
                toPos = Position(33306, 32530, 7)
        }
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
            elseif randomValue <= 3 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createMonster("Scarab", toPosition)

        --elseif randomValue == 1 then
        --    Game.createItem(2159, 1, toPosition)
        --    player:addAchievementProgress("Gold Digger", 100)
        --elseif randomValue > 95 then
        --    Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end
LUA:
local posSand = {
    fromPos = Position(33018, 32894, 7),
    toPos = Position(33306, 32530, 7)
}

your Y position is incorrect.
 
sorry for bumping, tried this.
LUA:
ROPE_SPOT = {384, 418}
OPENED_HOLE = {294, 383, 392, 469, 470, 482, 484, 485, 489}
CLOSED_HOLE = {468, 481, 483}
OPENED_TRAP = {462}
DOWN_LADDER = {369, 370, 408, 409, 427, 428, 430, 924, 3135, 3136}
JUNGLE_GRASS_TRANSFORM = {2782, 3985}
JUNGLE_GRASS_REMOVE = {1499}

POOLS = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030}

WATER = {490, 4608, 491, 492, 493, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627,
628, 629, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621,
4622, 4623, 4624, 4625, 4664, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}

SWAMP = {602, 603, 604, 605, 4691, 4692, 4693, 4694, 4695, 4696, 4697, 4698, 4699, 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4749, 4750, 4751, 4752, 4753, 4754, 4755, 4758}

OVEN_ON = {1786, 1788, 1790, 1792}
LADDER = {1386, 3678}
DECAYTO_ITEM_INCREMENT = {2041, 2044, 2047, 2050, 2052, 2054, 2162}

--LOCKED_DOORS = {1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 3545, 3545, 3542}

CONSTRUCTIONS = {
    [3901] = 1666, [3902] = 1670, [3903] = 1652, [3904] = 1674, [3905] = 1658,
    [3906] = 3813, [3907] = 3817, [3908] = 1619, [3909] = 1615, [3910] = 2105,
    [3911] = 1614, [3912] = 3806, [3913] = 3807, [3914] = 3809, [3915] = 1716,
    [3916] = 1724, [3917] = 1732, [3918] = 1775, [3919] = 1774, [3920] = 1750,
    [3921] = 3832, [3922] = 2095, [3923] = 2098, [3924] = 2064, [3925] = 2582,
    [3926] = 2117, [3927] = 1728, [3928] = 1442, [3929] = 1446, [3930] = 1447,
    [3931] = 2034, [3932] = 2604, [3933] = 2080, [3934] = 2084, [3935] = 3821,
    [3936] = 3811, [3937] = 2101, [3938] = 3812, [5086] = 5046, [5087] = 5055,
    [5088] = 5056,
}

FOODS = {
    [2328] = {84, "Gulp."},    [2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
    [2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
    [2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
    [2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
    [2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
    [2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
    [2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
    [2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [2769] = {60, "Crunch."}, [2787] = {108, "Crunch."},
    [2788] = {48, "Crunch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
    [2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
    [2796] = {300, "Crunch."}
}

SMALL_SAPPHIRE    = 2146
SMALL_RUBY    = 2147
SMALL_EMERALD    = 2149
SMALL_AMETHYST    = 2150

MUSICAL_INSTRUMENTS = {2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2332, 2364, 2367, 2368, 2370, 2371, 2372, 2373, 2374, 3951, 3953, 3957}

NORTH_BEDS = {1754, 1758, 1762, 1766, 3836, 3840}
SOUTH_BEDS = {1755, 1759, 1763, 1767, 3837, 3841}
WEST_BEDS = {1756, 1760, 1764, 1768, 3838, 3842}
EAST_BEDS = {1757, 1761, 1765, 1769, 3839, 3843}

BREAKABLE_BY_WEAPONS = {
    [1619] = { remainings = 2255, chance = 15 },
    [1650] = { remainings = 2253, chance = 20 },
    [1651] = { remainings = 2253, chance = 20 },
    [1652] = { remainings = 2253, chance = 20 },
    [1653] = { remainings = 2253, chance = 20 }, 
    [3798] = { remainings = 3959, chance = 20 }, 
    [3799] = { remainings = 3958, chance = 20 },
}

function destroyItem(player, target, toPosition)
    if type(target) ~= "userdata" or not target:isItem() then
        return false
    end

    if target:hasAttribute(ITEM_ATTRIBUTE_UNIQUEID) or target:hasAttribute(ITEM_ATTRIBUTE_ACTIONID) then
        return false
    end

    if toPosition.x == CONTAINER_POSITION then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    local destroyId = ItemType(target.itemid):getDestroyId()
    if destroyId == 0 then
        return false
    end

    if math.random(7) == 1 then
        local item = Game.createItem(destroyId, 1, toPosition)
        if item then
            item:decay()
        end

        -- Move items outside the container
        if target:isContainer() then
            for i = target:getSize() - 1, 0, -1 do
                local containerItem = target:getItem(i)
                if containerItem then
                    containerItem:moveTo(toPosition)
                end
            end
        end

        target:remove(1)
    end

    toPosition:sendMagicEffect(CONST_ME_POFF)
    return true
end

function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    if not targetId then
        return true
    end

    if table.contains(wildGrowth, targetId) then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        target:remove()
        return true
    end

    local grass = jungleGrass[targetId]
    if grass then
        target:transform(grass)
        target:decay()
        player:addAchievementProgress("Nothing Can Stop Me", 100)
        return true
    end

    return destroyItem(player, target, toPosition)
end

function onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 11227 then -- shiny stone refining
        local chance = math.random(1, 100)
        if chance == 1 then
            player:addItem(ITEM_CRYSTAL_COIN) -- 1% chance of getting crystal coin
        elseif chance <= 6 then
            player:addItem(ITEM_GOLD_COIN) -- 5% chance of getting gold coin
        elseif chance <= 51 then
            player:addItem(ITEM_PLATINUM_COIN) -- 45% chance of getting platinum coin
        else
            player:addItem(2145) -- 49% chance of getting small diamond
        end
        player:addAchievementProgress("Petrologist", 100)
        target:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        target:remove(1)
        return true
    end

    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    if table.contains(groundIds, ground.itemid) and ground.actionid == actionIds.pickHole then
        ground:transform(392)
        ground:decay()
        toPosition:sendMagicEffect(CONST_ME_POFF)

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
        return true
    end

    -- Ice fishing hole
    if ground.itemid == 7200 then
        ground:transform(7236)
        ground:decay()
        toPosition:sendMagicEffect(CONST_ME_HITAREA)
        return true
    end

    return false
end

function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()

    if ground and table.contains(ropeSpots, ground:getId()) then
        tile = Tile(toPosition:moveUpstairs())
        if not tile then
            return false
        end

        if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
            return true
        end

        player:teleportTo(toPosition, false)
        return true
    end

    if table.contains(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if not tile then
            return false
        end

        local thing = tile:getTopVisibleThing()
        if not thing then
            return true
        end

        --if thing:isPlayer() then
        if thing:isPlayer() or thing:isMonster() then --agregado rope monster
            if Tile(toPosition:moveUpstairs()):queryAdd(thing) ~= RETURNVALUE_NOERROR then
                return false
            end

            return thing:teleportTo(toPosition, false)
        elseif thing:isItem() and thing:getType():isMovable() then
            return thing:moveTo(toPosition:moveUpstairs())
        end

        return true
    end

    return false
end

function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    local groundId = ground:getId()
    if table.contains(holes, groundId) then
        ground:transform(groundId + 1)
        ground:decay()

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 7932 then -- large hole
        target:transform(7933)
        target:decay()
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 20230 then -- swamp digging
        if (player:getStorageValue(PlayerStorageKeys.swampDigging)) <= os.time() then
            local chance = math.random(100)
            if chance >= 1 and chance <= 42 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a dead snake.")
                player:addItem(3077)
            elseif chance >= 43 and chance <= 79 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a small diamond.")
                player:addItem(2145)
            elseif chance >= 80 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a leech.")
                player:addItem(20138)
            end
            player:setStorageValue(PlayerStorageKeys.swampDigging, os.time() + 7 * 24 * 60 * 60)
            player:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS)
        end
    elseif table.contains(sandIds, groundId) then
              local posSand = {
                fromPos = Position(32957,32347, 7), --{x = 32957, y = 32347, z = 7}
                toPos = Position(33345, 32908, 7)  --{x = 33345, y = 32908, z = 7}
        }
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
            elseif randomValue <= 3 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createMonster("Scarab", toPosition)

        --elseif randomValue == 1 then
        --    Game.createItem(2159, 1, toPosition)
        --    player:addAchievementProgress("Gold Digger", 100)
        --elseif randomValue > 95 then
        --    Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end

function onUseScythe(player, item, fromPosition, target, toPosition, isHotkey)
    if not table.contains({2550, 10513}, item.itemid) then
        return false
    end

    if target.itemid == 2739 then -- wheat
        target:transform(2737)
        target:decay()
        Game.createItem(2694, 1, toPosition) -- bunch of wheat
        player:addAchievementProgress("Happy Farmer", 200)
        return true
    end
    if target.itemid == 5465 then -- burning sugar cane
        target:transform(5464)
        target:decay()
        Game.createItem(5467, 1, toPosition) -- bunch of sugar cane
        player:addAchievementProgress("Natural Sweetener", 50)
        return true
    end
    return destroyItem(player, target, toPosition)
end

function onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
    if not table.contains({2416, 10515}, item.itemid) then
        return false
    end

    return destroyItem(player, target, toPosition)
end

function onUseKitchenKnife(player, item, fromPosition, target, toPosition, isHotkey)
    if not table.contains({2566, 10511, 10515}, item.itemid) then
        return false
    end

    if table.contains(fruits, target.itemid) and player:removeItem(6278, 1) then
        target:remove(1)
        player:addItem(6279, 1)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        return true
    end

    return false
end
does not work, want to dig only in darashia and anrahmun
 
Last edited:
sorry for bumping, tried this.
LUA:
ROPE_SPOT = {384, 418}
OPENED_HOLE = {294, 383, 392, 469, 470, 482, 484, 485, 489}
CLOSED_HOLE = {468, 481, 483}
OPENED_TRAP = {462}
DOWN_LADDER = {369, 370, 408, 409, 427, 428, 430, 924, 3135, 3136}
JUNGLE_GRASS_TRANSFORM = {2782, 3985}
JUNGLE_GRASS_REMOVE = {1499}

POOLS = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030}

WATER = {490, 4608, 491, 492, 493, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627,
628, 629, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621,
4622, 4623, 4624, 4625, 4664, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}

SWAMP = {602, 603, 604, 605, 4691, 4692, 4693, 4694, 4695, 4696, 4697, 4698, 4699, 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4749, 4750, 4751, 4752, 4753, 4754, 4755, 4758}

OVEN_ON = {1786, 1788, 1790, 1792}
LADDER = {1386, 3678}
DECAYTO_ITEM_INCREMENT = {2041, 2044, 2047, 2050, 2052, 2054, 2162}

--LOCKED_DOORS = {1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 3545, 3545, 3542}

CONSTRUCTIONS = {
    [3901] = 1666, [3902] = 1670, [3903] = 1652, [3904] = 1674, [3905] = 1658,
    [3906] = 3813, [3907] = 3817, [3908] = 1619, [3909] = 1615, [3910] = 2105,
    [3911] = 1614, [3912] = 3806, [3913] = 3807, [3914] = 3809, [3915] = 1716,
    [3916] = 1724, [3917] = 1732, [3918] = 1775, [3919] = 1774, [3920] = 1750,
    [3921] = 3832, [3922] = 2095, [3923] = 2098, [3924] = 2064, [3925] = 2582,
    [3926] = 2117, [3927] = 1728, [3928] = 1442, [3929] = 1446, [3930] = 1447,
    [3931] = 2034, [3932] = 2604, [3933] = 2080, [3934] = 2084, [3935] = 3821,
    [3936] = 3811, [3937] = 2101, [3938] = 3812, [5086] = 5046, [5087] = 5055,
    [5088] = 5056,
}

FOODS = {
    [2328] = {84, "Gulp."},    [2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
    [2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
    [2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
    [2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
    [2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
    [2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
    [2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
    [2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [2769] = {60, "Crunch."}, [2787] = {108, "Crunch."},
    [2788] = {48, "Crunch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
    [2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
    [2796] = {300, "Crunch."}
}

SMALL_SAPPHIRE    = 2146
SMALL_RUBY    = 2147
SMALL_EMERALD    = 2149
SMALL_AMETHYST    = 2150

MUSICAL_INSTRUMENTS = {2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2332, 2364, 2367, 2368, 2370, 2371, 2372, 2373, 2374, 3951, 3953, 3957}

NORTH_BEDS = {1754, 1758, 1762, 1766, 3836, 3840}
SOUTH_BEDS = {1755, 1759, 1763, 1767, 3837, 3841}
WEST_BEDS = {1756, 1760, 1764, 1768, 3838, 3842}
EAST_BEDS = {1757, 1761, 1765, 1769, 3839, 3843}

BREAKABLE_BY_WEAPONS = {
    [1619] = { remainings = 2255, chance = 15 },
    [1650] = { remainings = 2253, chance = 20 },
    [1651] = { remainings = 2253, chance = 20 },
    [1652] = { remainings = 2253, chance = 20 },
    [1653] = { remainings = 2253, chance = 20 },
    [3798] = { remainings = 3959, chance = 20 },
    [3799] = { remainings = 3958, chance = 20 },
}

function destroyItem(player, target, toPosition)
    if type(target) ~= "userdata" or not target:isItem() then
        return false
    end

    if target:hasAttribute(ITEM_ATTRIBUTE_UNIQUEID) or target:hasAttribute(ITEM_ATTRIBUTE_ACTIONID) then
        return false
    end

    if toPosition.x == CONTAINER_POSITION then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    local destroyId = ItemType(target.itemid):getDestroyId()
    if destroyId == 0 then
        return false
    end

    if math.random(7) == 1 then
        local item = Game.createItem(destroyId, 1, toPosition)
        if item then
            item:decay()
        end

        -- Move items outside the container
        if target:isContainer() then
            for i = target:getSize() - 1, 0, -1 do
                local containerItem = target:getItem(i)
                if containerItem then
                    containerItem:moveTo(toPosition)
                end
            end
        end

        target:remove(1)
    end

    toPosition:sendMagicEffect(CONST_ME_POFF)
    return true
end

function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    if not targetId then
        return true
    end

    if table.contains(wildGrowth, targetId) then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        target:remove()
        return true
    end

    local grass = jungleGrass[targetId]
    if grass then
        target:transform(grass)
        target:decay()
        player:addAchievementProgress("Nothing Can Stop Me", 100)
        return true
    end

    return destroyItem(player, target, toPosition)
end

function onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 11227 then -- shiny stone refining
        local chance = math.random(1, 100)
        if chance == 1 then
            player:addItem(ITEM_CRYSTAL_COIN) -- 1% chance of getting crystal coin
        elseif chance <= 6 then
            player:addItem(ITEM_GOLD_COIN) -- 5% chance of getting gold coin
        elseif chance <= 51 then
            player:addItem(ITEM_PLATINUM_COIN) -- 45% chance of getting platinum coin
        else
            player:addItem(2145) -- 49% chance of getting small diamond
        end
        player:addAchievementProgress("Petrologist", 100)
        target:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        target:remove(1)
        return true
    end

    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    if table.contains(groundIds, ground.itemid) and ground.actionid == actionIds.pickHole then
        ground:transform(392)
        ground:decay()
        toPosition:sendMagicEffect(CONST_ME_POFF)

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
        return true
    end

    -- Ice fishing hole
    if ground.itemid == 7200 then
        ground:transform(7236)
        ground:decay()
        toPosition:sendMagicEffect(CONST_ME_HITAREA)
        return true
    end

    return false
end

function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()

    if ground and table.contains(ropeSpots, ground:getId()) then
        tile = Tile(toPosition:moveUpstairs())
        if not tile then
            return false
        end

        if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
            return true
        end

        player:teleportTo(toPosition, false)
        return true
    end

    if table.contains(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if not tile then
            return false
        end

        local thing = tile:getTopVisibleThing()
        if not thing then
            return true
        end

        --if thing:isPlayer() then
        if thing:isPlayer() or thing:isMonster() then --agregado rope monster
            if Tile(toPosition:moveUpstairs()):queryAdd(thing) ~= RETURNVALUE_NOERROR then
                return false
            end

            return thing:teleportTo(toPosition, false)
        elseif thing:isItem() and thing:getType():isMovable() then
            return thing:moveTo(toPosition:moveUpstairs())
        end

        return true
    end

    return false
end

function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground then
        return false
    end

    local groundId = ground:getId()
    if table.contains(holes, groundId) then
        ground:transform(groundId + 1)
        ground:decay()

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 7932 then -- large hole
        target:transform(7933)
        target:decay()
        player:addAchievementProgress("The Undertaker", 500)
    elseif target.itemid == 20230 then -- swamp digging
        if (player:getStorageValue(PlayerStorageKeys.swampDigging)) <= os.time() then
            local chance = math.random(100)
            if chance >= 1 and chance <= 42 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a dead snake.")
                player:addItem(3077)
            elseif chance >= 43 and chance <= 79 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a small diamond.")
                player:addItem(2145)
            elseif chance >= 80 then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a leech.")
                player:addItem(20138)
            end
            player:setStorageValue(PlayerStorageKeys.swampDigging, os.time() + 7 * 24 * 60 * 60)
            player:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS)
        end
    elseif table.contains(sandIds, groundId) then
              local posSand = {
                fromPos = Position(32957,32347, 7), --{x = 32957, y = 32347, z = 7}
                toPos = Position(33345, 32908, 7)  --{x = 33345, y = 32908, z = 7}
        }
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
            elseif randomValue <= 3 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
            Game.createMonster("Scarab", toPosition)

        --elseif randomValue == 1 then
        --    Game.createItem(2159, 1, toPosition)
        --    player:addAchievementProgress("Gold Digger", 100)
        --elseif randomValue > 95 then
        --    Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end

function onUseScythe(player, item, fromPosition, target, toPosition, isHotkey)
    if not table.contains({2550, 10513}, item.itemid) then
        return false
    end

    if target.itemid == 2739 then -- wheat
        target:transform(2737)
        target:decay()
        Game.createItem(2694, 1, toPosition) -- bunch of wheat
        player:addAchievementProgress("Happy Farmer", 200)
        return true
    end
    if target.itemid == 5465 then -- burning sugar cane
        target:transform(5464)
        target:decay()
        Game.createItem(5467, 1, toPosition) -- bunch of sugar cane
        player:addAchievementProgress("Natural Sweetener", 50)
        return true
    end
    return destroyItem(player, target, toPosition)
end

function onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
    if not table.contains({2416, 10515}, item.itemid) then
        return false
    end

    return destroyItem(player, target, toPosition)
end

function onUseKitchenKnife(player, item, fromPosition, target, toPosition, isHotkey)
    if not table.contains({2566, 10511, 10515}, item.itemid) then
        return false
    end

    if table.contains(fruits, target.itemid) and player:removeItem(6278, 1) then
        target:remove(1)
        player:addItem(6279, 1)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        return true
    end

    return false
end
does not work, want to dig only in darashia and anrahmun
LUA:
    elseif table.contains(sandIds, groundId) then
        local posSands = {
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)},
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}, -- can add more positions here
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}
        }
        local playerIsIn_posSands = false
        local playerPos = player:getPosition()
        for i = 1, #posSands do
            print("sand fromPosition = Position(" .. posSands[i].fromPos.x .. ", " .. posSands[i].fromPos.y .. ", " .. posSands[i].fromPos.z .. ")")
            print("- player position = Position(" .. playerPos.x .. ", " .. playerPos.y .. ", " .. playerPos.z .. ")")
            print("- sand toPosition = Position(" .. posSands[i].toPos).x .. ", " .. posSands[i].toPos).y .. ", " .. posSands[i].toPos).z .. ")")
            if playerPos:isInRange(posSands[i].fromPos, posSands[i].toPos) then
                playerIsIn_posSands = true
                print("Player is in the premium area.")
                break
            end
        end
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
        elseif randomValue <= 3 and playerIsIn_posSands then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and playerIsIn_posSands then
            Game.createMonster("Scarab", toPosition)
    
        --elseif randomValue == 1 then
        --    Game.createItem(2159, 1, toPosition)
        --    player:addAchievementProgress("Gold Digger", 100)
        --elseif randomValue > 95 then
        --    Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)

Made it possible to use multiple 'squares' of positions.
Also added 4 prints, so you can check console and verify that it's working as intended.
 
I created a sand with a different id, and used it in the premmy area, and rookgard, so I don't have problems with scarab in the free area and rook
 
LUA:
    elseif table.contains(sandIds, groundId) then
        local posSands = {
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)},
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}, -- can add more positions here
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}
        }
        local playerIsIn_posSands = false
        local playerPos = player:getPosition()
        for i = 1, #posSands do
            print("sand fromPosition = Position(" .. posSands[i].fromPos.x .. ", " .. posSands[i].fromPos.y .. ", " .. posSands[i].fromPos.z .. ")")
            print("- player position = Position(" .. playerPos.x .. ", " .. playerPos.y .. ", " .. playerPos.z .. ")")
            print("- sand toPosition = Position(" .. posSands[i].toPos).x .. ", " .. posSands[i].toPos).y .. ", " .. posSands[i].toPos).z .. ")")
            if playerPos:isInRange(posSands[i].fromPos, posSands[i].toPos) then
                playerIsIn_posSands = true
                print("Player is in the premium area.")
                break
            end
        end
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
        elseif randomValue <= 3 and playerIsIn_posSands then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and playerIsIn_posSands then
            Game.createMonster("Scarab", toPosition)
   
        --elseif randomValue == 1 then
        --    Game.createItem(2159, 1, toPosition)
        --    player:addAchievementProgress("Gold Digger", 100)
        --elseif randomValue > 95 then
        --    Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)

Made it possible to use multiple 'squares' of positions.
Also added 4 prints, so you can check console and verify that it's working as intended.
not working. sorry, posted another script at first.
LUA:
function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId, targetActionId = target.itemid, target.actionid
    if isInArray(holes, targetId) then
        target:transform(targetId + 1)
        target:decay()

  
elseif isInArray(sandIds, groundId) then
        local posSands = {
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)},
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}, -- can add more positions here
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}
        }
        local playerIsIn_posSands = false
        local playerPos = player:getPosition()
        for i = 1, #posSands do
            print("sand fromPosition = Position(" .. posSands[i].fromPos.x .. ", " .. posSands[i].fromPos.y .. ", " .. posSands[i].fromPos.z .. ")")
            print("- player position = Position(" .. playerPos.x .. ", " .. playerPos.y .. ", " .. playerPos.z .. ")")
            print("- sand toPosition = Position(" .. posSands[i].toPos).x .. ", " .. posSands[i].toPos).y .. ", " .. posSands[i].toPos).z .. ")")
            if playerPos:isInRange(posSands[i].fromPos, posSands[i].toPos) then
                playerIsIn_posSands = true
                print("Player is in the premium area.")
                break
           end
        end
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
        elseif randomValue <= 3 and playerIsIn_posSands then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and playerIsIn_posSands then
            Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)


        -- Wrath of the emperor quest
    elseif targetId == 351 and targetActionId == 8024 then
        player:addItem(12297, 1)
        player:say("You dig out a handful of earth from this sacred place.", TALKTYPE_MONSTER_SAY)

    -- RookgaardTutorialIsland
    elseif targetId == 8579 and player:getStorageValue(PlayerStorageKeys.RookgaardTutorialIsland.tutorialHintsStorage) < 20 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You dug a hole! Walk onto it as long as it is open to jump down into the forest cave.')
        player:setStorageValue(PlayerStorageKeys.RookgaardTutorialIsland.tutorialHintsStorage, 19)
        Position(32070, 32266, 7):sendMagicEffect(CONST_ME_TUTORIALARROW)
        Position(32070, 32266, 7):sendMagicEffect(CONST_ME_TUTORIALSQUARE)
        target:transform(469)
        addEvent(revertItem, 30 * 1000, toPosition, 469, 8579)

    -- Gravedigger Quest
    elseif targetActionId == 4654 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission49) == 1 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission50) < 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You found a piece of the scroll. You pocket it quickly.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:addItem(21250, 1)
        player:setStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission50, 1)

    elseif targetActionId == 4668 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission69) == 1 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission70) < 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'A torn scroll piece emerges. Probably gnawed off by rats.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:addItem(21250, 1)
        player:setStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission70, 1)

    -- ???
    elseif targetActionId == 50118 then
        local wagonItem = Tile(Position(32717, 31492, 11)):getItemById(7131)
        if wagonItem then
            Game.createItem(8749, 1, wagonItem:getPosition())
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end

    elseif targetId == 8749 then
        local coalItem = Tile(Position(32699, 31492, 11)):getItemById(8749)
        if coalItem then
            coalItem:remove(1)
            toPosition:sendMagicEffect(CONST_ME_POFF)

            local crucibleItem = Tile(Position(32699, 31494, 11)):getItemById(8642)
            if crucibleItem then
                crucibleItem:setActionId(50119)
            end
        end

    elseif isInArray({9632, 20230, 17672, 18586, 18580}, targetId) then
        if player:getStorageValue(PlayerStorageKeys.SwampDiggingTimeout) >= os.time() then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            return false
        end

        local config = { {from = 1, to = 39, itemId = 2817}, {from = 40, to = 79, itemId = 2145}, {from = 80, to = 100, itemId = 20138} }
        local chance = math.random(100)

        for i = 1, #config do
            local randItem = config[i]
            if chance >= randItem.from and chance <= randItem.to then
                player:addItem(randItem.itemId, 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You dug up a ' .. ItemType(randItem.itemId):getName() .. '.')
                player:setStorageValue(PlayerStorageKeys.SwampDiggingTimeout, os.time() + 604800)
                toPosition:sendMagicEffect(CONST_ME_GREEN_RINGS)
                break
            end
        end

    elseif targetId == 103 and targetActionId == 4205 then
        if player:getStorageValue(PlayerStorageKeys.TibiaTales.IntoTheBonePit) ~= 1 then
            return false
        end

        local remains = Game.createItem(2248, 1, toPosition)
        if remains then
            remains:setActionId(4206)
        end
        toPosition:sendMagicEffect(CONST_ME_HITAREA)
        addEvent(removeRemains, 60000, toPosition)

        elseif targetId == 22674 then
        if not player:removeItem(5091, 1) then
            return false
        end

        target:transform(5731)
        target:decay()
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end
 
not working. sorry, posted another script at first.
LUA:
function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId, targetActionId = target.itemid, target.actionid
    if isInArray(holes, targetId) then
        target:transform(targetId + 1)
        target:decay()

 
elseif isInArray(sandIds, groundId) then
        local posSands = {
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)},
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}, -- can add more positions here
            {fromPos = Position(32957,32347, 7), toPos = Position(33345, 32908, 7)}
        }
        local playerIsIn_posSands = false
        local playerPos = player:getPosition()
        for i = 1, #posSands do
            print("sand fromPosition = Position(" .. posSands[i].fromPos.x .. ", " .. posSands[i].fromPos.y .. ", " .. posSands[i].fromPos.z .. ")")
            print("- player position = Position(" .. playerPos.x .. ", " .. playerPos.y .. ", " .. playerPos.z .. ")")
            print("- sand toPosition = Position(" .. posSands[i].toPos).x .. ", " .. posSands[i].toPos).y .. ", " .. posSands[i].toPos).z .. ")")
            if playerPos:isInRange(posSands[i].fromPos, posSands[i].toPos) then
                playerIsIn_posSands = true
                print("Player is in the premium area.")
                break
           end
        end
        local randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
        elseif randomValue <= 3 and playerIsIn_posSands then
            Game.createItem(2159, 1, toPosition)
            player:addAchievementProgress("Gold Digger", 100)
        elseif randomValue > 95 and playerIsIn_posSands then
            Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)


        -- Wrath of the emperor quest
    elseif targetId == 351 and targetActionId == 8024 then
        player:addItem(12297, 1)
        player:say("You dig out a handful of earth from this sacred place.", TALKTYPE_MONSTER_SAY)

    -- RookgaardTutorialIsland
    elseif targetId == 8579 and player:getStorageValue(PlayerStorageKeys.RookgaardTutorialIsland.tutorialHintsStorage) < 20 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You dug a hole! Walk onto it as long as it is open to jump down into the forest cave.')
        player:setStorageValue(PlayerStorageKeys.RookgaardTutorialIsland.tutorialHintsStorage, 19)
        Position(32070, 32266, 7):sendMagicEffect(CONST_ME_TUTORIALARROW)
        Position(32070, 32266, 7):sendMagicEffect(CONST_ME_TUTORIALSQUARE)
        target:transform(469)
        addEvent(revertItem, 30 * 1000, toPosition, 469, 8579)

    -- Gravedigger Quest
    elseif targetActionId == 4654 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission49) == 1 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission50) < 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You found a piece of the scroll. You pocket it quickly.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:addItem(21250, 1)
        player:setStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission50, 1)

    elseif targetActionId == 4668 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission69) == 1 and player:getStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission70) < 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'A torn scroll piece emerges. Probably gnawed off by rats.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:addItem(21250, 1)
        player:setStorageValue(PlayerStorageKeys.GravediggerOfDrefia.Mission70, 1)

    -- ???
    elseif targetActionId == 50118 then
        local wagonItem = Tile(Position(32717, 31492, 11)):getItemById(7131)
        if wagonItem then
            Game.createItem(8749, 1, wagonItem:getPosition())
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end

    elseif targetId == 8749 then
        local coalItem = Tile(Position(32699, 31492, 11)):getItemById(8749)
        if coalItem then
            coalItem:remove(1)
            toPosition:sendMagicEffect(CONST_ME_POFF)

            local crucibleItem = Tile(Position(32699, 31494, 11)):getItemById(8642)
            if crucibleItem then
                crucibleItem:setActionId(50119)
            end
        end

    elseif isInArray({9632, 20230, 17672, 18586, 18580}, targetId) then
        if player:getStorageValue(PlayerStorageKeys.SwampDiggingTimeout) >= os.time() then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            return false
        end

        local config = { {from = 1, to = 39, itemId = 2817}, {from = 40, to = 79, itemId = 2145}, {from = 80, to = 100, itemId = 20138} }
        local chance = math.random(100)

        for i = 1, #config do
            local randItem = config[i]
            if chance >= randItem.from and chance <= randItem.to then
                player:addItem(randItem.itemId, 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You dug up a ' .. ItemType(randItem.itemId):getName() .. '.')
                player:setStorageValue(PlayerStorageKeys.SwampDiggingTimeout, os.time() + 604800)
                toPosition:sendMagicEffect(CONST_ME_GREEN_RINGS)
                break
            end
        end

    elseif targetId == 103 and targetActionId == 4205 then
        if player:getStorageValue(PlayerStorageKeys.TibiaTales.IntoTheBonePit) ~= 1 then
            return false
        end

        local remains = Game.createItem(2248, 1, toPosition)
        if remains then
            remains:setActionId(4206)
        end
        toPosition:sendMagicEffect(CONST_ME_HITAREA)
        addEvent(removeRemains, 60000, toPosition)

        elseif targetId == 22674 then
        if not player:removeItem(5091, 1) then
            return false
        end

        target:transform(5731)
        target:decay()
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end
What shows in console?

There should be prints.
 
The test code Xikini posted for you has a line with unwanted closing parentheses, change:
LUA:
print("- sand toPosition = Position(" .. posSands[i].toPos).x .. ", " .. posSands[i].toPos).y .. ", " .. posSands[i].toPos).z .. ")")
to
LUA:
print("- sand toPosition = Position(" .. posSands[i].toPos.x .. ", " .. posSands[i].toPos.y .. ", " .. posSands[i].toPos.z .. ")")
 
The test code Xikini posted for you has a line with unwanted closing parentheses, change:
LUA:
print("- sand toPosition = Position(" .. posSands[i].toPos).x .. ", " .. posSands[i].toPos).y .. ", " .. posSands[i].toPos).z .. ")")
to
LUA:
print("- sand toPosition = Position(" .. posSands[i].toPos.x .. ", " .. posSands[i].toPos.y .. ", " .. posSands[i].toPos.z .. ")")

What shows in console?

There should be prints.

Working now! thank you both
Edit: Is there a way to disable the poof is player tries to dig outside premium area?
 
Just move the sendMagicEffect inside anything if statement that is checking for playerIsIn_posSands:
LUA:
elseif randomValue <= 3 and playerIsIn_posSands then
    Game.createItem(2159, 1, toPosition)
    player:addAchievementProgress("Gold Digger", 100)
    toPosition:sendMagicEffect(CONST_ME_POFF)
elseif randomValue > 95 and playerIsIn_posSands then
    Game.createMonster("Scarab", toPosition)
    toPosition:sendMagicEffect(CONST_ME_POFF)
end

Or just wrap it in its own if statement later on:
LUA:
if playerIsIn_posSands then
    toPosition:sendMagicEffect(CONST_ME_POFF)
end
 
Just move the sendMagicEffect inside anything if statement that is checking for playerIsIn_posSands:
LUA:
elseif randomValue <= 3 and playerIsIn_posSands then
    Game.createItem(2159, 1, toPosition)
    player:addAchievementProgress("Gold Digger", 100)
    toPosition:sendMagicEffect(CONST_ME_POFF)
elseif randomValue > 95 and playerIsIn_posSands then
    Game.createMonster("Scarab", toPosition)
    toPosition:sendMagicEffect(CONST_ME_POFF)
end

Or just wrap it in its own if statement later on:
LUA:
if playerIsIn_posSands then
    toPosition:sendMagicEffect(CONST_ME_POFF)
end
thank you ! it works as i want
 

Similar threads

Back
Top