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
  • Can someone help me improve/fix this code?


    zafric123

    Recommended Posts

    Code: https://pastebin.com/r8cEJmy4

     

    I am really new to scripting so I'm asking for a little help because I cant figure this out.

     

    Whats wrong:

    - Waiting is a bit funky. Probably needs to sleep until a condition is met like not moving instead of waiting 15 seconds but idk how.

    - It clicks some of the doors and goes through but not all the 1s i added in.

    - Probably a lot can be improved.

     

    What its suppose to do:

    Travel to stronghold of security in barbarian village, go down the hole, and go through the first 5 doors (Eventually all of em)

     

    UPDATE: I got it to work. My only question is now how do I make it so it walks only no matter what I try it keeps trying to run I can get it to click run off but then a second or two later it toggles it back on in a loop.

     

    if(getWalking().isRunEnabled() == true) { getWalking().toggleRun(); }

     

    I've also messed with runthreshold it did nothing as well.

    Link to comment
    Share on other sites

    5 hours ago, zafric123 said:

    Code: https://pastebin.com/r8cEJmy4

     

    I am really new to scripting so I'm asking for a little help because I cant figure this out.

     

    Whats wrong:

    - Waiting is a bit funky. Probably needs to sleep until a condition is met like not moving instead of waiting 15 seconds but idk how.

    - It clicks some of the doors and goes through but not all the 1s i added in.

    - Probably a lot can be improved.

     

    What its suppose to do:

    Travel to stronghold of security in barbarian village, go down the hole, and go through the first 5 doors (Eventually all of em)

    You need to start with something easier. Either that or divide your goal into small tasks and try working on a single task till it's done and move to the next one.

    There are too many things wrong with your code logic, you need to learn some basics first. 

    Link to comment
    Share on other sites

    UPDATE: I got it to work. My only question is now how do I make it so it walks only no matter what I try it keeps trying to run I can get it to click run off but then a second or two later it toggles it back on in a loop.

    if(getWalking().isRunEnabled() == true) { getWalking().toggleRun(); }

     I've also messed with runthreshold it did nothing as well.

    Link to comment
    Share on other sites

    Think it's a quality idea for a script, you've done pretty well so far.

    Couple suggestions:

    Use Calculations.random for generating random ints as opposed to creating a random object

    Think you should avoid using multiple states for the doors, potentially keep a track of which door and floor you are on and  use an array of Tile arrays (Tile[][]) to keep track of which door you are currently in and where the next one is, increment the door after you successfully open a door and floor when you go down the next ladder because it's going to get complicated with lots of different floors and doors as states.  

     

     

    Link to comment
    Share on other sites

    20 minutes ago, zafric123 said:

    UPDATE: I got it to work. My only question is now how do I make it so it walks only no matter what I try it keeps trying to run I can get it to click run off but then a second or two later it toggles it back on in a loop.

    if(getWalking().isRunEnabled() == true) { getWalking().toggleRun(); }

     I've also messed with runthreshold it did nothing as well.

    You could add a line to toggle run if it's disabled while entering a dangerous zone then once within x distance of the next door toggling run again or adding a sleep between the two toggles, unsure why it would be continually being turned back on with that code though. 

    Link to comment
    Share on other sites

    here's my comments, some of them apply to the issues you'd asking about others are just general advice on code structure, etc:

    1. make your doDialogue parameter a static variable, there's no reason to type the same thing 3 times. ("Decline the offer and report that player.", "Don"...)

    2. in your travelTo method, you should not be using a while loop, as it blocks the main run method. instead, have a conditional there, and have your main state determine whether to run that method or now, so if it needs to run twice in a row, that method will run again instead of locking it in a while loop

    3.  for your custom nodes, check with the web node debugger tool to see if its already mapped, if so you can remove your custom nodes

    4. in your onloop, if you're having trouble with timings in specific states, consider returning different values instead of sleeping and breaking. you can directly return different values for different case statements

    if I think of more, I'll add them

    Link to comment
    Share on other sites

    1 hour ago, zafric123 said:

    UPDATE: I got it to work. My only question is now how do I make it so it walks only no matter what I try it keeps trying to run I can get it to click run off but then a second or two later it toggles it back on in a loop.

    if(getWalking().isRunEnabled() == true) { getWalking().toggleRun(); }

     I've also messed with runthreshold it did nothing as well.

    theres a method you can call to handle this, its called something like setrunthreshold(), If you set that threshhold to 100, it should not turn back on after you turn it off. 

     

    checkout the Walking class here: https://dreambot.org/javadocs/

    edit: i am retarded, you already looked at run threshold -- did you set this in the onStart?

    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.