• 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+ Pick for mining system

anderkrox

New Member
Joined
May 14, 2020
Messages
21
Reaction score
1
I need to adapt this code to be used with a pick.
I also need the character to be unable to move for twenty seconds, unable to use spells, unable to attack, and finally, unable to leave the game ...
And one more thing ... When the stone is mined, I need another one to appear at the site after twenty minutes.
Currently, this is my script:
Lua:
local stone_id = 19959

function vinteMinutos(toPosition) -- Recreate the stone after 20 minutes.
    Game.createItem(stone_id, 1, toPosition)
    return true
end

function vinteVezes(playerID, toPosition) -- Repeat this function every second. Repeat this twenty times.
    local player = Player(playerID)
    if player:getStorageValue(mining) <= 20 then
        toPosition:sendMagicEffect(CONST_ME_BLOCKHIT) -- Effect while mining.
        player:setStorageValue(mining, player:getStorageValue(mining) + 1)
        player:addItem(2225, 1, true) -- Piece of Iron
        addEvent(vinteVezes, 1 * 1000, playerID, toPosition) -- Perform this function after 1 second.
    else
        -- Remove stone.
        player:setStorageValue(mining, 0)
        player:setStorageValue(started, 0)
        addEvent(vinteMinutos, 20 * 60 * 1000, toPosition) -- Perform this function after 20 minutes.
    end
    return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local miningSkill = player:getStorageValue(SKILL_MINERADOR)
    local random = math.random(1, 100000)
    local chance = (miningSkill / 1.5)

    if player:getStorageValue(started) == 1 then
        player.sendCancelMessage(player, "Ja esta minerando.")
    else
        if chance < 10000 then chance = 10000 end
        if random <= chance then
            player:setStorageValue(ESTIMA, getPlayerStorageValue(player, ESTIMA) + 1) -- Adds a reputation point.
            player:setStorageValue(started, 1)
            vinteVezes(player:getId(), toPosition)
            local G_SKILL_MINERADOR = player:getStorageValue(SKILL_MINERADOR)
            local max = 100000
            if math.random(1, max) <= (max / (G_SKILL_MINERADOR / 4)) then
                player:setStorageValue(SKILL_MINERADOR, G_SKILL_MINERADOR + 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Habilidade como minerador: ".. G_SKILL_MINERADOR ..".")
            end
        else
            toPosition:sendMagicEffect(CONST_ME_POFF) -- Effect while mining.
            player.sendCancelMessage(player, "Falha.")
            addEvent(vinteMinutos, 20 * 60 * 1000, toPosition) -- Perform this function after 20 minutes.
        end
    end
    return true
end

-- To do:
-- It makes it impossible for the character to move for twenty seconds.
-- It makes it impossible for the character to use spells for twenty seconds.
-- Impossible for the character to attack for twenty seconds.
-- It prevents the character from leaving the game for twenty seconds.
 
Solution
Lua:
local config = {
    quarrytype = 19959,         -- What is the identity of our stone?
    hibernate = 20 * 60 * 1000, -- How long the stone must wait before respawning?
    endurance = 20,             -- How many swings of the pick will the stone endure?
    mineblood = 2225,           -- What item does our stone bleed? -- Piece of Iron
    swingrate = 1 * 1000,       -- How soon before the next swing of the players pick?
    maxchance = 100000,         -- What is the upper range of our random number?
}

local messages = {
    cancel = "Ja esta minerando.",
    failure = "Falha.",
    success = function(si) return string.format("Habilidade como minerador: %s.", si) end,
}

-- Add a reputation point
function estima(player)...
I've edited the script, and now I've the problem:
Lua Script Error: [Action Interface]
data/actions/scripts/tools/minerar.lua:eek:nUse
data/actions/scripts/tools/minerar.lua:10: attempt to call global 'Target' (a nil value)
stack traceback:
[C]: in function 'Target'
data/actions/scripts/tools/minerar.lua:10: in function 'vinteVezes'
data/actions/scripts/tools/minerar.lua:37: in function <data/actions/scripts/tools/minerar.lua:25>

Script:
Lua:
local stone_id = 19959

function vinteMinutos(toPosition) -- Recreate the stone after 20 minutes.
    Game.createItem(stone_id, 1, toPosition)   
    return true
end

function vinteVezes(playerID, targetID, toPosition) -- Repeat this function every second. Repeat this twenty times.
    local player = Player(playerID)
    local target = Target(targetID)
    if player:getStorageValue(mining) <= 20 then
        toPosition:sendMagicEffect(CONST_ME_BLOCKHIT) -- Effect while mining.
        player:setStorageValue(mining, player:getStorageValue(mining) + 1)
        player:addItem(2225, 1, true) -- Piece of Iron
        addEvent(vinteVezes, 1 * 1000, playerID, targetID, toPosition) -- Perform this function after 1 second.
    else
        target:remove(-1) -- Remove stone.       
        player:setStorageValue(mining, 0)
        player:setStorageValue(started, 0)
        addEvent(vinteMinutos, 20 * 60 * 1000, toPosition) -- Perform this function after 20 minutes.
    end
    return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local miningSkill = player:getStorageValue(SKILL_MINERADOR)
    local random = math.random(1, 100000)
    local chance = (miningSkill / 1.5)

    if player:getStorageValue(started) == 1 then
        player.sendCancelMessage(player, "Ja esta minerando.")
    else
        if chance < 10000 then chance = 10000 end
        if random <= chance then
            player:setStorageValue(ESTIMA, getPlayerStorageValue(player, ESTIMA) + 1) -- Adds a reputation point.
            player:setStorageValue(started, 1)
            vinteVezes(player:getId(), target:getId(), toPosition)
            local G_SKILL_MINERADOR = player:getStorageValue(SKILL_MINERADOR)
            local max = 100000
            if math.random(1, max) <= (max / (G_SKILL_MINERADOR / 4)) then
                player:setStorageValue(SKILL_MINERADOR, G_SKILL_MINERADOR + 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Habilidade como minerador: ".. G_SKILL_MINERADOR ..".")
            end
        else
            toPosition:sendMagicEffect(CONST_ME_POFF)
            player.sendCancelMessage(player, "Falha.")

        end
    end
    return true
end

-- To do:
-- It makes it impossible for the character to move for twenty seconds.
-- It makes it impossible for the character to use spells for twenty seconds.
-- Impossible for the character to attack for twenty seconds.
-- It prevents the character from leaving the game for twenty seconds.
 
Lua:
local config = {
    quarrytype = 19959,         -- What is the identity of our stone?
    hibernate = 20 * 60 * 1000, -- How long the stone must wait before respawning?
    endurance = 20,             -- How many swings of the pick will the stone endure?
    mineblood = 2225,           -- What item does our stone bleed? -- Piece of Iron
    swingrate = 1 * 1000,       -- How soon before the next swing of the players pick?
    maxchance = 100000,         -- What is the upper range of our random number?
}

local messages = {
    cancel = "Ja esta minerando.",
    failure = "Falha.",
    success = function(si) return string.format("Habilidade como minerador: %s.", si) end,
}

-- Add a reputation point
function estima(player)
    player:setStorageValue(ESTIMA, getPlayerStorageValue(player, ESTIMA) + 1)
end

-- Regenerate the stone after set time
function regenMine(toPosition)
    return addEvent(Game.createItem, config.hibernate, config.quarrytype, 1, toPosition)
end

-- Lock the player into mining recursion until stones endurance is spent
function miningCycle(playerID, toPosition)
    local player = Player(playerID)

    if player:getStorageValue(mining) <= config.endurance then
        player:addItem(config.mineblood, 1, true)
        player:setStorageValue(mining, player:getStorageValue(mining) + 1)
        -- Queue recursion
        addEvent(miningCycle, config.swingrate, playerID, toPosition)
        return toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
    else
        -- Remove stone
        player:setStorageValue(mining, 0)
        player:setStorageValue(started, 0)
        -- Queue regeneration
        return regenMine(toPosition)
    end
end

-- Immobilize player until mining cycle is complete
-- Silence player until mining cycle is complete
-- Pacify player until mining cycle is complete
-- Logblock player until mining cycle is complete
function commenceCraftTask(playerID, toPosition)
    local player = Player(playerID)
    local variant = Variant(player:getName())

    local petrific = Condition(CONDITION_PARALYZE)
    local logblock = Condition(CONDITION_INFIGHT)
    local pacified = Condition(CONDITION_PACIFIED)
    local silenced = Condition(CONDITION_MUTED)
    local maglock1 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock2 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock3 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock4 = Condition(CONDITION_SPELLGROUPCOOLDOWN)

    petrific:setParameter(CONDITION_PARAM_TICKS, 20000)
    logblock:setParameter(CONDITION_PARAM_TICKS, 20000)
    pacified:setParameter(CONDITION_PARAM_TICKS, 20000)
    silenced:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock1:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock2:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock3:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock4:setParameter(CONDITION_PARAM_TICKS, 20000)

    petrific:setParameter(CONDITION_PARAM_SPEED, -400)
    maglock1:setParameter(CONDITION_PARAM_SUBID, 1) -- SPELLGROUP_ATTACK
    maglock2:setParameter(CONDITION_PARAM_SUBID, 2) -- SPELLGROUP_HEALING
    maglock3:setParameter(CONDITION_PARAM_SUBID, 3) -- SPELLGROUP_SUPPORT
    maglock4:setParameter(CONDITION_PARAM_SUBID, 4) -- SPELLGROUP_SPECIAL

    local pickswing = Combat()
    pickswing:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
    pickswing:setParameter(COMBAT_PARAM_AGGRESSIVE, true)
    pickswing:addCondition(petrific)
    pickswing:addCondition(logblock)
    pickswing:addCondition(pacified)
    pickswing:addCondition(silenced)
    pickswing:addCondition(maglock1)
    pickswing:addCondition(maglock2)
    pickswing:addCondition(maglock3)
    pickswing:addCondition(maglock4)

    return pickswing:execute(player, variant), miningCycle(playerID, toPosition)
end



function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local miningSkill = player:getStorageValue(SKILL_MINERADOR)
    local random = math.random(1, config.maxchance)
    local chance = (miningSkill / 1.5)

    if player:getStorageValue(started) == 1 then
        player.sendCancelMessage(player, messages.cancel)
    else
        chance = math.min(chance, 10000)
        if random <= chance then
            estima(player)
            player:setStorageValue(started, 1)
            if math.random(1, max) <= (max / (miningSkill / 4)) then
                miningSkill = miningSkill + 1
                player:setStorageValue(SKILL_MINERADOR, miningSkill)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, messages.success(miningSkill))
            end
            commenceCraftTask(player:getId(), toPosition)
        else
            regenMine(toPosition) -- Queue regen
            player.sendCancelMessage(player, messages.failure)
            -- Biff it
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end
    end
    return true
end
 
Solution
I made minor modifications to the script, and tried to add the function to remove the stone, but it is not working.
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/tools/minerar.lua:37: attempt to index global 'target' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/tools/minerar.lua:37: in function <data/actions/scripts/tools/minerar.lua:27>

Currently the script looks like this:
Lua:
local config = {
    quarrytype = 19959,             -- What is the identity of our stone?
    hibernate = 20 * 60 * 1000,     -- How long the stone must wait before respawning?
    endurance = 20,                 -- How many swings of the pick will the stone endure?
    mineblood = 5880,               -- What item does our stone bleed? -- Iron Ore
    swingrate = 1 * 1000,           -- How soon before the next swing of the players pick?
    maxchance = 100000,             -- What is the upper range of our random number?
}

local messages = {
    cancel = "Ja esta minerando.",
    failure = "Falha.",
    success = function(si) return string.format("Habilidade como minerador: %s.", si) end,
}

-- Add a reputation point
function estima(player)
    player:setStorageValue(ESTIMA, getPlayerStorageValue(player, ESTIMA) + 1)
end

-- Regenerate the stone after set time
function regenMine(toPosition)
    return addEvent(Game.createItem, config.hibernate, config.quarrytype, 1, toPosition)
end

-- Lock the player into mining recursion until stones endurance is spent
function miningCycle(playerID, toPosition)
    local player = Player(playerID)

    if player:getStorageValue(mining) < config.endurance then
        player:addItem(config.mineblood, 1, true)
        player:setStorageValue(mining, player:getStorageValue(mining) + 1)
        -- Queue recursion
        addEvent(miningCycle, config.swingrate, playerID, toPosition)
        return toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
    else
        target:remove(1)
        player:setStorageValue(mining, 0)
        player:setStorageValue(started, 0)
        -- Queue regeneration
        return regenMine(toPosition)
    end
end

function commenceCraftTask(playerID, toPosition)
    local player = Player(playerID)
    local variant = Variant(player:getName())

    local petrific = Condition(CONDITION_PARALYZE)
    local logblock = Condition(CONDITION_INFIGHT)
    local pacified = Condition(CONDITION_PACIFIED)
    local silenced = Condition(CONDITION_MUTED)
    local maglock1 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock2 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock3 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock4 = Condition(CONDITION_SPELLGROUPCOOLDOWN)

    petrific:setParameter(CONDITION_PARAM_TICKS, 20000)
    logblock:setParameter(CONDITION_PARAM_TICKS, 20000)
    pacified:setParameter(CONDITION_PARAM_TICKS, 20000)
    silenced:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock1:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock2:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock3:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock4:setParameter(CONDITION_PARAM_TICKS, 20000)

    petrific:setParameter(CONDITION_PARAM_SPEED, -400)
    maglock1:setParameter(CONDITION_PARAM_SUBID, 1) -- SPELLGROUP_ATTACK
    maglock2:setParameter(CONDITION_PARAM_SUBID, 2) -- SPELLGROUP_HEALING
    maglock3:setParameter(CONDITION_PARAM_SUBID, 3) -- SPELLGROUP_SUPPORT
    maglock4:setParameter(CONDITION_PARAM_SUBID, 4) -- SPELLGROUP_SPECIAL

    local pickswing = Combat()
    pickswing:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
    pickswing:setParameter(COMBAT_PARAM_AGGRESSIVE, true)
    pickswing:addCondition(petrific)
    pickswing:addCondition(logblock)
    pickswing:addCondition(pacified)
    pickswing:addCondition(silenced)
    pickswing:addCondition(maglock1)
    pickswing:addCondition(maglock2)
    pickswing:addCondition(maglock3)
    pickswing:addCondition(maglock4)

    return pickswing:execute(player, variant), miningCycle(playerID, toPosition)
end



function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local miningSkill = player:getStorageValue(SKILL_MINERADOR)
    local random = math.random(1, config.maxchance)
    local chance = (miningSkill / 1.5)

    if player:getStorageValue(started) == 1 then
        player.sendCancelMessage(player, messages.cancel)
    else
        if chance < 90000 then chance = 90000 end
        if random <= chance then
            estima(player)
            player:setStorageValue(started, 1)
            if math.random(1, config.maxchance) <= (config.maxchance / (miningSkill / 4)) then
                miningSkill = miningSkill + 1
                player:setStorageValue(SKILL_MINERADOR, miningSkill)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, messages.success(miningSkill))
            end
            commenceCraftTask(player:getId(), toPosition)
        else
            regenMine(toPosition) -- Queue regen
            player.sendCancelMessage(player, messages.failure)
            -- Biff it
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end
    end
    return true
