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

RevScripts Automatic mining with delay between each action

nefinoo

Carnage.flv
Joined
Sep 11, 2010
Messages
552
Solutions
1
Reaction score
60
Location
Lo Mochis, Sinaloa
I wanted to make the player use the pickaxe only once on a rock, and this script would be running by itself for 1 hour, with a 2 second delay between each action.
i am using otservbr

Lua:
local Minar = Action()

local monsters = {
    [1] = { mons = "White Pale", chance = 3, expmin= 500000, expemax = 550000, skill = 15},
    [2] = { mons = "The Sandking", chance = 6, expmin= 75000, expemax = 100000, skill = 10},
    [3] = { mons = "Rotworm Queen", chance = 12, expmin= 50000, expemax = 60000, skill = 9},
    [4] = { mons = "Sub Worm", chance = 24, expmin= 15000, expemax = 20000, skill = 8},
    [5] = { mons = "Greed Worm", chance = 48, expmin= 7000, expemax = 9000, skill = 7},
    [6] = { mons = "Drillworm", chance = 96, expmin= 4500, expemax = 6500, skill = 6},
    [7] = { mons = "Deepworm", chance = 192, expmin= 5000, expemax = 5500, skill = 5},
    [8] = { mons = "Carrion Worm", chance = 384, expmin= 3000, expemax = 3500, skill = 4},
    [9] = { mons = "Rotworm", chance = 768, expmin= 1000, expemax = 2000, skill = 3},
    [10] = { mons = "Cave Rat", chance = 1536, expmin= 400, expemax = 500, skill = 2},
    [11] = { mons = "Rat", chance = 3072, expmin= 200, expemax = 250, skill = 1},
}

local rewards = {
    [1] = { item = 32724, count = 3, chance = 50, expmin= 13000, expemax = 16000, skill = 13},
    [2] = { item = 32724, count = 2, chance = 150, expmin= 11000, expemax = 14000, skill = 12},
    [3] = { item = 32724, count = 1, chance = 250, expmin= 9000, expemax = 12000, skill = 11},
    [4] = { item = 16135, count = 3, chance = 500, expmin= 3500, expemax = 3900, skill = 10},
    [5] = { item = 16135, count = 2, chance = 650, expmin= 3250, expemax = 3650, skill = 9},
    [6] = { item = 16135, count = 1, chance = 800, expmin= 3000, expemax = 3400, skill = 8},
    [7] = { item = 947, count = 5, chance = 1500, expmin= 900, expemax = 1000, skill = 7},
    [8] = { item = 947, count = 3, chance = 2000, expmin= 750, expemax = 850, skill = 6},
    [9] = { item = 947, count = 1, chance = 2500, expmin= 600, expemax = 700, skill = 5},
    [10] = { item = 3031, count = 50, chance = 24000, expmin= 150, expemax = 200, skill = 4},
    [11] = { item = 3031, count = 35, chance = 26000, expmin= 120, expemax = 140, skill = 3},
    [12] = { item = 3031, count = 20, chance = 28000, expmin= 90, expemax = 110, skill = 2},
    [13] = { item = 3031, count = 5, chance = 30000, expmin= 75, expemax = 80, skill = 1}
}


local config = {
storagemining = 100000,
expperlevel = 250,
experiencemining = 125
}

local storage = 5000
local delay_timer = 0
local aleatorio = 50500
local aleatorio2 = 10100
local start = os.time()
local end_time = start + 3600

