Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

interactAndWait(), castSpellOn(Spell spell, Entity entity)

Featured Replies

Want to share some snippets i'm using. Dont sure if they are needed by scripters, but...

 

The first is function that interacts with object, and then waits until movement and animations will end.

If interact insuccessful, returns false without waiting.

public static boolean interactAndWait(Script scp, Player player, RS2Object obj, String action) throws InterruptedException{
		if(player.isMoving() || player.isAnimating()){
    		do{
    			scp.sleep(100);
    		} while(player.isMoving() || player.isAnimating());
    		scp.sleep(200);
    	}
    	//if(!obj.isVisible()){
    	//	scp.client.moveCameraToEntity(obj);
    	//	return false;
    	//}
    	
    	if(obj.interact(action)){
    		scp.sleep(500);
    		while(player.isMoving()){
    			scp.sleep(100);
    		}
    		int x = player.getX();
    		int y = player.getY();
    		int z = player.getZ();
    		scp.sleep(1500);
    		while(player.isAnimating())
    			scp.sleep(100);
    		if(action == "Pull"){
    			Date start = new Date();
    			while(true)
    			{
    				if((new Date().getTime() - start.getTime()) >= 5000){
    					scp.log("break by time");
    					break;
    				}
    				if(player.getX()!=x || player.getY()!=y || player.getZ()!=z){
    					scp.log("break by loc");
    					break; //teleported
    				}
    				scp.sleep(100);
    			}
    		}
    		return true;
    	}
    	return false;
	}

The second is casting spell on entity routine, with improved accuracy (tries to click by horizontal and vertical around bounding box center of entity). CHECK IT in your case!

public boolean castSpellOn(Spell spell, Entity entity) throws InterruptedException{
		scp.magicTab.castSpell(spell);
		sleep(200, 300);
		for(int i = 0; i<7; i++){
			Rectangle bb = entity.getMouseDestination().getBoundingBox();
			//Rectangle bbmodified = new Rectangle(bb.x - bb.width/2, bb.y - bb.height/2, bb.width, bb.height);
			int x = (int)bb.getCenterX();
			int y = (int)bb.getCenterY();
			if(i==0){
				if(!client.moveMouseTo(entity.getMouseDestination(), false, false, false))
					return false;
			}
			if(i==1){
				if(!client.moveMouseTo(new RectangleDestination(x - 10, y - 10, 4, 4), false, false, false))
					return false;
			}
			if(i==2){
				if(!client.moveMouseTo(new RectangleDestination(x - 2, y - 12, 4, 4), false, false, false))
					return false;
			}
			if(i==3){
				if(!client.moveMouseTo(new RectangleDestination(x + 10, y - 10, 4, 4), false, false, false))
					return false;
			}
			if(i==4){
				if(!client.moveMouseTo(new RectangleDestination(x + 10, y + 10, 4, 4), false, false, false))
					return false;
			}
			if(i==5){
				if(!client.moveMouseTo(new RectangleDestination(x - 2, y + 12, 4, 4), false, false, false))
					return false;
			}
			if(i==6){
				if(!client.moveMouseTo(new RectangleDestination(x - 10, y + 10, 4, 4), false, false, false))
					return false;
			}
			sleep(100, 150);
			Option opt = client.getMenu().get(0);
			if(opt==null)
				continue;
			if(!opt.action.equals("Cast"))
				continue;
			if(!opt.noun.contains(entity.getName()))
				continue;
			client.clickMouse(false);
			return true;
		}
		return false;
	}
	

For dynamic sleeping:

 

 1. Create a new interface XDynamicSleep with an abstract canAwake method.

public interface XDynamicSleep {

	public boolean canAwake();

}

 2. If you've got a script framework, implement this into it, else just throw it in your script somewhere:

public boolean sleep(long base, long offset, XDynamicSleep sleep)
	throws InterruptedException {
	
	if (base < 0 || sleep == null)
		throw new IllegalArgumentException();
	
	long start = System.currentTimeMillis();
	
	base += MethodProvider((int) offset);
	offset = (long) (base * 0.1);
	
	while (start + base > System.currentTimeMillis()) {
		if (sleep.canAwake())
			return true;
		else
			sleep(offset);
	}
	return false;
}

 3. Time to sleep! Example:

	. . .
	
	if (goblin.interact("attack"))
		if (sleep(3000, 2000, new XDynamicSleep() {
				@Override
				public boolean canAwake() {
					return !goblin.exists();
				}
			})
		) {
			//Sleep was interrupted, goblin must have died
		} else {
			//Sleep slept to the full length... Time to revalidate
			//our situation!
		}

	. . .

I wrote this up in NotePad++ so there might be syntax errors.

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.