Jump to content

Mouse click broken?


Rudie

Recommended Posts

In my firemaking script I'm working on I want that if it accidentally wants to light fires at a tile where already is a fire to move a coord.

This is what I've tried:

    		RS2Object fire = objects.closest("Fire");
    		if(fire.getY() == myPlayer().getY()) {
    			mouse.click(myPlayer().getX(), myPlayer().getY() + 1, true);
    			log("help");
    		}

(Placed the log "help" there to debug and yes it does spam help in the console.)

This doesn't work, I've also tried with the MessageListener like this:

		if (txt.contains("light a fire here")) {
			mouse.click(myPlayer().getX(), myPlayer().getY() + 1, true);
			sleep(random(150, 250));
		}

But none of it works, so I'm wondering is it broken in the API or is there another better way to do this? Cause I really need it.

 

Thanks,

 

Rudie.

Edited by Rudie
Link to comment
Share on other sites

In my firemaking script I'm working on I want that if it accidentally wants to light fires at a tile where already is a fire to move a coord.

This is what I've tried:

    		RS2Object fire = objects.closest("Fire");
    		if(fire.getY() == myPlayer().getY()) {
    			mouse.click(myPlayer().getX(), myPlayer().getY() + 1, true);
    			log("help");
    		}

(Placed the log "help" there to debug and yes it does spam help in the console.)

This doesn't work, I've also tried with the MessageListener like this:

		if (txt.contains("light a fire here")) {
			mouse.click(myPlayer().getX(), myPlayer().getY() + 1, true);
			sleep(random(150, 250));
		}

But none of it works, so I'm wondering is it broken in the API or is there another better way to do this? Cause I really need it.

 

Thanks,

 

Rudie.

 

This code... would never work. Your comparing players X/Y ingame coords to mouse coords, only increasing the mouse Y by 1, nice try though :p

myPlayer().getPosition().translate(0, 1).interact("Walk here");

Should work.

Edited by dudeami
Link to comment
Share on other sites

This code... would never work. Your comparing players X/Y ingame coords to mouse coords, only increasing the mouse Y by 1, nice try though tongue.png

myPlayer().getPosition().translate(0, 1).interact("Walk here");

Should work.

I get this error:

The method interact(Bot, String...) in the type Position is not applicable for the arguments (String)

 

Still need this, localwalker wont walk for me to that specific tile..

Link to comment
Share on other sites

Got it, this is working for me right now:

RS2Object fire = objects.closest("Fire");
if(fire.getY() == myPlayer().getY() && fire.getX() == myPlayer().getX()) {
int a = Integer.parseInt(""+myPlayer().getY()+"");
int b =  Integer.parseInt(""+a+"") + 1 ;
int c = Integer.parseInt(""+myPlayer().getX()+"");
int d =  Integer.parseInt(""+c+"") + 1 ;
   Position path = new Position(d, b, 0);
   path.interact(bot, "Walk here");
log("ot works");
sleep(random(150, 250));
}
Thanks for everyone who tried to help! smile.png
Link to comment
Share on other sites

fire.getX() is getting the X coordinate for the fire. You need to get the x and y coordinates then add 1 to this but then you are doing the click wrong. mouse.click cannot be fed coordinates. It clicks the position on the screen mouseX, mouseY. You need to calculate what the screen mouse coordinates are for tht tile. You are confusing the 2. Tile coordinates (position in runescape world) and mouse sxreen coordinates, where 0, 0 means the top left of the screen.

Link to comment
Share on other sites

 

Got it, this is working for me right now:

RS2Object fire = objects.closest("Fire");
if(fire.getY() == myPlayer().getY() && fire.getX() == myPlayer().getX()) {
int a = Integer.parseInt(""+myPlayer().getY()+"");
int b =  Integer.parseInt(""+a+"") + 1 ;
int c = Integer.parseInt(""+myPlayer().getX()+"");
int d =  Integer.parseInt(""+c+"") + 1 ;
   Position path = new Position(d, b, 0);
   path.interact(bot, "Walk here");
log("ot works");
sleep(random(150, 250));
}
Thanks for everyone who tried to help! smile.png

 

int a = Integer.parseInt(""+myPlayer().getY()+"");
int b =  Integer.parseInt(""+a+"") + 1 ;
int c = Integer.parseInt(""+myPlayer().getX()+"");

What did I just read....

You take an int turn it into a string an then parse an int out of it again.

Don't do that.

Ever.

  • Like 1
Link to comment
Share on other sites

int a = Integer.parseInt(""+myPlayer().getY()+"");
int b =  Integer.parseInt(""+a+"") + 1 ;
int c = Integer.parseInt(""+myPlayer().getX()+"");

What did I just read....

You take an int turn it into a string an then parse an int out of it again.

Don't do that.

Ever.

 

I know it is a horrible way of doing it but I couldn't get it to work any other way, but it worked so I didn't care to change it.

Link to comment
Share on other sites

I know it is a horrible way of doing it but I couldn't get it to work any other way, but it worked so I didn't care to change it.

what he is saying is that those methods return an int already. what you have there is an int, then you convert it into string. Then once you have the string you convert it into an int again.

 

int a = myPlayer().getY(); //works perfectly fine

Link to comment
Share on other sites

I know it is a horrible way of doing it but I couldn't get it to work any other way, but it worked so I didn't care to change it.

		RS2Object fire = objects.closest("Fire");
		if (fire != null && fire.exists() && fire.getPosition().equals(myPosition())) {
			new Position(myPosition().getX() + 1, myPosition().getY() + 1, myPosition().getZ()).interact(getBot(), "Walk here");
			sleep(random(150, 250));
		}
Edited by Botre
Link to comment
Share on other sites

what he is saying is that those methods return an int already. what you have there is an int, then you convert it into string. Then once you have the string you convert it into an int again.

 

int a = myPlayer().getY(); //works perfectly fine

Just thought about it and yes I could have done that and might change it in the script to clean it up. But please keep in mind that I'm a learning Java developer and was just doing everything I could to get it to work. Thanks for pointing out that that is a stupid way to do it, that way I keep learning and keep getting better at programming in Java smile.png

		RS2Object fire = objects.closest("Fire");
		if (fire != null && fire.exists() && fire.getPosition().equals(myPosition())) {
			new Position(myPosition().getX() + 1, myPosition().getY() + 1, myPosition().getZ()).interact(getBot(), "Walk here");
			sleep(random(150, 250));
		}

I have tried doing it by doing myPosition.getX() + 1 but it would add the number right after the coord so like if the coord was 3444 it would change to 34441, I remembered this was a problem once in my class at javascript where we had to do something similiar to this and the teacher told us about parseInt, I looked it up if there was something like that in Java and eventually did it that way.

Link to comment
Share on other sites

Just thought about it and yes I could have done that and might change it in the script to clean it up. But please keep in mind that I'm a learning Java developer and was just doing everything I could to get it to work. Thanks for pointing out that that is a stupid way to do it, that way I keep learning and keep getting better at programming in Java smile.png

 

Today you both solved a problem AND you learned something new.

#winning

 

(now go fix that conversion thingie ph34r.png )

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