function Minar.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    while os.time() < end_time do
    local cur_time, cur_storage = os.time(), player:getStorageValue(storage)
    local getMiningLevel = player:getStorageValue(config.storagemining)
    local getMiningExp = player:getStorageValue(config.experiencemining)
    local R = getMiningLevel
    local expmine = math.floor(25/3 * (17*(R*R*R) + 29*(R*R) + 173*(R) + 37))
 
    if cur_storage > cur_time then
        player:sendTextMessage(22, "You can mining again in " .. os.date("!%Hh %Mm %Ss", cur_storage - cur_time) .. ".")
        return true
    end
    
    local levelale = getMiningLevel * 1000
    local levelale2 = getMiningLevel * 200
    
    local function addbackstone()
        local tile = Tile(toPosition)
        rock = tile:getItemById(10870)
        rock:remove()
        local stones = {11427}
        local stone = Game.createItem(stones[math.random(#stones)], 1, toPosition)
            toPosition:sendMagicEffect(3)
            stone:setActionId(3001)
    end
    
    if player:getLevel() < 20 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You dont have the required level of 10 to mining.")
        return true
    end
    
    if not target then
        return false
    end
    
    if not target:isItem() then
        return false
    end

    if target.actionid ~= 3001 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You cannot use it here.')
        return false
    end
    
    local ran = math.random(aleatorio - levelale)
    local ran2 = math.random(aleatorio2 - levelale2)
    if target.actionid == 3001 then
        local break_chance = aleatorio / 1000
        if ran <= break_chance then
            item:remove(1)
            player:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
            player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You mined so hard you broke your pickaxe and the rock.')
            toPosition:sendMagicEffect(3)
            target:remove()
            Game.createItem(10870, 1, toPosition)
            addEvent(addbackstone, 10000)
            -- addEvent(addbackstone, 5000)
            return true
        end
    end   
    
    local text = "You have found "
    local text1 = "You have gained "
    local text2 = "You have lured a creature "
    local experience2 = 0
    for i = 1, #rewards do
        print("Ran: "..ran)
        if ran <= rewards[i].chance and getMiningLevel >= rewards[i].skill then
                if rewards[i].item == 3031 then
                    local premio = math.random(rewards[i].count)
                    player:addItem(rewards[i].item, premio)
                    text = text .. premio .. " " .. ItemType(rewards[i].item):getName()
                        if player:getStorageValue(storagemining) == 1 then
                        for x = 1, #monsters do
                            if ran2 <= monsters[x].chance and getMiningLevel >= monsters[x].skill then
                                Game.createMonster(monsters[x].mons, toPosition)
                                text2 = text2 .. "a " .. monsters[x].mons
                                player:sendTextMessage(MESSAGE_STATUS_WARNING, text2)
                                experience2 = experience2 + math.random(monsters[x].expmin, monsters[x].expemax)
                                break   
                            end
                        end
                        end
                elseif rewards[i].item == 947 then
                    local premio = math.random(rewards[i].count)
                    player:addItem(rewards[i].item, premio)
                    text = text .. premio .. " " .. ItemType(rewards[i].item):getName()
                        if player:getStorageValue(storagemining) == 1 then
                        for x = 1, #monsters do
                            if ran2 <= monsters[x].chance and getMiningLevel >= monsters[x].skill then
                                Game.createMonster(monsters[x].mons, toPosition)
                                text2 = text2 .. "a " .. monsters[x].mons
                                player:sendTextMessage(MESSAGE_STATUS_WARNING, text2)
                                experience2 = experience2 + math.random(monsters[x].expmin, monsters[x].expemax)
                                break   
                            end
                        end       
                        end       
                elseif rewards[i].item == 16135 then
                    local premio = math.random(rewards[i].count)
                    player:addItem(rewards[i].item, premio)
                    text = text .. premio .. " " .. ItemType(rewards[i].item):getName()
                        if player:getStorageValue(storagemining) == 1 then
                        for x = 1, #monsters do
                            if ran2 <= monsters[x].chance and getMiningLevel >= monsters[x].skill then
                                Game.createMonster(monsters[x].mons, toPosition)
                                text2 = text2 .. "a " .. monsters[x].mons
                                player:sendTextMessage(MESSAGE_STATUS_WARNING, text2)
                                experience2 = experience2 + math.random(monsters[x].expmin, monsters[x].expemax)
                                break   
                            end
                        end
                        end
                elseif rewards[i].item == 32724 then
                    local premio = math.random(rewards[i].count)
                    player:addItem(rewards[i].item, premio)
                    text = text .. premio .. " " .. ItemType(rewards[i].item):getName()
                        if player:getStorageValue(storagemining) == 1 then
                        for x = 1, #monsters do
                            if ran2 <= monsters[x].chance and getMiningLevel >= monsters[x].skill then
                                Game.createMonster(monsters[x].mons, toPosition)
                                text2 = text2 .. "a " .. monsters[x].mons
                                player:sendTextMessage(MESSAGE_STATUS_WARNING, text2)
                                experience2 = experience2 + math.random(monsters[x].expmin, monsters[x].expemax)
                                break
                            end
                        end
                        end
                end
                -- local exppla = player:addExperience(math.random(100))
                -- if text ~= "You have found " then
                    -- text = text .. ", "
                -- end
                local experience = math.random(rewards[i].expmin, rewards[i].expemax)
                experience = experience + experience2
                player:addExperience(experience)
                
                if getMiningExp >= expmine then
                    player:getPosition():sendMagicEffect(49)
                    player:setStorageValue(config.storagemining, getMiningLevel + 1)
                    player:setStorageValue(config.experiencemining, getMiningExp - expmine)
                    text1 = text1 ..experience.. " experience points in Mining. \n You advanced from mining skill level " ..getMiningLevel.. " to mining skill level " ..(getMiningLevel + 1).. "."
                else
                    player:setStorageValue(config.experiencemining, getMiningExp + experience)
                    text1 = text1 ..experience.. " experience points in Mining. \n" ..(expmine - getMiningExp - experience).. " experience points left to next level. \nCurrent Mining Skill: " ..getMiningLevel.. "."
                end
                doSendMagicEffect(toPosition, 9)
                player:sendTextMessage(22, text1)
                
                break
            end
    end
    
    if text == "You have found " then
            text = text .. "nothing"       
    end
    
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, text .. ".")
    cur_time = cur_time + delay_timer
    player:setStorageValue(storage, cur_time)
    addEvent(function (Minar) end, 1000, player, item, fromPosition, target, toPosition, isHotkey)
    end
    return true
end

Minar:id(32711)
Minar:register()
 
Back
Top