Jump to content

Nothing happens when i run script?


potatoer

Recommended Posts

I just started scripting and i have compiled my first script but it doesn't run X.x (shocker) could anyone give me pointers.

It goes from bank to a building, checks door if open, walks in, climbs stairs, walks to cupboard, open cupboard if closed if not clicks open cupboard. I plan to add inv checks and it will return to bank then start over. Take it easy on me :) and thank you for your help biggrin.png

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.model.Entity;

import java.awt.*;


@ScriptManifest(name = "GarlicGrabber", author = "Potatoer", version = 1.0, info = "", logo = "") 
public class Skeleton extends Script {




    @Override
    public void onStart() {
        //Code here will execute before the loop is started


    }
    
	private enum State {
		WALK_BANK,
		BANK,
		WALK_DOOR,
		PICK,
	};

private static final Area BANK_AREA = new Area(3092, 3245, 3095, 3241);//bank area
private static final int[] DOOR_ID = { 7122 };//door id closed
private static final int[] CUPBOARDC_ID = { 2612 };//cupboard id closed
private static final int[] CUPBOARDO_ID = { 2613 };//cupboard id open
private static final int[] STAIRSD_ID = { 15648 };//stair id going down
private static final int[] STAIRSU_ID = { 15645 };//Stair id going up
//path from bank to door
Position[] pathA = {
new Position(3092, 3245, 0), 
new Position(3100, 3254, 0), 
new Position(3104, 3260, 0), 
new Position(3104, 3267, 0), 
new Position(3098, 3271, 0)
};
//path from door to stair case
Position[] pathB = {
 new Position(3098, 3270, 0), 
 new Position(3098, 3266, 0)
};
//path from stair case to cupboard
Position[] pathC= {
  new Position(3102, 3266, 1),
  new Position(3096, 3270, 1) 
};
//path 
Position[] pathG = {
new Position(3245, 3092, 0), 
new Position(3254, 3100, 0), 
new Position(3260, 3104, 0), 
new Position(3267, 3104, 0), 
new Position(3271, 3098, 0)
};
//path door from stair case
Position[] pathF = {
 new Position(3270, 3098, 0), 
 new Position(3266, 3098, 0)
};
//path  stair case from cupboard
Position[] pathE= {
  new Position( 3266, 3102, 1),
  new Position(3270, 3096, 1) 
};
    @Override
    public void onExit() {
        //Code here will execute after the script ends


    }


    @Override
    public int onLoop() {
	 case WALK_DOOR:
			localWalker.walkPath(pathA);
            sleep(random(1500, 3500));
            break;
            Entity Door = objects.closest(DOOR_ID);
			if (Door != null) {
				Door.interact("Open");
			}
            break;
            localWalker.walkPath(pathB);
            sleep(random(1500, 3500));
            break;
            Entity Stair = objects.closest(STAIRSU_ID);
			if (Stair != null) {
				Stair.interact("Climb-up");
			}
            localWalker.walkPath(pathC);
            sleep(random(1500, 3500));
            break;
	case PICK:
           Entity Garlic = objects.closest(CUPBOARDC_ID);
			if (Garlic != null) {
				Door.interact("Open");
			}
			Entity Garlic = objects.closest(CUPBOARDC_ID);
			if (Garlic != null) {
				Door.interact("Pick");
			}
		case WALK_BANK:
		localWalker.walkPath(pathE);
            sleep(random(1500, 3500));
            break;
            Entity Door = objects.closest(DOOR_ID);
			if (Door != null) {
				Door.interact("Open");
			}
            break;
          localWalker.walkPath(pathF);
            sleep(random(1500, 3500));
            break;
            Entity Stair = objects.closest(STAIRSU_ID);
			if (Stair != null) {
				Stair.interact("Climb-up");
			}
            localWalker.walkPath(pathG);
            sleep(random(1500, 3500));
            break;
			
    }
         return 100; //The amount of time in milliseconds before the loop starts over
    }


    @Override
    public void onPaint(Graphics2D g) {
        //This is where you will put your code for paint(s)




    }


} 
Link to comment
Share on other sites

it must compile with lots of errors - You need to switch through your statemachine (which you don't have) in order to get the case scenarios.

 

As was mentioned above, you can use the framework from my tutorial to get the hang of it.

 

Also, DON'T USE IDS! (and i'm not sure why you define them in array format either) - just use names

 

eg

 

