Jump to content

why the error


mousbros

Recommended Posts

the title says it all, it does it job, sometimes tho

 

 

[ERROR][Bot #1][03/06 07:09:07 AM]: Error in script executor!
java.lang.NullPointerException
    at begin.Begin.onLoop(Begin.java:84)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(nj:193)
    at java.lang.Thread.run(Unknown Source)

 

 

 

 

```

package begin;

import org.osbot.rs07.api.filter.AreaFilter;
import org.osbot.rs07.api.filter.NameFilter;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Mousbros", info = "", logo = "", name = "EZBEGIN", version = 0) 

public class Begin extends Script {

    
    final Area GOBLIN_AREA = new Area (3250,3223,3264,3242);
    final Area COW_AREA = new Area (3239,3255,3265,3296);
    final Area START_AREA = new Area (3242,3228,3263,3250);
    final Area DIED_AREA = new Area (3217,3215,3226,3222);
    
    String status;
    String food="Salmon";
    String GroundItem ="Bones";
    
    public void onExit() {
            
    }
        
        public void onStart() {
            
            
        }    
        
        
        @Override
        public int onLoop() throws InterruptedException {
            
        
            
        status=getState();
        switch (status) {
        
        case "FIGHTING":
            
            if(!myPlayer().isAnimating() && !myPlayer().isUnderAttack() && !myPlayer().isMoving()) {
                NPC Goblin = npcs.closest("Goblin");
                if (Goblin != null && Goblin.isAttackable()
                && Goblin.getName().contains("Goblin")) {
                if (map.canReach(Goblin)) {
                log("Attacking that punk ass goblin!");
                Goblin.interact("Attack");
                }
                sleep(random(1435,2130));
                
            }
        }
        break;
        
        
        
        case "FIGHTING_COWS":
            
            if(!myPlayer().isAnimating() && !myPlayer().isUnderAttack() && !myPlayer().isMoving()) {
                NPC Cow = npcs.closest("Cow");
                if (Cow != null && Cow.isAttackable()
                && Cow.getName().contains("Cow")) {
                if (map.canReach(Cow)) {
                log("Attacking that punk ass Cow!");
                Cow.interact("Attack");
                }
                sleep(random(1435,2130));
                
            }
            if(Cow != null && Cow.getHealthPercent() == 0) {
                log("Cow we are tracking is dead");
            }else {
                log("LOOT -> chicken we are tracking is not dead?");
                 Cow = null;
                 }
            
            if(Cow.exists()) {
                sleep(random(256,2487));
            }
            Area corpse = Cow.getArea(1);
            if(getInventory().getAmount("Bones") >= 0) {
                GroundItem bones = groundItems.closest(new AreaFilter<GroundItem>(corpse), new NameFilter<GroundItem>("Bones"));
                if(bones !=null) {
                    log("Found Bones");
                    bones.interact("Take");
                    sleep(random(287,2869));
                    
                }
            }
            while (inventory.contains("Bones")) {
                log("Bury the Bones");
                inventory.interact("Bury", "Bones");
                sleep(random(369,2158));
                
            }
            
            
            }
            
        break;
        
        case "BANKING":
            if(!getBank().isOpen()) {
                    getBank().open();
            log("Try opening bank");
            }else{
                getBank().depositAll();
                
                }
        break;
        
        
                
        
        case "GOING_TO_BANK":
            getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
            break;
        case "GOING TO GOBLIN_AREA":
            getWalking().webWalk(GOBLIN_AREA);
            break;
        case "GOING_TO_COW_AREA":
            getWalking().webWalk(COW_AREA);
            break;
        
        }
        return random (2456,3450);
        
    
        }

        
            public String getState(){
                    if(START_AREA.contains(myPosition()) && !getInventory().isEmpty()&& myPlayer().getCombatLevel() == 3){
                        return "GOING_TO_BANK";
                    }else if (Banks.LUMBRIDGE_UPPER.contains(myPosition()) && !getInventory().isEmpty()) {
                        return "BANKING";
                    }else if (Banks.LUMBRIDGE_UPPER.contains(myPosition()) && getInventory().isEmpty()) {
                        return "GOING TO GOBLIN_AREA";
                    }else if(GOBLIN_AREA.contains(myPosition()) && myPlayer().getCombatLevel() < 10){
                        return "FIGHTING";
                    }else if(GOBLIN_AREA.contains(myPosition()) &&myPlayer().getCombatLevel() >= 10){
                        return "GOING_TO_COW_AREA";
                    }else if (COW_AREA.contains(myPosition()) && myPlayer().getCombatLevel() >= 10){
                        return "FIGHTING_COWS";
                    }else if(Banks.LUMBRIDGE_UPPER.contains(myPosition()) && !inventory.contains(food)){
                        return "BANKING";
                    }else if(GOBLIN_AREA.contains(myPosition()) && !inventory.contains(food) && myPlayer().getHealthPercent()<30){
                        return "GOING_TO_BANK";
                    
                    }else{return "GOING TO GOBLIN_AREA";}
                    
                
               }
            


        }

```

Link to comment
Share on other sites

27 minutes ago, Malcolm said:

            NPC Cow = npcs.closest("Cow");
            if (Cow != null && Cow.isAttackable() && Cow.getName().contains("Cow")) {
                if (map.canReach(Cow)) {
                    log("Attacking that punk ass Cow!");
                    Cow.interact("Attack");
                }
                sleep(random(1435, 2130));

            }
            if (Cow != null && Cow.getHealthPercent() == 0) {
                log("Cow we are tracking is dead");
            } else {
                log("LOOT -> chicken we are tracking is not dead?");
                Cow = null;
            }

            if (Cow.exists()) {
                sleep(random(256, 2487));
            }

As you can see by this, you're well outside of your nullchecks and I'm pretty sure you need to nullcheck the cow before checking .exists().

I should add that .exists() in this context is a fairly useless check.

However I'm going to do a bit of spoonfeeding and show you something because it hurts my brain to read this code.


        NPC cow = npcs.closest("Cow");
        if (cow != null && cow.isAttackable() && getMap().canReach(cow)) {
            if (cow.getHealthPercent() == 0) {
                log("Cow we are tracking is dead");
            } else if (!getCombat().isFighting()) {
                if (cow.interact("Attack")) {
                    log("Attacking that punk ass Cow!");
                    // CONDITIONAL SLEEP
                }
            }
        }

If you choose to track the cows health percentage (which you should because I'm pretty sure if you don't you can end up interacting with NPCs that have 0hp.

Of course what I did can be written much better but I kinda just winged it because what you had really hurt my brain :doge:

Shut up I'm like 10 days into coding

 

Much appreciated for your reply bro, I'm gonna investigate what you did differently and try to fix it

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...