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.

Better Than a Script Instance

Featured Replies

Typically in most tutorial or snippet with in OSB. You have many of them telling you to create a script instance with in a new class. So that your allowed to use methods within the Script instance. Now i found a better and easier way of doing this. 

 

So here an example class

public class WorldHopper {
	
	private Script script;
	
	public final static int[] P2P_WORLDS = {301, 302, 303, 304, 305, 306, 309, 310, 311, 312,
		313, 314, 317, 318, 319, 320, 321, 322, 326, 327, 328, 329, 330, 333, 334, 335,
		336, 338, 341, 342, 343, 344, 345, 346, 349, 350, 351, 352, 353, 354, 357, 358,
		359, 360, 361, 362, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377, 378};	
	
	public final static int[] F2P_WORLDS = {308, 316};
	
	public final static int[] PVP_WORLDS = {325, 337};

	public final static int[] TRIAL_WORLDS = {381, 382, 383, 384, 393, 394};
	
	public WorldHopper(Script script)	{
		this.script = script;
	}
	
	public void hopWorld(int...worlds)	{
		List<Integer> worldList = new ArrayList<Integer>(); 
		
		for (int world: worlds){
			worldList.add(world);
		}
		
		if (script.interfaces.closeOpenInterface())	{
			int index = MethodProvider.random(worldList.size());
			script.worldHopper.hop(worldList.get(index));			
		}else{
			script.log("can't close open interface");
		}
	}	

}

 

See how within your class constructor you have Script argument that will initialize your private field Script. So whenever you want to use the bank. You'll have to use your script instance then call the bank method. Finally call the methods you want to use from the bank class.

 

What you should do stead would be to extend Method Provider. Then within the constructor you will use the method within the Method Provider class to help you initialize all the classes it has.

 

Example of the code above redone.

public class WorldHopper extends MethodProvider{
		
	public final static int[] P2P_WORLDS = {301, 302, 303, 304, 305, 306, 309, 310, 311, 312,
		313, 314, 317, 318, 319, 320, 321, 322, 326, 327, 328, 329, 330, 333, 334, 335,
		336, 338, 341, 342, 343, 344, 345, 346, 349, 350, 351, 352, 353, 354, 357, 358,
		359, 360, 361, 362, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377, 378};	
	
	public final static int[] F2P_WORLDS = {308, 316};
	
	public final static int[] PVP_WORLDS = {325, 337};

	public final static int[] TRIAL_WORLDS = {381, 382, 383, 384, 393, 394};
	
	public WorldHopper(Script script)	{
        exchangeContext(script.bot);

	}
	
	public void hopWorld(int...worlds)	{
		List<Integer> worldList = new ArrayList<Integer>(); 
		
		for (int world: worlds){
			worldList.add(world);
		}
		
		if (interfaces.closeOpenInterface())	{
			int index = MethodProvider.random(worldList.size());
			worldHopper.hop(worldList.get(index));			
		}else{
			log("can't close open interface");
		}
	}	
}

I'm not seeing why this is better. It prevents you from extending something more important, even if you don't have anything else to extend, is this just to avoid typing script?

Umm wouldn't this create a ton of unnecessary MethodProvider class instances? Passing it via constructor just passes the reference, keeping the heap clean.

  • Author

dude i was just lazy i ddint really want to create a new instance and have to go about using that. Rather then having it already initialize.

dude i was just lazy i ddint really want to create a new instance and have to go about using that. Rather then having it already initialize.

 

Well that's why a lot of people including myself when I wrote scripts use the Node frame, since your able to store your method provider instance inside of the NodeWrapper, allowing you to use it throughout all your nodes, which I'm sure you already know.

 

Though as @Swizzbeat said above, this creates a unnecessary amount of method provider instances; when in reality, you only need one, and have it passed around like a dirty whore.

 

The less redundant instantiations, the better. :)

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.