Jump to content

My first ever script


meganide97

Recommended Posts

Hey just wrote my first ever OSbot script after having studied Java for 2 days with no prior experience whatsoever, just wanted to ask for some feedback. It's a very basic mining script that mines Copper ore and then banks, so far it seems to work. :)

  Reveal hidden contents

What I want to add next is a GUI that lets the user input what kind of ore & location they want to mine in and bank, and also add paint. However I have no idea whatsoever how to this so I will have to study more before doing this. I also read about dividing the script in multiple classes and using the switch command to make it look cleaner so that I wouldn't have to use so many if statements.

 

Will update you guys on the script as I add new stuff. :)

Edit 1: 

- Cleaned up the code a little bit after reading the feedback.

- Added paint (Total runtime, xp gained, lvls gained, total gp made, gp/hour, ore mined, xp/hr.

- Added some antiban (it now randomly hovers the mining skillicon).

- Changed it to mine iron ore instead.

Picture of the bot running: https://i.gyazo.com/87b8d4cf40e87cb4f054b9825d4eae38.png

Updated code:

  Reveal hidden contents

 

Future updates: 

- Will add a GUI that will let you choose whether you want to powermine or bank, and also lets you choose which ore to mine that supports more locations and not just the Al-Kharid mine.

- Will have to implement some kind of method that gets the GE prices for different ores to calculate the gp/hour.

- For the powermining part, I want it to use shift-click to drop if possible.

Appreciate further feedback, thanks!

 

Edit 2:

- Script now remembers starting position so you can start it from any mine and it will automatically walk to the closest bank.

- Filtered deposit item to bank everything that ends with ore so skillers can have pickaxe in inventory.

 

Edit 3:

- Added a GUI that lets you choose which ores you want to mine (based on color).

- Cleaned up the code a little bit.

Thanks @Vilius for the help!

 

Edit 4:

- Added a powermining checkbox in GUI that supports shift dropping.

- Script is now finished!!! :-)

 

Code:

  Reveal hidden contents

 

Edited by meganide97
Added update.
  • Like 2
Link to comment
Share on other sites

Logic needs to be relooked at and worked on

possible nullpointer before you even check if ore is null

banking is poor logic and can be rewritten. You can see an example here: https://github.com/christophernarciso/programming/blob/master/Meire %26 Brito Automation [OSBot.org]/OSBot Scripting Open Source Projects/Scripts/CAccountEvaluator/src/Evaluator.java#L108

Link to comment
Share on other sites

Not bad for 2 days of study.

 

Here are some specifics:

you can get rid of the second call to getBank().open(), because you already called it once in the if statement, it is redundant

get rid of the inventory.isFull() in the same if statement as above, because you already checked it once, so checking it a second time is redundant

the conditionalSleeps that you are using can be broken, the timeout is longer than the sleep delay check (the constructor is ConditionalSleep(int timeout, int sleepTime))

the indentation at the end is confusing, you should probably clean that up (banking has a lot of issues in general)

you called ore.isVisible() before nullchecking ore, so it could throw a null pointer exception

probably some more that I missed

Link to comment
Share on other sites

  On 7/5/2018 at 2:57 AM, D Bolter said:

Congrats on your first script man. May I ask what guides on osbot helped you learn about the API?

Expand  

Thanks man! I watched some youtube videos and read tutorials here on the forums as well as read snippets of scripts to get an idea how to type the code.

Chris has a discord as well where he teaches you the basics of coding. Here are some links that were very helpful to me:

 

 

 there is a link to the discord ^ up there.

Also I've just started watching these youtube guides which are very helpful: 

Gl man :D

Edited by meganide97
  • Like 1
Link to comment
Share on other sites

  On 7/5/2018 at 10:44 AM, CJ7 said:

Also, I believe this piece of code:

if (!ore.isVisible()){
                getCamera().toEntity(ore);
            }

aside from the possibility of causing nullpointer exceptions is also unnecassesary, since you're calling "ore.interact" after that. Interact also moves the camera! 

Expand  

Thanks! Removed that line from the code, also as Chris pointed out I did this command before even nullchecking which was a mistake :)

Link to comment
Share on other sites

  On 7/5/2018 at 5:55 AM, dogetrix said:

Not bad for 2 days of study.

 

Here are some specifics:

you can get rid of the second call to getBank().open(), because you already called it once in the if statement, it is redundant

get rid of the inventory.isFull() in the same if statement as above, because you already checked it once, so checking it a second time is redundant

the conditionalSleeps that you are using can be broken, the timeout is longer than the sleep delay check (the constructor is ConditionalSleep(int timeout, int sleepTime))

the indentation at the end is confusing, you should probably clean that up (banking has a lot of issues in general)

you called ore.isVisible() before nullchecking ore, so it could throw a null pointer exception

probably some more that I missed

Expand  

Thanks for the feedback! Cleaned the code up a little, but what I don't understand is why I should get rid of the call to getBank().open(), if I remove this line it won't open up the bank.

 

Edit: Just tried what you said and it opened up the bank anyway, does the deposit function also open the bank? I'm kinda confused here as to what command decided to open the bank.

Edited by meganide97
Link to comment
Share on other sites

  On 7/5/2018 at 1:00 PM, Explv said:
Expand  

Old accounts I created before, I tried running several clients at once but didn't work and I didn't know it was against the rules to have several accounts, however this is the only account I use now that I'm better informed. You can go ahead and remove those accounts, thanks.

  On 7/5/2018 at 3:24 AM, Chris said:

Logic needs to be relooked at and worked on

possible nullpointer before you even check if ore is null

banking is poor logic and can be rewritten. You can see an example here: https://github.com/christophernarciso/programming/blob/master/Meire %26 Brito Automation [OSBot.org]/OSBot Scripting Open Source Projects/Scripts/CAccountEvaluator/src/Evaluator.java#L108

Expand  

Thanks for the feedback, have cleaned up the code a little will update soon :)

Link to comment
Share on other sites

@meganide97

The bank will still open because of the statement in the if. in the if statement you have !getBank().open(). The open() method tries to open the bank and returns true or false. This means that the bot will try to open the bank while your code is in the if statement. If the bank opens successfully, it will return true and you won't go to that part of your code again. Therefore calling getBank().open() again inside of the if statement is basically pointless

Link to comment
Share on other sites

  On 7/5/2018 at 4:47 PM, dogetrix said:

@meganide97

The bank will still open because of the statement in the if. in the if statement you have !getBank().open(). The open() method tries to open the bank and returns true or false. This means that the bot will try to open the bank while your code is in the if statement. If the bank opens successfully, it will return true and you won't go to that part of your code again. Therefore calling getBank().open() again inside of the if statement is basically pointless

Expand  

I see now, thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...