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

Lua Shovel

clouf

Member
Joined
Jul 5, 2012
Messages
166
Reaction score
23
Hello, my lua script for shovel is not working like I wanted.
For now is openning hole always, doesn't matter if is field on it or any other item:
hole.png
I would like players first destroy field, move items or disintegrate first before open hole (only ground tile?)

shovel.lua
Lua:
local holes = {468, 481, 483}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if toPosition.x == CONTAINER_POSITION then
        return false
    end

    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 isInArray(holes, groundId) then
        ground:transform(groundId + 1)
        ground:decay()

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
    elseif groundId == 231 then
        local randomValue = math.random(1, 100)
        if randomValue == 1 then
            Game.createItem(2159, 1, toPosition)
        elseif randomValue > 95 then
            Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end
 
Hello, my lua script for shovel is not working like I wanted.
For now is openning hole always, doesn't matter if is field on it or any other item:
View attachment 84507
I would like players first destroy field, move items or disintegrate first before open hole (only ground tile?)

shovel.lua
Lua:
local holes = {468, 481, 483}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if toPosition.x == CONTAINER_POSITION then
        return false
    end

    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 isInArray(holes, groundId) then
        ground:transform(groundId + 1)
        ground:decay()

        toPosition.z = toPosition.z + 1
        tile:relocateTo(toPosition)
    elseif groundId == 231 then
        local randomValue = math.random(1, 100)
        if randomValue == 1 then
            Game.createItem(2159, 1, toPosition)
        elseif randomValue > 95 then
            Game.createMonster("Scarab", toPosition)
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false
    end

    return true
end

above
Lua:
local ground = tile:getGround()
add
Lua:
if tile:getCreatureCount() > 0 then
    return false
end

if tile:getItemCount() > 0 then
    return false
end
 
above
Lua:
local ground = tile:getGround()
add
Lua:
if tile:getCreatureCount() > 0 then
    return false
end

if tile:getItemCount() > 0 then
    return false
end
Oh, what about all this fluids sources (like blood)? Should i add them to some whitelist?
 
Oh, what about all this fluids sources (like blood)? Should i add them to some whitelist?
at top of script, add
Lua:
shovel_whitelist = {1111, 2222, 3333} -- itemIds that will be ignored, and shovel can pass through

above
Lua:
local ground = tile:getGround()
add
Lua:
local topVisible = tile:getTopVisibleThing(player)

if not topVisible:isItem() then
    return false
end

if not table.contains(shovel_whitelist, topVisible:getId()) then
    return false
end

-- edit
Could possibly also try..
it might do all the 'splash' fields for you.
Lua:
local topVisible = tile:getTopVisibleThing(player)

if not topVisible:isItem() then
    return false
end

local topVisibleItemId = topVisible:getId()
if ItemType(topVisibleItemId):getGroup() ~= ITEM_GROUP_SPLASH and not table.contains(shovel_whitelist, topVisibleItemId) then
    return false
end
 
Last edited:
Hi guys! I have the same problem, but with my pick. I use TFS 1.5 downgrade to 8.6 by Nekiro. This is my fragment of code:
Lua:
local groundIds = {354, 355} -- pick usable ground
local lava = {
    Position(2023, 2078, 11),
    Position(2024, 2078, 11),
    Position(2028, 2075, 11)
}
local pick_whitelist = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030} -- itemIds that will be ignored, and pick can pass through (all splashes at the moment)
function onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
    --[[1]]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

    --[[2]]if target.itemid == 1304 then
        --The Pits of Inferno Quest
        if target.uid == 1022 then
            for i = 1, #lava do
                Game.createItem(5815, 1, lava[i])
            end
            target:transform(2256)
            toPosition:sendMagicEffect(CONST_ME_SMOKE)
        end
    end

    --[[3]]local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local topVisible = tile:getTopVisibleThing(player)
    if not topVisible:isItem() then
        return false
    end

    if not table.contains(pick_whitelist, topVisible:getId()) 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

end

Section --[[1]] and section --[[2]] are working perfectly, but section --[[3]] isn't working. I can't use my pick on the ground (id: 354 with actionid). I can use pick when there is item from pick_whitelist, only. How can I solve it?
 
Hi guys! I have the same problem, but with my pick. I use TFS 1.5 downgrade to 8.6 by Nekiro. This is my fragment of code:
Lua:
local groundIds = {354, 355} -- pick usable ground
local lava = {
    Position(2023, 2078, 11),
    Position(2024, 2078, 11),
    Position(2028, 2075, 11)
}
local pick_whitelist = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030} -- itemIds that will be ignored, and pick can pass through (all splashes at the moment)
function onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
    --[[1]]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

    --[[2]]if target.itemid == 1304 then
        --The Pits of Inferno Quest
        if target.uid == 1022 then
            for i = 1, #lava do
                Game.createItem(5815, 1, lava[i])
            end
            target:transform(2256)
            toPosition:sendMagicEffect(CONST_ME_SMOKE)
        end
    end

    --[[3]]local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local topVisible = tile:getTopVisibleThing(player)
    if not topVisible:isItem() then
        return false
    end

    if not table.contains(pick_whitelist, topVisible:getId()) 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

end

Section --[[1]] and section --[[2]] are working perfectly, but section --[[3]] isn't working. I can't use my pick on the ground (id: 354 with actionid). I can use pick when there is item from pick_whitelist, only. How can I solve it?
Lua:
local groundIds = {354, 355} -- pick usable ground
local lava = {
    Position(2023, 2078, 11),
    Position(2024, 2078, 11),
    Position(2028, 2075, 11)
}
local pick_whitelist = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030} -- itemIds that will be ignored, and pick can pass through (all splashes at the moment)
function onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
    --[[1]]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

    --[[2]]if target.itemid == 1304 then
        --The Pits of Inferno Quest
        if target.uid == 1022 then
            for i = 1, #lava do
                Game.createItem(5815, 1, lava[i])
            end
            target:transform(2256)
            toPosition:sendMagicEffect(CONST_ME_SMOKE)
        end
    end

    --[[3]]local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local topVisible = tile:getTopVisibleThing(player)
    if not topVisible:isItem() then
        return false
    end

    if table.contains(pick_whitelist, topVisible:getId()) then
        topVisible = tile:getGround()
		if not topVisible then
			return false
		end
    end

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

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

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

	return false
end
 
Back
Top