Jump to content

Never really coded in java, where to start


archiebaker

Recommended Posts

So its more the syntax, i've coded in various languages such as visual basic, pascal/delphi and others. I'm fairly familiar with programming concepts and study A2 computing.

 

The real question is where to start coding java for bots? Ideally I just want to make a simple bot to say, enchant jeweley with a reliable-ish antiban. Sorry if I may need spoonfeeding at first but I figured its best to make my own stuff than always use everyone else's and maybe even give back to the community if i become experienced enough

Link to comment
Share on other sites

So its more the syntax, i've coded in various languages such as visual basic, pascal/delphi and others. I'm fairly familiar with programming concepts and study A2 computing.

 

The real question is where to start coding java for bots? Ideally I just want to make a simple bot to say, enchant jeweley with a reliable-ish antiban. Sorry if I may need spoonfeeding at first but I figured its best to make my own stuff than always use everyone else's and maybe even give back to the community if i become experienced enough

 

There are plenty of Java tutorials on the internet.

 

Once you are familiar with Java read the scripting tutorials in the Scripting help section, and check out the API which can be found in the navigation bar above.

Edited by Explv
Link to comment
Share on other sites

If you have some programming experience you can download Core Java Volume 1, which is a nice introduction to java imo. Then just read some of the open source scripts and use the api docs and you should be fine.

Sorry if this is naive but are local scripts and open source the same thing? Can i decompile them to get the 'raw' code?

Link to comment
Share on other sites

Sorry if this is naive but are local scripts and open source the same thing? Can i decompile them to get the 'raw' code?

Yep, some post the source and if there's no source you can just decompile it. Note that a lot of scripts posted there are not the most well-structured programs around, but it's useful to see how the API is being used by others.

Link to comment
Share on other sites

osbot.org/forum/topic/58775-a-beginners-guide-to-writing-osbot-scripts-where-to-get-started-by-apaec/

 

should hopefully cover the very basics! smile.png

 

apa

I literally went over this about 5-10 minutes after writing this post! The guide was really informative! Its more the fact I don't understand how to open banks reliably (Without spam clicking) etc which is more where I'm trying to learn stuff from. 

 

I've been looking at the API and picked up a bit but some of it still confuses me because not that many of them have understandable examples D:

 

Also any idea why this isn't working? I guess i forgot to define its class (Or whatever its called) at  the top of the project?

post-55295-0-04523400-1452959844_thumb.png

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

I literally went over this about 5-10 minutes after writing this post! The guide was really informative! Its more the fact I don't understand how to open banks reliably (Without spam clicking) etc which is more where I'm trying to learn stuff from. 

 

I've been looking at the API and picked up a bit but some of it still confuses me because not that many of them have understandable examples D:

 

Yea, I think a great addition to the API would be some worked examples . They would really help newer scripters get started, however if you're good at reading API docs from other areas (even standard java libs), it makes it alot easier.

 

 

As for opening banks, you can do stuff like

 

i

