Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Beginner coder (Al Kahrid killer) - how does my code look


    Trentnz

    Recommended Posts

    Wanting to start off with a simple Al Kahrid warrior killer 

     

    please let me know what you think of my code

     

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.wrappers.interactive.Character;
    import org.dreambot.api.wrappers.interactive.NPC;

    public class AlKahridWarriorKiller extends AbstractScript {

        private static final int AL_KAHRID_WARRIOR_ID = 2634;
        private static final int LOBSTER_ID = 379;
        private static final int RUNE_SCIMITAR_ID = 4587;

        @Override
        public void onStart() {
            if (!getInventory().contains(RUNE_SCIMITAR_ID)) {
                log("You do not have a rune scimitar in your inventory. Stopping script.");
                stop();
            }
        }

        @Override
        public int onLoop() {
            NPC alKahridWarrior = getNpcs().closest(AL_KAHRID_WARRIOR_ID);
            if (alKahridWarrior != null) {
                if (!alKahridWarrior.isInteractingWithLocalPlayer()) {
                    if (getInventory().contains(LOBSTER_ID)) {
                        getInventory().interact(LOBSTER_ID, "Eat");
                    }
                    if (getCombat().getHealthPercent() < 50) {
                        alKahridWarrior.interact("Attack");
                    }
                }
            } else {
                getWalking().walk(Calculations.random(3095, 3105), Calculations.random(3236, 3247));
            }
            return Calculations.random(1000, 2000);
        }
    }
     

    Link to comment
    Share on other sites

    1 hour ago, Pandemic said:

    It reminds me of ChatGPT, haha.

    It's using the old API so it wouldn't work in the latest client, and I think your eating/attacking logic is backwards or something?

    Haha well thats because it is chatGPT 

    I’ve been playing around with it and I think thats actually a bad example of some of the code its spat out, but I was curious to see if it could actually spit something workable out

    Link to comment
    Share on other sites

    Don't get it...

    If you're not in combat, you eat regardless of what your hp is?
    Also, you'd only attack the warrior, if you have UNDER 50%?  

    That seems extremely bug-prone. Wastes food, and can never attack the warrior, if you accidentally over-ate due to your eat logic.

     

    Maybe do an HP check before eating (vs just eating regardless of hp), and correct the attack logic, to if your hp is ABOVE 50%?

    Link to comment
    Share on other sites

    10 hours ago, oh_my_goth said:

    Don't get it...

    If you're not in combat, you eat regardless of what your hp is?
    Also, you'd only attack the warrior, if you have UNDER 50%?  

    That seems extremely bug-prone. Wastes food, and can never attack the warrior, if you accidentally over-ate due to your eat logic.

     

    Maybe do an HP check before eating (vs just eating regardless of hp), and correct the attack logic, to if your hp is ABOVE 50%?

    chatgpt wrote the code good sir

    its using the outdated API methods

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.