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.

Combat script overflowing

Featured Replies

Not sure what is happening here. My RAM is filling up and processor usage is skyrocketing. What is going wrong here?

public class Combat extends Script {
	
	private Player me; 
	private boolean changeToAttack = true;
	private boolean changeToDefence = true;
	
	private enum State {
		ATTACK, EAT
	}
	
	private State getState() {
		if (getSkills().getDynamic(Skill.HITPOINTS) < 4) {
			return State.EAT;
		} else if (!getCombat().isFighting()) {
			return State.ATTACK;
		} else {
			return null;
		}
	}
	
	@Override
    public void onStart() {
    	log("Welcome!");
    	me = getPlayers().myPlayer();
    }

    @Override
    public void onExit() {
        
    }
    
	@Override
	public int onLoop() throws InterruptedException {
		
		switch(getState()) {
		case ATTACK:
			Attack();
			break;
		case EAT:
			Eat();
			break;
		default:
			break;
		}
		return 225;
	}
	
	
	
	private void Eat() {
		// TODO Auto-generated method stub
		
	}

	private void Attack() {
		
		/*
		if (changeToAttack) {
			if (getSkills().getStatic(Skill.STRENGTH) > 9) {
				if (getWidgets().interact(548, 48, null)) {
					if (getWidgets().interact(593, 3, null)) {
						changeToAttack = false;
					}
				}
			} 
		}
		
		if (changeToDefence) {
			if (getSkills().getStatic(Skill.STRENGTH) > 9 && getSkills().getStatic(Skill.ATTACK) > 9) {
				if (getWidgets().interact(548, 48, null)) {
					if (getWidgets().interact(593, 15, null)) {
						changeToDefence = false;
					}
				}
			} 
		}
		*/
		
		@SuppressWarnings("unchecked")
		NPC monster = getNpcs().closest(new Filter<NPC>() {
			@Override
			public boolean match(NPC npc) {
				 return npc != null && npc.getName().equals("Chicken") && npc.exists()
	                        && getMap().canReach(npc) && npc.getHealthPercent() > 0 && npc.getInteracting() == null;
			}
		});
		
		if (monster.isVisible()) {
			if (monster.hasAction("Attack")) {
				if (monster.interact("Attack")) {
					try {
						Thread.sleep(3000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	@Override
	public void onPaint(Graphics2D g) {
		
		/*
		List<Position> areaList = choppingArea.getPositions();

		g.setColor(Color.GREEN);
		for (int i = 0; i < areaList.size(); i++) {
			g.draw(areaList.get(i).getPolygon(getBot()));
		}
		*/

	}
}

 

1 hour ago, TrekToop11 said:

Check your getState()

Wouldn't that be a Nullpointerexception?

Instead of returning null in your getState() which is what's causing the problem, return a state in which you do nothing.

For future problems check the osbot logger when you're having issues, it'll tell you where exactly in your code there is an NPE, etc.

Create an account or sign in to comment

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.