Adblock breaks this site

usefull RS functions ins JAVA

Discussion in 'Programming General' started by slashshot007, Nov 22, 2007.

  1. slashshot007

    slashshot007 Active Member

    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0
    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);
    	}
     
  2. timk777

    timk777 Active Member

    Joined:
    Feb 19, 2007
    Posts:
    156
    Referrals:
    0
    Sythe Gold:
    0
    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.
     
  3. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    usefull RS functions ins JAVA

    These could be useful for some people, too bad nobody here is interested in Java :/
     
  4. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    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
     
  5. slashshot007

    slashshot007 Active Member

    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0
    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.
     
  6. isosceles

    isosceles Forum Addict
    $5 USD Donor

    Joined:
    Jan 22, 2007
    Posts:
    455
    Referrals:
    0
    Sythe Gold:
    0
    usefull RS functions ins JAVA

    Thanks, very helpful.

    I have been fooling around with the robot class lately, and this should prove useful.
     
  7. rscheater13

    rscheater13 Guest

    Referrals:
    0
    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
     
  8. slashshot007

    slashshot007 Active Member

    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0
    usefull RS functions ins JAVA

    http://www.sythe.org/showthread.php?t=304438
     
  9. Big Knockers

    Big Knockers Member
    Banned

    Joined:
    Oct 8, 2007
    Posts:
    72
    Referrals:
    0
    Sythe Gold:
    0
    usefull RS functions ins JAVA

    Pretty helpful. Thank for saying



    -Big Knockers
     
  10. Shlorine

    Shlorine Guest

    Referrals:
    0
    usefull RS functions ins JAVA

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

    Shit
    Compare To
    Auto
    Rune
     
  11. _3x6

    _3x6 Active Member
    Banned

    Joined:
    Dec 23, 2007
    Posts:
    232
    Referrals:
    0
    Sythe Gold:
    0
    usefull RS functions ins JAVA

    is it scar or not?
     
< java 1.6 for mac | problems with java autominer >


 
 
Adblock breaks this site