• Log in or sign up for an account here: https://www.sythe.org/login

usefull RS functions ins JAVA

slashshot007

Active Member
Joined
May 6, 2006
Sythe Gold
0
Messages
164
usefull RS functions ins JAVA
Movemouse Smooth:
yeah.. credits go to flaming idiots for the code, i just converted it to java.
heres the import statements needed:
Code:
import java.awt.*;

and heres the code
Code:
	public void SmoothMove(Point Destination, double Speed){
   		try {
	   		Robot robot = new Robot();
	   		PointerInfo PInfo = MouseInfo.getPointerInfo();
			Point origin = PInfo.getLocation();
	   		Point Difference = new Point((int)(Destination.getX() - PInfo.getLocation().getX()),(int)(Destination.getY() - PInfo.getLocation().getY()));				
			for(double Current = 0; Current < 1; Current+= (Speed/Math.sqrt(Math.pow(Difference.getX(),2) + Math.pow(Difference.getY(),2)))){
				PInfo = MouseInfo.getPointerInfo();
				robot.mouseMove((int)origin.getX() + (int)(Difference.getX() * Current),(int)origin.getY() + (int)(Difference.getY() * Current););
				robot.setAutoDelay(3);
			}
			}catch(java.awt.AWTException exc) {
				System.out.println("error");
			}	
	}

findColor
I made a basic findColor function - it probably could be done in less code, but i'm too lazy to try and fingure it out so this is what you're stuck with unless you know how to change it. It returns a Point if you can't figure that out from the code.
if it cannot find the color in the rectangle, it will return the point as x = -1, y = -1

x1 is the x coordinate of the upper left point of the Rectangle that will be searched. y1 is the y coordinate.
x2 is the x coordinate of the bottom right point of the Rectangle, and y2 is the Y coordinate.

heres the import statements needed:
Code:
import java.awt.*;

and heres the code:
Code:
	private static Point findColor(Color color, int x1, int y1, int x2, int y2){
		try {
			Robot robot = new Robot();
			for(int x = x1; x<x2; x++)
				for(int y = y1; y<y2;y++)
					if(robot.getPixelColor(x,y).equals(color))
						return new Point(x,y);
		}catch(java.awt.AWTException exc) {
			return new Point(-1,-1);
		}
		return new Point(-1,-1);
	}
EDIT:I updated the findcolor code DRASTICALLY. Now is much more efficient. still does everything the same way though.

EDIT AGAIN:
ok i found a much more efficient method, i've been told that getPixelColor can get very slow so heres a much faster way:
usage remains the same
Code:
	private static Point findColor(Color color, int x1, int y1, int x2, int y2){
		try {
			Robot robot = new Robot();
			BufferedImage image = robot.createScreenCapture(new Rectangle(x1-1,y1-1,Math.abs(x1-x2)+1,Math.abs(y1-y2)+1));
			int colorint = color.getRGB();
			for(int y = 0; y < y2-y1; y++)
				for(int x = 0; x < x2-x1 ; x++)
					if(image.getRGB(x,y)==colorint){					
						return new Point(x+x1,y+y1);
		}catch(java.awt.AWTException exc) {
			return new Point(-1,-1);
		}
		return new Point(-1,-1);
	}
 
usefull RS functions ins JAVA
Nice work Slashshot. Haven't talked to you in a while. Keep up the good work though. I'm glad to see people still using Java besides Moparscape.
 
usefull RS functions ins JAVA
These could be useful for some people, too bad nobody here is interested in Java :/
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
usefull RS functions ins JAVA
I am interseted in Java. And i have been looking for something like this cuz I am very lazy to write my own code XD
 
usefull RS functions ins JAVA
be sure to give credit SuF

and also i updated the FindColor so its ALOT smaller, but still can be used the same way, and is still done the same way.
 
usefull RS functions ins JAVA
Thanks, very helpful.

I have been fooling around with the robot class lately, and this should prove useful.
 
usefull RS functions ins JAVA
Nice. I started writing the SendKeys method, but it's being a pain in the butt. You might wanna add that, as it can be easier than keyPress keyRelease
 
usefull RS functions ins JAVA
Pretty helpful. Thank for saying



-Big Knockers
 
usefull RS functions ins JAVA
Nice. I started writing the SendKeys method, but it's being a pain in the butt. You might wanna add that, as it can be easier than keyPress keyRelease

btw that buldozer in your avy, it isnt original SCAR its Autorune.

Shit
Compare To
Auto
Rune
 
usefull RS functions ins JAVA
is it scar or not?
 
Runescape Gamblingrunescape gambling
Back
Top