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.

Help with beginner script

Featured Replies

Hey, I'm just getting into scripting having some java and other various programming background.

 

From following the tutorials I've come up with a bit of a base for a simple cow fighter which I want to build off of, and I have what I think will give me a script which will attack cows, but whenever I run it nothing happens.

Here's my onLoop() code.  my onStart() code sets the current state to initialState.  Any idea what I'm doing wrong?

Also I might just be blind, but if anybody could link me to a good debugging tutorial I'd be very appreciative!

 

public int onLoop() throws InterruptedException {
        objects.closest("Cow").interact("Attack");
        switch (getCurrentState()){ //state transitions

            case initialState:
                setState(states.lookingForFight);
                break;
            case inCombat:
                if(!myPlayer().isUnderAttack()){
                    setState(states.lookingForFight);
                }
                break;
            case lookingForFight:
                if(myPlayer().isUnderAttack()){
                    setState(states.inCombat);
                }
                break;
            case lowHealth:
                setState(states.eating);
                break;
            case eating:
                if (!needToEat()){
                    if (myPlayer().isUnderAttack()){
                        setState(states.inCombat);
                    } else{
                        setState(states.lookingForFight);
                    }
                }
                break;
            case waiting:
                break;
            case finish:
                break;
            case bank:
                break;
            default:
                break;
        }
        switch (getCurrentState()){ //state actions
            case initialState:
                break;
            case inCombat:
                break;
            case lookingForFight:
                log("attempting to attack");
                Entity cow = objects.closest("Cow");
                if(cow != null ){
                    cow.interact("Attack");
                }
                break;
            case lowHealth:
                break;
            case eating:
                getInventory().interact("Trout", "Eat");
                break;
            case waiting:
                break;
            case finish:
                break;
            default:
                break;
        }
        return random(400, 1200);
    }

 

Cows aren't objects...theyre npcs. I'd suggest reading the api docs a bit.

 

https://osbot.org/api/

 

Specifically introduce yourself to the different classes that implement Entity.

Use the api the way its meant to be, methods return boolean for a reason..use it to control your script logic.

 

objects = doors, gates, trees, fires, etc

npcs = uhh...npcs

groundItems = lootable items 

item = bank/equipment/inventory items

 

It seems unnecessary that you're switching getCurrentState() twice per loop. If you want to save which state you're currently executing, try something like this:

// global variables:
State currentState = State.INITIAL_STATE; // or whatever your 'initial' or 'unknown' state is
// in your onloop:
switch(currentState = getCurrentState()) {
  case BANK:
    getBank().depositAll();
    ...
    break;
  case ...:
    ...
    break;
  ...
}

 

5 hours ago, Alek said:

 

 

Time to fuck both of your lives:


 


XTile[][] plane = map.getRegion().getTiles()[myPosition().getZ()];
        for (int x = 0; x < plane.length; ++x)
            for (int y = 0; y < plane[x].length; ++y)
                for (XInteractableObject obj : plane[x][y].getObjects()) {
                    if (obj != null) {
                        InteractableObject obj2 = Wrapper.wrap(obj);
                        if(obj2.isNPC() || obj2.isPlayer())
                        System.out.println(obj2.getName() + ", " + obj2.isNPC() + ", " +obj2.isPlayer());
                    }

                }

 

InteractableObjects are part of the getAll() list from Objects, however they are put in a list of RS2Object which object slices them. It's one of the gray areas for me in OSBot, you'd have to ask Zach or MGI who know a lot more about the game than I do. 

Nice to see you are spending your time making algorithms to fuck with people rather than working on re-sizeable mode <3

Edited by Tom

9 hours ago, Polymorphism said:

Cows aren't objects...theyre npcs. I'd suggest reading the api docs a bit.

 

https://osbot.org/api/

 

Specifically introduce yourself to the different classes that implement Entity.

Use the api the way its meant to be, methods return boolean for a reason..use it to control your script logic.

 

objects = doors, gates, trees, fires, etc

npcs = uhh...npcs

groundItems = lootable items 

item = bank/equipment/inventory items

 

I'm just here to say that 

 

NPC = Non-Player Charcter

 

Any character that's not controlled by an actual person in real time is an NPC.

 

so like a cow.

 

or Bob of Bob's Axes in lumbridge.

 

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.