Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

mining script

Ask for help
Post Reply
Ming Xiao
Posts: 1
Joined: 18.01.2020 22:20

mining script

Post by Ming Xiao »

Hey there,
I have a problem with mining script, since I am total newb in case of programming I beg for an assistance.
I've noticed few issues in this material:
1. Character does not make shovels sometimes, once I do it manually script resumes.
2. Character tries do dig a couple of times on a tile where there is no more ore(it consumes a bit of time)
3. Character does not dig as fast as it could be possible in my opinion.

To fix that script I think it would be good if someone would log in on to Demise server.

Code: Select all

from py_stealth import *
from datetime import datetime, timedelta
#*************************************************************************
# Mining v1.0
# Autor : MaZa
# Need 2+ runebooks with marked runes and 1 runebook with 1st rune to dropbox
# Script auto scan in 2 tile raduis for mining locations
# Auto Reconnect, craft tools
# For start need tinkertools and 50 ingots in backpack
#*************************************************************************
home_runebook = 0x430fe489
runebooks = [0x44bd3495,0x4233d029]
dropbox = 0x41e71d9f
forge = 0x40d06733
#*************************************************************************
#*************************************************************************
#*************************************************************************
rune_type = 0x1F14
tinkertools = 0x1EB8
shoovel = 0xf39
ingots = 0x1BF2
msg = 'There is no metal here to mine|That is too far away|mine there|mine that|be seen'
ore_types = [
    0x19B7,
    0x19BA,
    0x19B9,
    0x19B8,
]
gem_types = [
    0x3195,
    0x3194,
    0x3198,
    0x3193,
    0x3197,
    0x3192
]
#*************************************************************************
#*************************************************************************
#*************************************************************************
mining_tiles = [
    220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
    230, 231, 236, 237, 238, 239, 240, 241, 242, 243,
    244, 245, 246, 247, 252, 253, 254, 255, 256, 257,
    258, 259, 260, 261, 262, 263, 268, 269, 270, 271,
    272, 273, 274, 275, 276, 277, 278, 279, 286, 287,
    288, 289, 290, 291, 292, 293, 294, 296, 296, 297,
    321, 322, 323, 324, 467, 468, 469, 470, 471, 472,
    473, 474, 476, 477, 478, 479, 480, 481, 482, 483,
    484, 485, 486, 487, 492, 493, 494, 495, 543, 544,
    545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
    555, 556, 557, 558, 559, 560, 561, 562, 563, 564,
    565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
    575, 576, 577, 578, 579, 581, 582, 583, 584, 585,
    586, 587, 588, 589, 590, 591, 592, 593, 594, 595,
    596, 597, 598, 599, 600, 601, 610, 611, 612, 613,
    1010, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749,
    1750, 1751, 1752, 1753, 1754, 1755, 1756, 1757, 1771, 1772,
    1773, 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782,
    1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1801, 1802,
    1803, 1804, 1805, 1806, 1807, 1808, 1809, 1811, 1812, 1813,
    1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823,
    1824, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839,
    1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849,
    1850, 1851, 1852, 1853, 1854, 1861, 1862, 1863, 1864, 1865,
    1866, 1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875,
    1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1981,
    1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991,
    1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
    2002, 2003, 2004, 2028, 2029, 2030, 2031, 2032, 2033, 2100,
    2101, 2102, 2103, 2104, 2105,
    0x453B, 0x453C, 0x453D, 0x453E, 0x453F, 0x4540, 0x4541,
    0x4542, 0x4543, 0x4544, 0x4545, 0x4546, 0x4547, 0x4548,
    0x4549, 0x454A, 0x454B, 0x454C, 0x454D, 0x454E, 0x454F
]


def craft(n):
    if FindType(tinkertools, Backpack()) > 0:
        UseObject(FindItem())
        Wait(700)
        NumGumpButton(GetGumpsCount() - 1, n)
        Wait(1300)