end
 
I made minor modifications to the script, and tried to add the function to remove the stone, but it is not working.


Currently the script looks like this:
Lua:
local config = {
    quarrytype = 19959,             -- What is the identity of our stone?
    hibernate = 20 * 60 * 1000,     -- How long the stone must wait before respawning?
    endurance = 20,                 -- How many swings of the pick will the stone endure?
    mineblood = 5880,               -- What item does our stone bleed? -- Iron Ore
    swingrate = 1 * 1000,           -- How soon before the next swing of the players pick?
    maxchance = 100000,             -- What is the upper range of our random number?
}

local messages = {
    cancel = "Ja esta minerando.",
    failure = "Falha.",
    success = function(si) return string.format("Habilidade como minerador: %s.", si) end,
}

-- Add a reputation point
function estima(player)
    player:setStorageValue(ESTIMA, getPlayerStorageValue(player, ESTIMA) + 1)
end

-- Regenerate the stone after set time
function regenMine(toPosition)
    return addEvent(Game.createItem, config.hibernate, config.quarrytype, 1, toPosition)
end

-- Lock the player into mining recursion until stones endurance is spent
function miningCycle(playerID, toPosition)
    local player = Player(playerID)

    if player:getStorageValue(mining) < config.endurance then
        player:addItem(config.mineblood, 1, true)
        player:setStorageValue(mining, player:getStorageValue(mining) + 1)
        -- Queue recursion
        addEvent(miningCycle, config.swingrate, playerID, toPosition)
        return toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
    else
        target:remove(1)
        player:setStorageValue(mining, 0)
        player:setStorageValue(started, 0)
        -- Queue regeneration
        return regenMine(toPosition)
    end