cupboard.hasAction("Open"); will return true if the cupboard has the 'open' action (i.e if it's closed).

 

Also, format your code. If you're using eclipse, the formatting shortcut is ctrl+shift + f. If you're using another IDE, then i'm not sure what it is xD

Just makes it easier to read

 

apa

Link to comment
Share on other sites

it must compile with lots of errors - You need to switch through your statemachine (which you don't have) in order to get the case scenarios.

 

As was mentioned above, you can use the framework from my tutorial to get the hang of it.

 

Also, DON'T USE IDS! (and i'm not sure why you define them in array format either) - just use names

 

eg

 

cupboard.hasAction("Open"); will return true if the cupboard has the 'open' action (i.e if it's closed).

 

Also, format your code. If you're using eclipse, the formatting shortcut is ctrl+shift + f. If you're using another IDE, then i'm not sure what it is xD

Just makes it easier to read

 

apa

Thanks for the help using your guide i made a working script that picks and drops garlic, do you have any more tutorials for banking and walking :D

Link to comment
Share on other sites

posting again because I am having much the same error, where the code will populate in the local lis but not execute. So i'm assuming it's a faulty logic thing? But I can't see where or how, though it is pretty late and i'm Suuuuuper tired. Again, any and all criticism, comments, and help on either the error, or my methods is welcomed and appreciated!

 

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.GroundItem;
//import org.osbot.rs07.api.EntityAPI;
//import org.osbot.rs07.api.ui.Message;
//import org.osbot.rs07.api.ui.Message.MessageType;
import org.osbot.rs07.api.map.Area;

import java.awt.*;
import java.util.concurrent.TimeUnit;
 
@ScriptManifest(
		author = "Abhorrent", 
		info = "Hunter", 
		name = "Upgraded Hunter", 
		version = 1.1,
		logo = "")

public class main extends Script {
	
	String status = "Nothing";
	long startTime = System.currentTimeMillis();
	long timeElapsed = 0;
	int trapsUp = 1;
	Position [] spots = {
			new Position(2540,2882,0),
			new Position(2538,2882,0),
			new Position(2539,2884,0),
			new Position(2537,2884,0),
			new Position(2536,2882,0),
	};
	Position myP = myPlayer().getPosition();
	Position spot = new Position(0,0,0);
	Area[] traps = {
			new Area(2540, 2882, 2540, 2882),
			new Area(2538, 2882, 2538, 2882),
			new Area(2539, 2884, 2539, 2884),
			new Area(2537, 2884, 2537, 2884),
			new Area(2536, 2882, 2536, 2882),
	};
	int huntlvl = skills.getStatic(Skill.HUNTER);
	int numTraps = huntlvl/20 + 1;
    @Override
    public void onStart() {
        log("=======================");
        log("= Starting Hunter Bot =");
        log("=======================");
        getBot().addMessageListener(this);
    }
    
    private enum State {
    	HUNTING, WAITING;
	};
    	
	private State getState() {

		Entity trapDown = objects.closest(9344);
		Entity trapBird = objects.closest(9348);
		
		if (trapsUp < numTraps || trapDown != null || trapBird != null)
		{
			status = "Hunting";
			return State.HUNTING;
		}
		else
		{
			status = "Waiting";
			return State.WAITING;
		}
	}
	
	/*
	public void onMessage(Message message) {
		if (message.getType() == MessageType.GAME) {
			try {
				if (message.getMessage().contains("You can't")) {
					if(spot == spots[1]){
						spot = spots[2];
					}
					if (spot == spots[2]){
						spot = spots[1];
					}
					
				} else {
					// Do nothing
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	*/
	
	@Override
    public int onLoop() throws InterruptedException {
		switch (getState()) {
		case HUNTING: 
			myP = myPlayer().getPosition();
			Entity trapSet = objects.closest(9345);
			Entity trapDown = objects.closest(9344);
			Entity trapBird = objects.closest(9348);
			
			int x = 1;
			trapsUp = 0;
			for (x = 1; x < 5; x++)
			{
				if (traps[x].contains(trapSet) || traps[x].contains(trapDown) || traps[x].contains(trapBird))
				{
					trapsUp++;
				}
			}
			
			int y = 1;
			
			for (y=1;y<numTraps;y++)
			{
				if (trapsUp < numTraps && !myPlayer().isAnimating())
				{
					if (myP.equals(spots[y]))
					{
						inventory.interact("Lay","Bird Snare");
						sleep(random(4500,5250));
						break;
					}
					if (!myP.equals(spots[y]))
					{
						spots[y].interact(bot,"Walk here");
						sleep(random(435,550));
						break;
					}
				}
				if (trapDown != null && trapDown.isVisible() && !myPlayer().isAnimating())
				{
					trapDown.interact("Dismantle");
					sleep(random(500,800));
					break;
				}
				if (trapBird != null && trapBird.isVisible() && !myPlayer().isAnimating())
				{
					trapBird.interact("Check");
					sleep(random(600,890));
					break;
				}
				else
				{
				}	
			}
			
		case WAITING:
			GroundItem trap = groundItems.closest(10006);
			if (trap != null)
			{
				trap.interact("Take");
				break;
			}
			if (inventory.contains("Bones"))
			{
				inventory.interact("Drop","Bones");
				break;
			}
			if (inventory.contains("Raw bird meat"))
			{
				inventory.interact("Drop","Raw bird meat");
				break;
			}
			sleep(random(675,1100));
			break;
		}
		return random(700,800);
	}
	
    @Override
    public void onExit() {
        log("YoloSwagAFk");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
		long currentTime = System.currentTimeMillis();
		timeElapsed = currentTime - startTime;
		long hours = TimeUnit.MILLISECONDS.toHours(timeElapsed);
		timeElapsed -= TimeUnit.HOURS.toMillis(hours);
		long minutes = TimeUnit.MILLISECONDS.toMinutes(timeElapsed);
		timeElapsed -= TimeUnit.MINUTES.toMillis(minutes);
		long seconds = TimeUnit.MILLISECONDS.toSeconds(timeElapsed);
    	g.drawString("Status: " + status, 200, 314);
    	g.drawString("Run Time: " + hours + ":" + minutes + ":" + seconds, 200, 300);
    	g.drawString("Hunter Lvl: " + skills.getStatic(Skill.HUNTER), 200, 342);
    	g.drawString("Number of traps you can set: " + numTraps, 200, 286);
    	g.drawString("Traps set up : " + trapsUp, 200, 272);
    	g.drawString("My position : " + myP, 200, 328);
    	g.drawString("The spot is: " + spot, 200, 356);
    }
 
}

 

 

Falling asleep as I type, thanks in advance for any help and advice

Link to comment
Share on other sites

posting again because I am having much the same error, where the code will populate in the local lis but not execute. So i'm assuming it's a faulty logic thing? But I can't see where or how, though it is pretty late and i'm Suuuuuper tired. Again, any and all criticism, comments, and help on either the error, or my methods is welcomed and appreciated!

 

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.GroundItem;
//import org.osbot.rs07.api.EntityAPI;
//import org.osbot.rs07.api.ui.Message;
//import org.osbot.rs07.api.ui.Message.MessageType;
import org.osbot.rs07.api.map.Area;

import java.awt.*;
import java.util.concurrent.TimeUnit;
 
@ScriptManifest(
		author = "Abhorrent", 
		info = "Hunter", 
		name = "Upgraded Hunter", 
		version = 1.1,
		logo = "")

public class main extends Script {
	
	String status = "Nothing";
	long startTime = System.currentTimeMillis();
	long timeElapsed = 0;
	int trapsUp = 1;
	Position [] spots = {
			new Position(2540,2882,0),
			new Position(2538,2882,0),
			new Position(2539,2884,0),
			new Position(2537,2884,0),
			new Position(2536,2882,0),
	};
	Position myP = myPlayer().getPosition();
	Position spot = new Position(0,0,0);
	Area[] traps = {
			new Area(2540, 2882, 2540, 2882),
			new Area(2538, 2882, 2538, 2882),
			new Area(2539, 2884, 2539, 2884),
			new Area(2537, 2884, 2537, 2884),
			new Area(2536, 2882, 2536, 2882),
	};
	int huntlvl = skills.getStatic(Skill.HUNTER);
	int numTraps = huntlvl/20 + 1;
    @Override
    public void onStart() {
        log("=======================");
        log("= Starting Hunter Bot =");
        log("=======================");
        getBot().addMessageListener(this);
    }
    
    private enum State {
    	HUNTING, WAITING;
	};
    	
	private State getState() {

		Entity trapDown = objects.closest(9344);
		Entity trapBird = objects.closest(9348);
		
		if (trapsUp < numTraps || trapDown != null || trapBird != null)
		{
			status = "Hunting";
			return State.HUNTING;
		}
		else
		{
			status = "Waiting";
			return State.WAITING;
		}
	}
	
	/*
	public void onMessage(Message message) {
		if (message.getType() == MessageType.GAME) {
			try {
				if (message.getMessage().contains("You can't")) {
					if(spot == spots[1]){
						spot = spots[2];
					}
					if (spot == spots[2]){
						spot = spots[1];
					}
					
				} else {
					// Do nothing
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	*/
	
	@Override
    public int onLoop() throws InterruptedException {
		switch (getState()) {
		case HUNTING: 
			myP = myPlayer().getPosition();
			Entity trapSet = objects.closest(9345);
			Entity trapDown = objects.closest(9344);
			Entity trapBird = objects.closest(9348);
			
			int x = 1;
			trapsUp = 0;
			for (x = 1; x < 5; x++)
			{
				if (traps[x].contains(trapSet) || traps[x].contains(trapDown) || traps[x].contains(trapBird))
				{
					trapsUp++;
				}
			}
			
			int y = 1;
			
			for (y=1;y<numTraps;y++)
			{
				if (trapsUp < numTraps && !myPlayer().isAnimating())
				{
					if (myP.equals(spots[y]))
					{
						inventory.interact("Lay","Bird Snare");
						sleep(random(4500,5250));
						break;
					}
					if (!myP.equals(spots[y]))
					{
						spots[y].interact(bot,"Walk here");
						sleep(random(435,550));
						break;
					}
				}
				if (trapDown != null && trapDown.isVisible() && !myPlayer().isAnimating())
				{
					trapDown.interact("Dismantle");
					sleep(random(500,800));
					break;
				}
				if (trapBird != null && trapBird.isVisible() && !myPlayer().isAnimating())
				{
					trapBird.interact("Check");
					sleep(random(600,890));
					break;
				}
				else
				{
				}	
			}
			
		case WAITING:
			GroundItem trap = groundItems.closest(10006);
			if (trap != null)
			{
				trap.interact("Take");
				break;
			}
			if (inventory.contains("Bones"))
			{
				inventory.interact("Drop","Bones");
				break;
			}
			if (inventory.contains("Raw bird meat"))
			{
				inventory.interact("Drop","Raw bird meat");
				break;
			}
			sleep(random(675,1100));
			break;
		}
		return random(700,800);
	}
	
    @Override
    public void onExit() {
        log("YoloSwagAFk");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
		long currentTime = System.currentTimeMillis();
		timeElapsed = currentTime - startTime;
		long hours = TimeUnit.MILLISECONDS.toHours(timeElapsed);
		timeElapsed -= TimeUnit.HOURS.toMillis(hours);
		long minutes = TimeUnit.MILLISECONDS.toMinutes(timeElapsed);
		timeElapsed -= TimeUnit.MINUTES.toMillis(minutes);
		long seconds = TimeUnit.MILLISECONDS.toSeconds(timeElapsed);
    	g.drawString("Status: " + status, 200, 314);
    	g.drawString("Run Time: " + hours + ":" + minutes + ":" + seconds, 200, 300);
    	g.drawString("Hunter Lvl: " + skills.getStatic(Skill.HUNTER), 200, 342);
    	g.drawString("Number of traps you can set: " + numTraps, 200, 286);
    	g.drawString("Traps set up : " + trapsUp, 200, 272);
    	g.drawString("My position : " + myP, 200, 328);
    	g.drawString("The spot is: " + spot, 200, 356);
    }
 
}

 

 

Falling asleep as I type, thanks in advance for any help and advice

Tbh, your code is really ugly to read; why do you have your "{" on a separate line?

 

You shouldn't break after every action, it looks like you don't understand what break means in java. And yea, your logic still fails. Try a different approach on how to check for traps. Remember that someone else might set up a trap nearby you, and your script will think it's your characters trap.

 

Find an empty position -> set up trap -> if trap is up -> save this position in a list as positions with trap -> loop through your list with positions and see if any position has an object on it, matching trap down.

 

This was just an example. It's up to you how you want to do it.

Link to comment
Share on other sites

Tbh, your code is really ugly to read; why do you have your "{" on a separate line?

 

You shouldn't break after every action, it looks like you don't understand what break means in java. And yea, your logic still fails. Try a different approach on how to check for traps. Remember that someone else might set up a trap nearby you, and your script will think it's your characters trap.

 

Find an empty position -> set up trap -> if trap is up -> save this position in a list as positions with trap -> loop through your list with positions and see if any position has an object on it, matching trap down.

 

This was just an example. It's up to you how you want to do it.

mmkk i will try that. as for break. wouldn't it break out of just the loop that it's in? 

so in hunter it won't move to a new location before it places the trap, and in wait it would only drop while there is nothing to do in hunter?

though i'm sure that's wrong as it's not running... lol

 

and i'll just have to get used to  { in line ha, you're right it's definitely cleaner that way.

 

Edited by abhorrent
Link to comment
Share on other sites

mmkk i will try that. as for break. wouldn't it break out of just the loop that it's in? 

so in hunter it won't move to a new location before it places the trap, and in wait it would only drop while there is nothing to do in hunter?

though i'm sure that's wrong as it's not running... lol

 

and i'll just have to get used to  { in line ha, you're right it's definitely cleaner that way.

yes, it will break out of the loop. But you are using it wrong, you shouldn't break after every action.

 

Just break and the end of your case.

  • Like 1
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...