if (bank.isOpen()) {
//withdraw stuff etc
} else {
RS2Object bank = objects.closest("Bank booth");
if (bank != null && bank.exists()) {
bank.interact("Open");Timer t = new Timer(0L);
while (!bank.isOpen() && t.getElapsed() < timeout) {
sleep(400);
}
}

thats a really basic example which I wrote in the reply box, should do the trick but you will need a timer class. Theres simpler ways with conditional sleep (check api for this one), but that works fine too.

 

apa

 

 

Link to comment
Share on other sites

I literally have no idea how to even withdraw, i've looked through some open source code on here but it just seems to parse an error whenever I stick it in my IDE

 

EDIT: I think I understand how to withdraw now. 

However i'm not quite sure how the timer works [More how to set it up]

 

Or just conditional sleep as that seems easier to use. Yet i'm not sure how use that either xD

Edited by archiebaker
Link to comment
Share on other sites

I've spent the past month of so trying to learn how to start writing scripts here with little-to-no experience in coding. What helped me the most was looking through the downloadable script section, downloading .jars that people posted, and try to read their scripts and understand what they're doing, and why. It's also a good idea to read scripts written for other botting sites. Just keep in mind that by doing this, you may not be looking at the most optimized code. If you can find source code for more premium bots that would be a huge help for you to learn from.

 

Also, about the conditional sleeping talk above, here is how Explv showed me to do it:

new ConditionalSleep(7000) {

		@Override
		public boolean condition() throws InterruptedException {
			return (S.chatbox.isVisible());	
		}
	}.sleep();

If this needs explaining, this method will sleep until the condition you input returns true. However, if the condition never returns true, it will only sleep the preset amount. So the conditional sleep above will sleep until the chatbox is visible, but if the chatbox is never visible, it will stop sleeping after 7 seconds

 

I've tried to condense it down since conditional sleeps are so common, but I couldn't get it to work :( Here's how I tried, maybe someone will know why this didnt work:

	public void customSleep(boolean sleepUntil, int sleepMax){
		
		new ConditionalSleep(sleepMax) {

			@Override
			public boolean condition() throws InterruptedException {
				return (sleepUntil);
			}
		}.sleep();
		
	}
Edited by ikk
  • Like 1
Link to comment
Share on other sites

 

I've spent the past month of so trying to learn how to start writing scripts here with little-to-no experience in coding. What helped me the most was looking through the downloadable script section, downloading .jars that people posted, and try to read their scripts and understand what they're doing, and why. It's also a good idea to read scripts written for other botting sites. Just keep in mind that by doing this, you may not be looking at the most optimized code. If you can find source code for more premium bots that would be a huge help for you to learn from.

 

Also, about the conditional sleeping talk above, here is how Explv showed me to do it:

new ConditionalSleep(7000) {

		@Override
		public boolean condition() throws InterruptedException {
			return (S.chatbox.isVisible());	
		}
	}.sleep();

If this needs explaining, this method will sleep until the condition you input returns true. However, if the condition never returns true, it will only sleep the preset amount. So the conditional sleep above will sleep until the chatbox is visible, but if the chatbox is never visible, it will stop sleeping after 7 seconds

 

I've tried to condense it down since conditional sleeps are so common, but I couldn't get it to work sad.png Here's how I tried, maybe someone will know why this didnt work:

	public void customSleep(boolean sleepUntil, int sleepMax){
		
		new ConditionalSleep(sleepMax) {

			@Override
			public boolean condition() throws InterruptedException {
				return (sleepUntil);
			}
		}.sleep();
		
	}

It will not work because the condition is evaluated exactly once, when the method is called.

I've created something similar using a custom interface:

 

public interface Condition {

    boolean eval(MethodProvider api);

}

In your script:

private boolean sleep(int millis, Condition cond) {
        MethodProvider api = this;

        return new ConditionalSleep(millis) {
            public boolean condition() {
                return cond.eval(api);
            }
        }.sleep();
    }

Now you can do:

 

sleep(2000, api -> api.myPlayer().isAnimating());
Edited by Flamezzz
  • Like 1
Link to comment
Share on other sites

Alright thankyou! I sort of understand this with my basic one day knowledge of java so thankyou biggrin.png! I made my first script and it ran for 1-2hours flawlessly (From what I can tell) until it ran out of materials biggrin.png

Hey! Congrats man! It felt so rewarding when my first script finally started to run flawlessly. 

 

Forgot to mention it above, but if you wanted to take a look at other people's .jars on here then it would be a good idea to download a Java decompiler. I've been using JD GUI and it's a piece of cake to use

 

 

 

It will not work because the condition is evaluated exactly once, when the method is called.

I've created something similar using a custom interface:

 

public interface Condition {

boolean eval(MethodProvider api);

}

In your script:

private boolean sleep(int millis, Condition cond) {

MethodProvider api = this;

return new ConditionalSleep(millis) {

public boolean condition() {

return cond.eval(api);

}

}.sleep();

}

Now you can do:

 

sleep(2000, api -> api.myPlayer().isAnimating());

 

Oh wow, that makes a lot of sense. I know so little about Java at the moment I don't think I could have figured that one out on my own right now tbh. But that is a big help, thanks :D

Link to comment
Share on other sites

Hey! Congrats man! It felt so rewarding when my first script finally started to run flawlessly. 

 

Forgot to mention it above, but if you wanted to take a look at other people's .jars on here then it would be a good idea to download a Java decompiler. I've been using JD GUI and it's a piece of cake to use

 

 
 

Thankyou :D

 

JD-GUI is what is used with Eclipse right? If so, how does one work that? 

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...