• 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 How to make Dwarven Pickaxe working?

Nyarl666

Member
Joined
Sep 25, 2022
Messages
63
Reaction score
7
Hi. How to get Dwarven Pickaxe (4874) to act like Pick?
Not literally. Check only this in [] and B inside. The problem is that it cannot be used. This cursor does not show up as USE can.

If I give it to a pick it works. For sure I forgot to add something, but I don't know where. TFS 1.4

I did this:

In actions.xml I add this:
XML:
<action itemid="4874" script="tools/pickaxe.lua" />

I add script in \data\actions\scripts pickaxe.lua
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    return onUsePickaxe(player, item, fromPosition, target, toPosition, isHotkey)
end

I add in script tool_gear.lua this:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if math.random(100) > 5 then
        return onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
        or onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
        or onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
       [B] or onUsePickaxe(player, item, fromPosition, target, toPosition, isHotkey)[/B]
        or onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
        or onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
        or onUseScythe(player, item, fromPosition, target, toPosition, isHotkey)
        or onUseKitchenKnife(player, item, fromPosition, target, toPosition, isHotkey)
    else
        player:say("Oh no! Your tool is jammed and can't be used for a minute.", TALKTYPE_MONSTER_SAY)
        player:addAchievementProgress("Bad Timming", 10)
        item:transform(item.itemid + 1)
        item:decay()
    end
    return true
end

and in \data\actions\lib actions.lua I add this:
Lua:
local wildGrowth = {1499, 11099} -- wild growth destroyable by machete
local jungleGrass = { -- grass destroyable by machete
    [2782] = 2781,
    [3985] = 3984,
    [19433] = 19431
}
local groundIds = {354, 355} -- pick usable ground
local sandIds = {231, 9059} -- desert sand
local holeId = { -- usable rope holes, for rope spots see global.lua
    294, 369, 370, 383, 392, 408, 409, 410, 427, 428, 429, 430, 462, 469, 470, 482,
    484, 485, 489, 924, 1369, 3135, 3136, 4835, 4837, 7933, 7938, 8170, 8249, 8250,
    8251, 8252, 8254, 8255, 8256, 8276, 8277, 8279, 8281, 8284, 8285, 8286, 8323,
    8567, 8585, 8595, 8596, 8972, 9606, 9625, 13190, 14461, 19519, 21536, 23713,
    26020
}
local holes = {468, 481, 483, 23712} -- holes opened by shovel
local fruits = {2673, 2674, 2675, 2676, 2677, 2678, 2679, 2680, 2681, 2682, 2684, 2685, 5097, 8839, 8840, 8841} -- fruits to make decorated cake with knife

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








[B]local rewards = {
    { item = 1294, count = 1, chance = 100 },
    { item = 2225, count = 1, chance = 100 },
    { item = 5944, count = 1, chance = 60 },
    { item = 5880, count = 1, chance = 60 },
    { item = 2157, count = 1, chance = 15 },
    { item = 2150, count = 1, chance = 15 },
    { item = 9970, count = 1, chance = 15 },
    { item = 2147, count = 1, chance = 15 },
    { item = 2146, count = 1, chance = 15 },
    { item = 2149, count = 1, chance = 15 },
    { item = 2145, count = 1, chance = 15 },
    { item = 8298, count = 1, chance = 10 },
    { item = 2154, count = 1, chance = 10 },
    { item = 2156, count = 1, chance = 10 },
    { item = 8299, count = 1, chance = 5 },
    { item = 8302, count = 1, chance = 5 },
    { item = 8303, count = 1, chance = 5 },
    { item = 8301, count = 1, chance = 4 },
    { item = 8310, count = 1, chance = 3 },
    { item = 2155, count = 1, chance = 3 },
    { item = 2158, count = 1, chance = 3 },
    { item = 2153, count = 1, chance = 1 }
}

local storage = 9001
local delay_timer = 900 -- 5 - 5 seconds, 300 - 5 minutes, 900 - 15 minutes, 1800 - 30 minutes, 3600 - 1 hour

function onUsePickaxe(player, item, fromPosition, target, toPosition, isHotkey)
   
    local cur_time, cur_storage = os.time(), player:getStorageValue(storage)[/B][/B][/B][/B][/B]
 
[B][B][B][B][B]    if cur_storage > cur_time then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can mining again in " .. os.date("!%Hh %Mm %Ss", cur_storage - cur_time) .. ".")
        return true
    end
   
    local function addbackstone()
    local stones = {5750, 5751, 5752, 5753, 5754}
    local stone = Game.createItem(stones[math.random(#stones)], 1, toPosition)
        stone:setActionId(40041)
    end
   
    if player:getLevel() < 10 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dont have the required level of 20 to mining.")
        return true
    end
   
    if not target then
        return false
    end
   
    if not target:isItem() then
        return false
    end

    if target.actionid ~= 40041 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You cannot use it here.')
        return false
    end
   
    if target.actionid == 40041 then
    local ran = math.random(100)
        if ran <= 10 then
            toPosition:sendMagicEffect(3)
            target:remove()
            addEvent(addbackstone, 120000)
            return true
        end
    end[/B][/B][/B][/B][/B]
 
[B][B][B][B][B]    local text = "You have found "
    for i = 1, #rewards do
        local rand = math.random(1000)
        if rand <= rewards[i].chance then
            player:addItem(rewards[i].item, rewards[i].count)
            if text ~= "You have found " then
                text = text .. ", "
            end
            text = text .. rewards[i].count .. " " .. ItemType(rewards[i].item):getName()
        end        
    end
    if text == "You have found " then
        text = text .. "nothing"
    end
    player:sendTextMessage(36, text .. ".")
    cur_time = cur_time + delay_timer
    player:setStorageValue(storage, cur_time)
    return true
end[/B]









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()) or tile:getItemById(14435) 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 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 randomValue = math.random(1, 100)
        if target.actionid == actionIds.sandHole and randomValue <= 20 then
            ground:transform(489)
            ground:decay()
        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
 
he said that in his version it's not, it must be an older version, I can't say either haha

I also don't know if from the beginning the item already came with the option or not

It was all added by me.
But maybe I am doing something wrong or somewhere else I need to add something?
 
Back
Top