Jump to content
Sign in to follow this  
Athylus

Combat script overflowing

Recommended Posts

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()));
		}
		*/

	}
}

 

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...