Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 30, 2021 10:35 pm GMT

Fourth Contribution

For this contribution, I came across OCVBot, a very interesting project that uses CV (computer vision) to automate tasks in the game Old School RuneScape.

In my years of playing, I've always wondered if something like this existed, so I was hooked right away.

Example

Image description

The Issue

Because this project was so new, I submitted an issue myself. I wanted to try making a script that trains the smithing skill.

The script would start at a bank, withdraw the required items, walk to the anvil, smith the items based on the config, and walk back to the bank.

The project owner responded with some tips to get started.

Getting started

I started by reviewing the chef script and Cooking class as suggested, and got a good idea on how to tackle this new script.

smither()

This is the "main" logic for the script. It's called from main() and passed config items.

Image description

Image description

smither() logic

Image description

Banking

The bank is a storage of items. The script would have to withdraw the needed items (hammer and bars). The banking class had all the functions I needed here.

Image description

I had some trouble with banking.open_bank("east"). This function call should look for a bank booth needle up to 2 tiles to the player's east. However, because this is a 3D game, there would have to be a different bank booth needle for each cardinal direction, and east was missing. So I added it:

Image description

Walking

The behavior.travel() is the main walking function. Thanks to the author's comprehensive comments, it was very easy to understand. The function works by accepting an array of waypoints and looking for the mini-map image (needle) against a "haystack" image. Once found, the coordinates of the waypoint, relative to the haystack image are clicked, which translates to a click on the mini-map, thus walking.

haystack

Image description

mini-map (needle)

Image description

Passing the following would click coordinates 88, 95 relative to the haystack image to a precision of 1, continue to the next waypoint once we're 4-7 coordinates away, and retry the current waypoint every 8-10 seconds.

bank = [((88, 95), 1, (4, 7), (8, 10))]behavior.travel(bank, haystack_map)

Smithing

As the project owner suggested, I made a Smithing class. This class had 2 functions; click_anvil() and smith_items().

click_anvil()

This function uses the click_needle() function of the Vision class to find and click the anvil, returning if it was successful or not.

Image description

If it was, it'd wait for a close button to appear, meaning the menu is visible. False is returned if it doesn't appear in the expected time frame.

Image description

smith_items()

This function starts by calling click_anvil(), retrying if it fails. When successful, we can assume the smithing menu is visible, so we can click on the item we want to smith in the menu.

Image description

Image description

Once clicked, the player starts smithing, which can take a while depending on the item. So we loop, checking if our inventory is completed or if we levelled up after every iteration.

We know the inventory is completed if we can't find a needle that contains a certain amount of bars at the bottom of our inventory, depending on the item.

Image description

Levelling up stops all actions, so we need to restart the smithing process if this happens.

Image description

If we're done smithing, the loop is broken and we return to the smither() function where we walk back to the bank.

Image description

Pull Request

After testing, I submitted a pull request and prayed.

Review

The project owner was concerned about the robustness of the method I used to check if the player is done smithing. He brought up the fact that if a partial inventory occurs, the script won't know when to stop, because the needles may never be found. A partial inventory happens when the bank doesn't contain enough items to completely fill the inventory.

I suggested a sleep after clicking on the menu item to smith, which would would solve partial inventories. But he brought up latency which could throw that off, a very good point.

So I proposed that we keep the current method I had written, but with an added check after withdrawing from the bank to ensure partial inventories don't occur.

He agreed, but had a few more simple issues that I quickly fixed. I pushed the fixes, which were accepted, and the script was was finally merged.


Original Link: https://dev.to/ar/fourth-contribution-55bb

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To