end

function commenceCraftTask(playerID, toPosition)
    local player = Player(playerID)
    local variant = Variant(player:getName())

    local petrific = Condition(CONDITION_PARALYZE)
    local logblock = Condition(CONDITION_INFIGHT)
    local pacified = Condition(CONDITION_PACIFIED)
    local silenced = Condition(CONDITION_MUTED)
    local maglock1 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock2 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock3 = Condition(CONDITION_SPELLGROUPCOOLDOWN)
    local maglock4 = Condition(CONDITION_SPELLGROUPCOOLDOWN)

    petrific:setParameter(CONDITION_PARAM_TICKS, 20000)
    logblock:setParameter(CONDITION_PARAM_TICKS, 20000)
    pacified:setParameter(CONDITION_PARAM_TICKS, 20000)
    silenced:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock1:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock2:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock3:setParameter(CONDITION_PARAM_TICKS, 20000)
    maglock4:setParameter(CONDITION_PARAM_TICKS, 20000)

    petrific:setParameter(CONDITION_PARAM_SPEED, -400)
    maglock1:setParameter(CONDITION_PARAM_SUBID, 1) -- SPELLGROUP_ATTACK
    maglock2:setParameter(CONDITION_PARAM_SUBID, 2) -- SPELLGROUP_HEALING
    maglock3:setParameter(CONDITION_PARAM_SUBID, 3) -- SPELLGROUP_SUPPORT
    maglock4:setParameter(CONDITION_PARAM_SUBID, 4) -- SPELLGROUP_SPECIAL

    local pickswing = Combat()
    pickswing:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
    pickswing:setParameter(COMBAT_PARAM_AGGRESSIVE, true)
    pickswing:addCondition(petrific)
    pickswing:addCondition(logblock)
    pickswing:addCondition(pacified)
    pickswing:addCondition(silenced)
    pickswing:addCondition(maglock1)
    pickswing:addCondition(maglock2)
    pickswing:addCondition(maglock3)
    pickswing:addCondition(maglock4)

    return pickswing:execute(player, variant), miningCycle(playerID, toPosition)
