OTBots Forums
[Free] Pickup spears around you when low count FOR TRAINING - Printable Version

+- OTBots Forums (https://forums.otbots.com)
+-- Forum: Mastercores OTBot (https://forums.otbots.com/Forum-Mastercores-OTBot--25)
+--- Forum: Scripts (https://forums.otbots.com/Forum-Scripts--30)
+---- Forum: LUA Scripts (https://forums.otbots.com/Forum-LUA-Scripts--31)
+---- Thread: [Free] Pickup spears around you when low count FOR TRAINING (/Thread-FREE-Pickup-spears-around-you-when-low-count-FOR-TRAINING--1910)



Pickup spears around you when low count FOR TRAINING - Arkilys - 10-06-2021

Hello.

This script will pickup spears AROUND YOU when you have low amount on your hand.
This script should be used on TRAIN, not hunting.

Using default setttings, it will sort "MinRange" between the range you setup on this field. Once you have lower amount than this random value, it will sort a random value between "MaxRange" that you setup then pickup spears around you until you have spears count equal to MaxRange.
Explaining again:
1. Let's say that you have 2 spears in your hand.
2. It will sort a value between 1 and 5 to "MinRange", let's say 3.
3. It will sort a value between 20 and 25 to "MaxRange", let's say 21.
When you have 3 or less spears in your hand, it will pickup an amount of spears that you will have a maximum of 21 spears in your hand, so it would pickup 19 spears. Because you have 2 spears in your hand + 19 spears = 21 spears, which is the sorted MaxRange. Then it will sort a new "MinRange".

That way, it will always sort random values for start picking up and the max amount on your hand to looks more legit.

local CONFIG = {
    SPEAR_ID = 3277, -- Id, not name.
    HAND = 'lhand', -- lhand or rhand
    MinRange = { 1, 5 }, -- It will pickup when you have a random count from this range.
    MaxRange = { 20, 25 }, -- It will pickup a maximum of x spears which will be a random count from this range.
}

-- DONT CHANGE ANYTHING BELOW THIS LINE --


if MIN_COUNT == nil then
    MIN_COUNT = random(CONFIG.MinRange[1], CONFIG.MinRange[2])
end

if gethandcount == nil then
    function gethandcount(hand)
        local handItem
        if hand:lower() == 'lhand' then
            handItem = lhand()
        else
            handItem = rhand()
        end
        if handItem.id == 0 or handItem.id == CONFIG.SPEAR_ID then
            return handItem.count
        else
            printerror('You are not using spear id ' .. CONFIG.SPEAR_ID .. ' on ' .. CONFIG.HAND .. '. Nor is this hand empty.')
            return 999
        end
    end
end

local handCount = gethandcount(CONFIG.HAND)
if handCount ~= 999 and handCount <= MIN_COUNT then
    local MAX_COUNT = random(CONFIG.MaxRange[1], CONFIG.MaxRange[2])
    local count_pickup = MAX_COUNT - handCount
    if count_pickup > 0 then
        local SPOTS = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 0 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }
        for i = #SPOTS, 2, -1 do
            local j = random(1, i)
            SPOTS[i], SPOTS[j] = SPOTS[j], SPOTS[i]
        end

        while count_pickup > 0 do
            local flag = false
            local player_x = posx()
            local player_y = posy()
            local player_z = posz()
            for _, spot in ipairs(SPOTS) do
                local topItem = topitem(player_x + spot[1], player_y + spot[2], player_z, false)
                if topItem.id == CONFIG.SPEAR_ID then
                    moveitems(CONFIG.SPEAR_ID, CONFIG.HAND, ground(player_x + spot[1], player_y + spot[2], player_z), count_pickup)
                    wait(500, 800)
                    count_pickup = MAX_COUNT - gethandcount(CONFIG.HAND)
                    flag = true
                    if count_pickup == 0 then
                        break
                    end
                end
            end

            if not flag then
                break
            end
        end
    end
end