Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Open Source DB3 Tutorial Island TaskScript!


    Realistic

    Recommended Posts

    Hey all,
    I just finished making my first script! I developed it using the DB3 beta JAR. Here is the source on Github!

    Right now it is NOT meant for public use, but aimed at showing devs a decent, large DB3 example and getting feedback from other devs about how I can improve. It includes most things that any bot will do. I tried to follow the new DB3 best practices IE: Widgets.getClosest not getWidgets ETC... I did not use any methods that will be deprecated in DB3. That being said THIS IS NOT PERFECT. I am new to Java/Scripting and want any and all feedback! Please post a comment or open a PR/Issue on GitHub if you notice anything I did wrong, bugs, or have any suggestions.

    NOTE: This script is still not a 1.0 release and has some (lots of) bugs! It is also missing some features (paint), and it does some very sketchy things (Clicking through walls...). I am working on improving the utils I wrote to be more Realistic(TM) ;) and I will be updating the repo on a regular bases.

    I will be pushing this to the DB script repo as a free script as soon as I am happy with it and DB3 is released. Until then, have fun looking through the code and running it from source!

    Read the README.md!

     

    More details about the script:

    I tried something kind of weird. The script extends TaskScript and using TaskNodes (standard), but I decided to use  a double layered state machine. The layers are in two files: ScriptState and TaskState.

    The script is broken into ScriptState (each tutor), and TaskStates (each step to complete a tutor).
     
    The ScriptState keeps track of what TaskNode(tutor) should be run, and the second state machine is essentially a double linked list of jobs that need to be completed for each tutor. The actual TaskNode.execute()  just runs the TaskState in each Java file. While each enum in TaskState contains its own logic that decides if it should be run, what it should do, and what task is next.

    This was a fun little experiment to try, and it seems to work well, At least for simple linear tasks. I am going mess around with a slight variation it in my next project. In that one the logic that tells the TaskState if it should be run will be pulled into a hash table/B-tree and the current player state will be checked vs that to decide what to do. I think Pandemic posted something along this line already.

    I have also started working on another git repo that contains useful snippets, DB3 vs DB2 code, and any open source DB scripts that I can find. I will be making a post about that in the next couple of days.

    Thank you to @holic for providing the snippet I used to generate names. See their original topic here

     

    P.S. If you want a good laugh take a look at the GIT history and how HORRIBLE the first 3 or so iterations were. I mean it is still pretty bad, but not as bad as it used to be.

    Link to comment
    Share on other sites

    Thank you for the contribution!

    Some things I could point out after taking a glance at the code:

    • kuva.png
      That's clearly not true, the code is quite nice to look at. I was expecting worse after reading that.
       
    • kuva.png
      There's a bunch of magic numbers out there. Those are item ids, yet you're not using your Items class that contains item ids in static vars.
       
    • kuva.png
      You're getting the range by its id. Gameobject ids change in the game very often, so that'll break at some point. Also, there's no null checks. It could be that GameObjects.closest returns a null value, making your script throw NPEs. Also, there's no need to fetch the object again to interact with it, you've already got it in the range variable => range.interact() instead.
    Link to comment
    Share on other sites

    6 hours ago, Hashtag said:

    Thank you for the contribution!

    Some things I could point out after taking a glance at the code:

    • kuva.png
      That's clearly not true, the code is quite nice to look at. I was expecting worse after reading that.
       
    • kuva.png
      There's a bunch of magic numbers out there. Those are item ids, yet you're not using your Items class that contains item ids in static vars.
       
    • kuva.png
      You're getting the range by its id. Gameobject ids change in the game very often, so that'll break at some point. Also, there's no null checks. It could be that GameObjects.closest returns a null value, making your script throw NPEs. Also, there's no need to fetch the object again to interact with it, you've already got it in the range variable => range.interact() instead.
    1. Promise low, deliver slightly less low ;)
    2. Ah. Thanks. I missed those. I will go back and make sure all of them are in the consts file.
    3. I didn't know game object ids changed. Good to know. So if I am looking one up it should be by name? I will also add in some null checks. Thanks
       

    Question:

    I am working on a class that detects if an object/NPC is behind a wall or hard to see and will move the camera before interacting with it. Any suggestions? I am trying to use 3d to 2d projection using org.dreambot.api.methods.ViewportTools and some other classes. I am sure I missed something and there is an easy way to tell of something is occluded.

    Link to comment
    Share on other sites

    Nice job, solid contribution!

    Some thoughts:

    • I'd combine most of your constants into one file (I don't think there's enough to really justify so many small classes), or at least rename the GameObjects/NPCS/(and possibly) Items, as it might be confusing using it with our API classes of the same name
    • I'm curious why you decided to use java.lang's Boolean for your TaskState
    • A couple of your util classes extend MethodContext, and I'd advise against that. I'd just call MethodProvider's static methods instead so you won't accidentally try to use MethodContext's other methods which could cause issues
    • TextHelper class is empty :o

    Good work!

    Link to comment
    Share on other sites

    6 hours ago, Realistic said:
    1. Promise low, deliver slightly less low ;)
    2. Ah. Thanks. I missed those. I will go back and make sure all of them are in the consts file.
    3. I didn't know game object ids changed. Good to know. So if I am looking one up it should be by name? I will also add in some null checks. Thanks
       

    Question:

    I am working on a class that detects if an object/NPC is behind a wall or hard to see and will move the camera before interacting with it. Any suggestions? I am trying to use 3d to 2d projection using org.dreambot.api.methods.ViewportTools and some other classes. I am sure I missed something and there is an easy way to tell of something is occluded.

    Looks good, something to consider for situations like this

    image.png.62c386a294d01b05127a48ad723473bc.png

     

    is first to ensure the item exists in your inventory and then sleepUntil -> item.isSelected

    As for the NPC/wall issue have you tried the NPC.isOnScreen()? I'm not entirely sure if it detects wether the npc is obstructed but it may help here.

    Another solution would be if distance -> NPC > 3 .... walk to NPC, else -> rotate to NPC

    Link to comment
    Share on other sites

    7 hours ago, Pandemic said:

    Nice job, solid contribution!

    Some thoughts:

    • I'd combine most of your constants into one file (I don't think there's enough to really justify so many small classes), or at least rename the GameObjects/NPCS/(and possibly) Items, as it might be confusing using it with our API classes of the same name
    • I'm curious why you decided to use java.lang's Boolean for your TaskState
    • A couple of your util classes extend MethodContext, and I'd advise against that. I'd just call MethodProvider's static methods instead so you won't accidentally try to use MethodContext's other methods which could cause issues
    • TextHelper class is empty :o

    Good work!

    1. Will do! I am still trying to figure out the best way to use java classes for consts like this. Ideally I would like to be able to do `item.hammer` and have it create an instance of the Item("Hammer") that I could just use. I was thinking about writing a wrapper that could handle ground and inventory items by doing this. Thoughts?
    2. Because I don't know how java primitive types work... I didn't really know that Boolean was different from boolean. I am going to change them to primitives...
    3. Good point! I will refactor it to only use static methods unless I am in a TaskNode
    4. I started writing a bunch of helper/wrapper classes when I was completely unfamiliar with the DB3 API and most of them are redundant and error prone. I will remove some of them/redo some of them in a refactor.

    Thank you for your feedback Pandemic!

    Link to comment
    Share on other sites

    4 hours ago, None said:

    Looks good, something to consider for situations like this

    image.png.62c386a294d01b05127a48ad723473bc.png

     

    is first to ensure the item exists in your inventory and then sleepUntil -> item.isSelected

    As for the NPC/wall issue have you tried the NPC.isOnScreen()? I'm not entirely sure if it detects wether the npc is obstructed but it may help here.

    Another solution would be if distance -> NPC > 3 .... walk to NPC, else -> rotate to NPC

    Ops, missed checking for the item to actually be made... Thanks.

    As far as I can tell isOnScreen does not check if anything is in the way. I did a bunch of testing with it , and NPC and a wall and could not get isOnScreen to return false if there was a wall in the way.

    Using rotate to NPC can sometimes move the camera behind an object. For instance if I do rotate to NPC with the mining tutor sometimes the camera ends up behind a stalactite and the script will just click through it. Not great :(

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.