end



function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local miningSkill = player:getStorageValue(SKILL_MINERADOR)
    local random = math.random(1, config.maxchance)
    local chance = (miningSkill / 1.5)

    if player:getStorageValue(started) == 1 then
        player.sendCancelMessage(player, messages.cancel)
    else
        if chance < 90000 then chance = 90000 end
        if random <= chance then
            estima(player)
            player:setStorageValue(started, 1)
            if math.random(1, config.maxchance) <= (config.maxchance / (miningSkill / 4)) then
                miningSkill = miningSkill + 1
                player:setStorageValue(SKILL_MINERADOR, miningSkill)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, messages.success(miningSkill))
            end
            commenceCraftTask(player:getId(), toPosition)
        else
            regenMine(toPosition) -- Queue regen
            player.sendCancelMessage(player, messages.failure)
            -- Biff it
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end
    end
    return true
end

At line 37 you have target:remove() but function miningCycle(playerID, toPosition) doesnt have target and there is no local variable inside the function that tells it what target is.

Add below line 28:
local target = Tile(toPosition):getItems()[1]

(Not tested)
 
Last edited:
If the rock is also supposed to disappear when the player fails, as it seems was your intention as per the bottom else branch where I put the "biff it" comment, to make them wait for the regen cycle, the code to remove the rock should be moved inside regenMine so both paths for a destroyed rock hit the removal code.
 
Is there a script for this, but without a mining skill? Just by using a pickaxe on a rock and a 50% to get an item, with the same exhausts and effects as this script.
 
"unable to use spells, unable to attack, and finally, unable to leave the game" does not work in TFS 1.4 - OTCv8
Any solution on how to apply these effects to player?

Using player:setMovementBlocked(false) in the meanwhile.
 
Last edited:
Back
Top