Jump to content

FROG KILLER


Imthabawse

Recommended Posts

Title says it all. Grab you're gear and select between 3 foods: Tuna, Lobsters, or Swordfish. Still working on banking method. Just messing around on pure account trying out random scripts. The scripts cluttered with IF's but for me and my low level of script knowledge it's easier to understand and also works. With that being said always looking for feedback, love the community discussion and how everyone's getting more involved and curious about scripting like myself. Thanks for the read. 

 

CODE: *Edited (Added banking support) looking into teleing to lumby then banking instead of walking if required level to tele and have runes

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(name = "Frogkiller", logo = "", version = 1, author = "Imthabawse", info = "Slaughters frogs for gains!")

public class Frogkiller extends Script {

    private void killFrog() {
        if (!myPlayer().isAnimating()) {
            if (!myPlayer().isUnderAttack()) {
                NPC giantfrog = getNpcs().closest("Giant frog", "Big frog");
                if (giantfrog != null) {
                    if (giantfrog.getHealthPercent() > 10) {
                        giantfrog.interact("Attack");
                        log("Slaughter time!");
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() {
                                return myPlayer().isUnderAttack();
                            }
                        }.sleep();
                    }
                }
            }
        }
    }


    private void eatFood() {
        if (myPlayer().getHealthPercent() < 48) {
            if(getInventory().contains("Tuna")) {
                log("Damn frogs fked me up.. let's eat!");
                getInventory().interact("Eat", "Tuna", "Lobster", "Swordfish");
            }
            }
    }

    private void bank() throws InterruptedException {
        if(getInventory().isEmptyExcept("Air rune","Earth rune")) {
            log("Inventory contains no food, banking.");
            getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
            getBank().open();
            bank.withdrawAll("Tuna");
            new ConditionalSleep(2500) {
                @Override
                public boolean condition() {
                    return getInventory().isFull();
                }
            }.sleep();
        }
    }



   private Area killArea = new Area(3186, 3187, 3209, 3160);

    @Override
    public void onStart() {
        log("Let's kill some frogs!");
    }

    @Override
    public int onLoop() throws InterruptedException {
        if(!killArea.contains(myPlayer())) {
            log("Not in kill area.. lets get there and slaughter more frogs!");
            getWalking().webWalk(killArea);
        }else {
            if (killArea.contains(myPlayer())) {
                killFrog();
                eatFood();
                bank();
            }
        }
        return 1200;
    }
}

 

Edited by Imthabawse
Link to comment
Share on other sites

Sorry for some grammar "features" 

Just a few fast suggestions :):

 

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import java.util.Arrays;

@ScriptManifest(name = "Frogkiller", logo = "", version = 1, author = "Imthabawse", info = "Slaughters frogs for gains!")

public class FrogKiller extends Script { //Change to FrogKiller

    private String[] frogName = { "Giant frog", "Big frog" };

    //words "Tuna", "Lobster", "Swordfish" were used in 2 different places/lines - it's better to make a variable for them to avoid duplicitions in code
    //a lot of duplicitions will make it harder to make changes in the code or to fix bugs in bigger projects
    private String[] foodNames = { "Tuna", "Lobster", "Swordfish" };


    private void killFrog()
    {
        if (!myPlayer().isAnimating() && !myPlayer().isMoving() && !myPlayer().isUnderAttack())
        {
            NPC giantFrog = getNpcs().closest(npc -> Arrays.asList(frogName).contains(npc.getName()) && !npc.isHitBarVisible() && !npc.isUnderAttack());
            //No need to check again for "if (!myPlayer().isAnimating() && !myPlayer().isMoving() && !myPlayer().isUnderAttack())", you can remove those 3 conditions after finding frog
            if (giantFrog != null)
            {
                log("Condition met.. found targets!"); //targets are found ONLY if giantFrog is not NULL, not before

                if (giantFrog.interact("Attack")) //check IF giant frog was Attacked succesfully, and then use ConditionalSleep
                {
                    log("Slaughter time!");
                    new ConditionalSleep(5000, 1000)
                    {
                        @Override
                        public boolean condition()
                        {
                            return !myPlayer().isUnderAttack() && !myPlayer().isMoving() && !myPlayer().isAnimating();
                        }
                    }.sleep();
                }
            }
        }
    }

