Jump to content

MidnightBlue

Members
  • Posts

    10
  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by MidnightBlue

  1. Here's the new script skeleton you will be using, please import the class files down below as these are not in the OsBot API.

     

    In the scriptStart method, add your class, or classes that extend my custom Node class. (Example shown below)

    package ca.midnightblue.scripts.wc;
    
    import java.awt.Graphics2D;
    import org.osbot.rs07.script.ScriptManifest;
    import ca.midnightblue.scripts.wc.nodes.Idling;
    
    @ScriptManifest(name = "Custom Script Skeleton", author = "Midnight Blue", version = 1.0, info = "", logo = "")
    public class Core extends CustomScript {
    
    	@Override
    	public void scriptStart() {
    		add(Woodcut.class, Walk.class, Bank.class);
    	}
    
    	@Override
    	public void scriptStop() {
    
    	}
    
    	@Override
    	public void loop() {
    		
    	}
    	
    	@Override
    	public void paint(Graphics2D g) {
    		
    	}
    }
    

    Now in your classes that extend Node, which will contain the back bone aka the script functionality, the function "loop" that returns an integer is where you want to put what the bot does during that loop, you will return the amount of time you want the bot to sleep, by default it sleeps a random interval of 10 to 100MS. Your validate method will return when you want this script to activate. (You don't want to run all of your scripts at the same time) And lastly, your getStatus method should return a string with a brief description of what the bot is doing at the moment. Example: If your bot is banking return "banking".

     

    Here's an example of how to use my new script skeleton

    package ca.midnightblue.scripts.wc.nodes;
    
    import org.osbot.rs07.script.Script;
    
    public class Idling extends Node {
    	
    	private long then;
    	
    	public Idling(Script script) {
    		super(script);
    		then = System.currentTimeMillis();
    	}
    
    	@Override
    	public int loop() {
    		long now = System.currentTimeMillis();
    		if(now - then <= 300000L) { //every 5 minutes
    			then = now;
    			//open tabs or something
    		}
    		return 0;
    	}
    
    	@Override
    	public boolean validate() {
    		return !script.myPlayer().isMoving();
    	}
    
    	@Override
    	public String getStatus() {
    		return "Idling";
    	}
    }
    
    

    Node.java

    package ca.midnightblue.scripts.wc.nodes;
    
    import org.osbot.rs07.script.Script;
    
    public abstract class Node {
    	
    	protected final Script script;
    
    	public Node(Script script) {
    		this.script = script;
    	}
    
    	public abstract int loop();
    
    	public abstract boolean validate();
    	
    	public abstract String getStatus();
    }
     

     

    CustomScript.java

    package ca.midnightblue.scripts.wc;
    
    import java.awt.Graphics2D;
    import java.lang.reflect.InvocationTargetException;
    import java.util.ArrayList;
    import org.osbot.rs07.script.Script;
    import ca.midnightblue.scripts.wc.nodes.Node;
    
    public abstract class CustomScript extends Script {
    	
    	protected ArrayList<Node> nodes = new ArrayList<Node>();
    	protected Script script;
    	
    	@Override
    	public void onStart() {
    		script = this;
    		scriptStart();
    	}
    
    	@Override
    	public void onExit() {
    		scriptStop();
    	}
    
    	@Override
    	public int onLoop() {
    		for(Node n : nodes) {
    			loop();
    			return n.loop();
    		}
    		return random(10, 100);
    	}
    
    	@Override
    	public void onPaint(Graphics2D g) {
    		paint(g);
    	}
    	
    	protected void add(Class<? extends Node>... node) {
    		for(Class c : node) {
    			try {
    				Node n = (Node) c.getConstructor(Script.class).newInstance(script);
    				if(!nodes.contains(n))
    					nodes.add(n);
    			} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    	
    	public abstract void scriptStart();
    	public abstract void scriptStop();
    	public abstract void loop();
    	public abstract void paint(Graphics2D g);
    }
    
    

     

    Hope you enjoy! :-) Please comment if you like this noob-friendly node snippet I made!

    • Like 1
  2. So when the inventory tab is open, I want to draw a rectangle around a certain slot.

    here's my code

    if(Tab.INVENTORY.isOpen(null)) {
    			Rectangle slot = client.getInventory().getDestinationForSlot(1);
    			g.drawRect(slot.x, slot.y, slot.width, slot.height);
    		}
    

    isOpen requires a paramater of the type RS2InterfaceChild, I've got no clue as to what to put for the parameter. Can somebody help me?

  3. So I'm using this custom type method because the built in type method uses delay. So I want to simulate hitting the enter key but it won't work, I think I have to add some delay between hitting the keys and hitting enter but I don't know if you can. Can somebody please check out my code?

     

    	public void test(String message) throws InterruptedException {
    		for(char c : message.toCharArray()) {
    			 bot.getKeyboard().typeKeyEvent(c, 0);
    		}
    		bot.getKeyboard().typeKeyEvent((char) KeyEvent.VK_ENTER, 0);
    	}
    
  4. I'm making a private price checker bot for my clan chat, here's the code I'm using.

     

    client.typeString("/" + args[1] + " - " + (price == 0 ? "not tradable" : price));
    

    Is there a way I can set the typing speed or the interval in milliseconds per character, such as:

     

    client.setTypingSpeed(7);
    

    If there's any possible way to do this, it would be greatly appreciated if you could help me out. Thanks in advanced. (:

×
×
  • Create New...