Jump to content

return isnt working properly??


hellcatz

Recommended Posts

hello everyone

 

im trying to write my first script basicly a sandcrab training script.

now is my problem this:

NPC SC = npcs.closest("Sand Crab");
    RS2Object BC = getObjects().closest("Bank chest");
    Position MP = myPosition();


    if (!CT.contains(MP) && getInventory().contains("Salmon")) {
        log("Combat Area is empty walking to there now");
        getWalking().webWalk(CT);
    } else if (myPlayer().getHealthPercent() < 35) {
        log("Health below 35% eating Salmon");
        getInventory().interact("Eat", "Salmon");
    } else if (CT.contains(SC) && SC != null && !myPlayer().isAnimating()) {
        log("Attacking Sand Crab");
        SC.interact("Attack");
        sleep(50);
    } else if (!myPlayer().isAnimating() && SC == null) {
        log("resetting Agro");
        getWalking().webWalk(RSA);
    } else if (!getInventory().contains("Salmon")) {
        log("No food found in inventory checking bank");
        getWalking().webWalk(BT);
        if (BT.contains(MP)) {
            BC.interact("Use");
            sleep(2000);
        }
        if (getBank().contains("Salmon")) {
            getBank().withdrawAll("Salmon");
        } else if (!getBank().contains("Salmon")) {
            log("No food to be found please restock");
            stop();
        }
    }

    return random(3000, 60000);
}

it takes ages to get the log the attack even so long that it will log me out it

also wont move to RSA when he supposed to (if we dont have agro or !myPlayer().isAnimating())

 

this is all in onLoop()

 

am i missing something or ....

 

this is what comes from the logger

[INFO][Bot #1][09/14 09:37:23 PM]: Attacking Sand Crab
[INFO][Bot #1][09/14 09:41:16 PM]: Attacking Sand Crab

 

clearly its more then 1 minute

 

thanks in advance:D

 

Edited by lucune
Logger log
  • Sad 1
Link to comment
Share on other sites

  • hellcatz changed the title to return isnt working properly??

So, a few problems. I'll go in order of least important to most important:

(1) Your code is prone to null pointer exceptions:

CT.contains(SC) && SC != null

Switch this to check if the object is null first. You should do this for all of your code. 

(2)

      (a) The sand crab is quite possibly also not in range. If you're not currently fighting the sand crab, somebody else probably is. How far away are the sand crabs you're trying to interact with? My guess is that they're reasonably far, or not easily visible.

       (b) Similarly, Sand crabs aren't actually NPCs until you turn them agro by standing beside them. You'll only attack a sand crab if it's already up and around.

(3) You sleep for up to an entire minute in between even checking the actions, totally tossing aside actually doing them.

return random(3000, 60000);

Make this wayyyy less. There are very few scenarios where it would actually make sense to have a gap this big, and this is not one of them.

(4) Please look into a state-based system. There are quite a few tutorials on it in the tutorials section. It'll make the code a lot easier to follow when you/others debug. Similarly, revise your variable names if you want others to be able to read your code. I don't know what CT, RSA, or BT are. 

 

Side note: This should reset agro anytime there isn't an active sand crab around you, given you have >= 35% HP, and have Salmon/are in some area CT. 

Edited by Team Cape
  • Like 1
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...