    private void bank() {

    }

    private void eatFood() {
        if(myPlayer().getHealthPercent() < 44)
        {
            log("Damn frogs fked me up.. let's eat!");
            if (getInventory().contains(foodNames)) //this is uselles call without a condition (IF condition in this case).
            {
                if (getInventory().interact("Eat", foodNames))
                {
                    //you could put a ConditionalSleep here, maybe attack frog again after eating or something like that
                }
            }
            else //else in this case means inventory does not contain food
            {
                log("No food stopping script..");
                stop();
            }
        }
    }

    private Area killArea = new Area(3187, 3183, 3213, 3157);

    @Override
    public void onStart() {
        log("Let's kill some frogs!");
    }

    @Override
    public int onLoop() {
        if(!killArea.contains(myPlayer())) {
            log("Not in kill area.. lets get there and slaughter more frogs!");
            getWalking().webWalk(killArea);
        }else {
            if (killArea.contains(myPlayer())) {
                killFrog();
                eatFood();
            }
        }
        return 1200;
    }
}

In Java, you should use following Naming Conventions:

  • for Class name you should use "FrogKiller", with capital "K" (change file name to "FrogKiller" as well if you want to use/compile it)
  • same goes for variable names, e.g. you should use "giantFrog", instead of "giantfrog"

First 3 "if" conditions in your "killFrog()" method can be combined to following one line:

if (!myPlayer().isAnimating() && !myPlayer().isMoving() && !myPlayer().isUnderAttack())

&& operator in a Java condition (and a lot other programming languages) means AND

You could use || operator as well, which means OR. However, probably you don't need it yet in your script.

Line below is an example of getting a NPC with more conditions in a single call.

NPC giantFrog = getNpcs().closest(npc -> Arrays.asList(frogName).contains(npc.getName()) && !npc.isHitBarVisible());

^^ could contain a lot more conditions that you might want to use for whatever reason, e.g. 

npc.isUnderAttack() && npc.hasAction("Attack") && //some other conditions

I will not go into depth with following condition, however, shortly it means that it will return only NPC with name that is in "frogName" array. 

Arrays.asList(frogName).contains(npc.getName())

One last thing - you might noticed that I'm putting "{" in new lines. That's the way I'm usually using those "Special brackets" (No idea what's their name) while programming, because in my opinion code is then easier to read. However, standards accept both ways - "{" in new line, or same as you did - in the end of the line before. Hopefully this paragraph make sense lol.

I didn't try code in the top of my reply, but is should work. However looks good, for a first working script, keep up good work.

Edited by Xx pk xX
  • Like 1
Link to comment
Share on other sites

Update: Added a banking method and added into onLoop. Only works for Tuna for now till I play around with it. Also the Air rune and Earth rune are only there cause I was testing and had in my inv.

private void bank() throws InterruptedException {
        if(getInventory().isEmptyExcept("Air rune","Earth rune")) {
            log("Inventory contains no food, banking.");
            getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
            getBank().open();
            bank.withdrawAll("Tuna");
        }
    }

onLoop 

@Override
    public int onLoop() throws InterruptedException {
        if(!killArea.contains(myPlayer())) {
            log("Not in kill area.. lets get there and slaughter more frogs!");
            getWalking().webWalk(killArea);
        }else {
            if (killArea.contains(myPlayer())) {
                killFrog();
                eatFood();
                bank();
            }
        }
        return 1200;
    }
}

Needs improvement and will mess around with it over time but gets the job done and gets some good levels for F2P pure accounts. 

Edited by Imthabawse
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...