def craft_tools():
    # 23 tinker
    # 72 shoovel
    if CountEx(ingots, 0, Backpack()) > 10:
        if CountEx(tinkertools, 0, Backpack()) > 0 and CountEx(tinkertools, 0, Backpack()) < 2:
            craft(23)
            return
    if CountEx(ingots, 0, Backpack()) > 10:
        if CountEx(shoovel, 0, Backpack()) < 2:
            craft(72)
            return

def userb(book, number):
    x, y = GetX(Self()), GetY(Self()) 
    print('Starting recall')
    while GetX(Self()) == x and GetY(Self()) == y:      
        print('in the recall loop')
        if Dead(): 
            return False
        UseObject(book)
        CheckLag(10000)
        NumGumpButton(GetGumpsCount() - 1, number)
        Wait(1500)


def unload(rb, rune):
    print('entered unload') 
    userb(home_runebook, 7)
    for ore in ore_types:
        while FindType(ore, Backpack()) > 0:
            UseObject(FindItem())
            WaitForTarget(2000)
            TargetToObject(forge)
            Wait(550)
            if GetType(FindItem()) == 0x19B7:
                DragItem(FindItem(),FindQuantity())
                Wait(600)
                DropItem(dropbox,0,0,0)
                Wait(750)

    while FindType(ingots, Backpack()) > 0:
        #MoveItem(FindItem(), FindQuantity(), dropbox, 1, 1, 0)
        DragItem(FindItem(), FindQuantity())
        Wait(600)
        DropItem(dropbox, 0, 0, 0)
        Wait(750)

    for gem in gem_types:
        if FindType(gem,Backpack()) > 0:
            #MoveItem(FindItem(),FindQuantity(),dropbox,1,25,0)
            DragItem(FindItem(), FindQuantity())
            Wait(600)
            DropItem(dropbox, 0, 0, 0)

    if FindTypeEx(ingots,0,dropbox,False) > 0:
        for i in GetFindedList():
            if GetQuantity(i) >= 50 and GetColor(i) == 0:
                #MoveItem(i, 50, Backpack(), 1, 1, 0)
                DragItem(FindItem(), 50)
                Wait(600)
                DropItem(Backpack(), 0, 0, 0)
                Wait(750)
                break
    IgnoreReset()
    userb(rb, rune)


def scan_tiles(r):
    x = GetX(Self())
    y = GetY(Self())
    found = GetLandTilesArray(x + r, y + r, x - r, y - r, WorldNum(), mining_tiles)  
    print(found)
    return found


def dig(rb, rune):
    print('entered dig')
    message_fail = "You loosen some rocks| You dig some "
    message_end = "There is nothing here |" \
                  "There is no metal |" \
                  "You cannot mine |" \
                  "You have no line |" \
                  "That is too far |" \
                  "Try mining elsewhere |" \
                  "You can't mine |" \
                  "someone |" \
                  "Target cannot be"
    message_attack = "is attacking you"
    message_all = message_fail + "|" + message_end + "|" + message_attack
#    cTime = datetime.now()
    tiles = scan_tiles(1)
    for t in tiles: 
        print(f"started mining in tile: {t}")
        minespot = True
        while minespot:
            if Dead():
                break
            if not Connected():
                Connect()
                Wait(5000)
            craft_tools()
            # check weight unload
            if Weight() >= MaxWeight() - 45:
                print('unload')
                unload(rb, rune)
                continue
            starttime = datetime.now()
            UseType2(shoovel)
            WaitForTarget(2000)
            if TargetPresent():
                TargetToXYZ(t[1], t[2], t[3])
                WaitJournalLine(starttime, message_all, 120000)
                if ((InJournalBetweenTimes(message_end, starttime, datetime.now())) > 0):
                                print('Node mined fully') 
                                Wait(200)
                                minespot = False


while True:
    if not Connected():
        Connect()
        Wait(5000)

    if Dead():
        continue

    for book in runebooks:
        r = 7 #<---------
        for rune in range(16):  # 50-65 servuo, 5-95
            if not Connected():
                Connect()
                Wait(5000)
            print('Book', book, 'Rune', r)  
            print('In the cycle')
            userb(book, r)
            dig(book, r)
            r += 6
Post Reply