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.

First Script Help

Featured Replies

I don't feel like I'm learning much by just remaking the same fisher/miner/woodcutter as the tutorials, so I like to try and make something that's a bit more demanding. With that being said, this is my failed attempt at an auto fighter for some cows...Script just stands there no matter what changes I've made (posted source is after 3-4 revisions/attempts). And I didn't originally use ID's for anyone that's going to post about it. 

public class main extends Script {

	private static final int[] COW_ID = { 2808, 
		2806, 2805 };	
	
	private enum State {
		IN_COMBAT, ATTACKING, IDLE
	};
	
	private State getState() {
		if(myPlayer().isAnimating())
			return State.IN_COMBAT;
		if(myPlayer().isMoving())
			return State.ATTACKING;
		return State.IDLE;
	}
	
	@Override
	public void onStart() {
		log("Let's get started!");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
			case ATTACKING:
				if(!myPlayer().isUnderAttack()){
				NPC cow = npcs.closest(COW_ID);
				if (cow.isAttackable()) {
					cow.interact("Attack-Cow");
				}
			}	
				break;
			case IN_COMBAT:
				sleep(random(300, 400));
				break;	
			case IDLE:
				sleep(random(50, 200));
				break;
		}
		return random(200, 300);
	}
	
	@Override
	public void onExit() {
		log("Thanks for running my cow killer!");
	}
}

Thanks in advanced. 

Edited by poptartjake

Read the getState method, look at when State.ATTACKING is actually set: When the player is moving. So whenever the player is moving, it will attack, if its not moving, it will be idle. 

        if(myPlayer().isUnderAttack()) {
            return State.IN_COMBAT;
        } else {
            return State.ATTACKING;
        }

That is just an example, you can find a suitable way of setting the state to attack biggrin.png

 

EDIT: 

 

"Attack" << Correct 

"Attack-Cow" << Incorrect

Edited by Czar

  • Author

Read the getState method, look at when State.ATTACKING is actually set: When the player is moving. So whenever the player is moving, it will attack, if its not moving, it will be idle. 

        if(myPlayer().isUnderAttack()) {
            return State.IN_COMBAT;
        } else {
            return State.ATTACKING;
        }

That is just an example, you can find a suitable way of setting the state to attack biggrin.png

 

EDIT: 

 

"Attack" << Correct 

"Attack-Cow" << Incorrect

 

Much appreciation. I've made the changes suggested and I'm now successfully murdering them naughty naughty cows. :)  Was just worried that my logic was completely off and that combat was going to be handled differently. 

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.