Jump to content

Judge my first script


icepotion

Recommended Posts

SO... i decided i want to make bots for osrs because it looked fun, so far it has been exactly that, that and gold. I'm a greedy beach. 

I made a separate botting account because i'm not going to risk my 10 year old account. And i wanted to lvl up my cooking, so i did the first thing that popped into my mind - cook fish. I made a script so that i fished (actually it was shrimps because you don't need bait or anything with shrimp) until my inventory was full, then i ran to the closest trees, chopped it down, made a fire and cooked it all. Dropped it all and ran back to cast my net once more. I wanted to add a banking part to the script but then the account got banned, because this technically wasn't my first script. Before this one i made one that killed goblins and then cows to get food to kill more goblins, but that one is a complete mess (that worked) and i don't want another living soul to see that.

It worked but i know there can be optimizations and i just wanted to know what you kind people might suggest. (i most likely will skill cooking with a different method but still)

Quote

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.api.Walking;

import java.awt.*;

import java.awt.Graphics2D;
import java.util.Arrays;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Ma dick", info = "pizza", name = "Cooking trainer + bank", version = 69, logo = "")
public class ass extends Script {



    public int fish_flag = 0;



    @Override
    public void onStart() {
        log("Now we becomin cuc");

    }

    @Override
    public int onLoop() throws InterruptedException {

        Position[] path_to_trees = {
                new Position(3237, 3159, 0), new Position(3239, 3168, 0),
                new Position(3241, 3179, 0), new Position(3244, 3190, 0),
                new Position(3241, 3195, 0), new Position(3238, 3201, 0),
                new Position(3234, 3211, 0), new Position(3235, 3223, 0),
                new Position(3232, 3230, 0),
                new Position(3224, 3236, 0), new Position(3220, 3244, 0)
        };

        Position[] path_to_shrimp = {
                new Position(3220, 3244, 0), new Position(3224, 3236, 0),
                new Position(3232, 3230, 0),
                new Position(3235, 3223, 0), new Position(3234, 3211, 0),
                new Position(3238, 3201, 0), new Position(3241, 3195, 0),
                new Position(3244, 3190, 0), new Position(3241, 3179, 0),
                new Position(3239, 3168, 0), new Position(3237, 3159, 0)
        };

        String raw_food = "Raw shrimps";

        switch (fish_flag){
            case 0:
                log("fish flag 0");
                if(getInventory().getEmptySlots() > 2) {
                    if (getNpcs().closest("Fishing spot") == null) {
                        if (!getNpcs().closest("Fishing spot").hasAction("Net")) {
                            getWalking().webWalk(new Position(3240, 3153, 0));
                        }
                    } else {
                        if (!myPlayer().isAnimating()) {
                            getNpcs().closest("Fishing spot").interact("Net");
                            sleep(random(1000, 5000));
                        } else {
                            sleep(10000);
                        }
                    }
                } else if (getInventory().getEmptySlots() == 0){
                    getInventory().drop(raw_food);
                } else {
                    fish_flag = 1;
                }
                break;
            case 1:
                log("fish flag 1");
                getWalking().walkPath(Arrays.asList(path_to_trees));
                if(getObjects().closest("Tree") != null) {
                    fish_flag = 2;
                }
                break;
            case 2:
                log("fish flag 2");
                if (getInventory().contains(raw_food)) {
                    if (getObjects().closest("Fire") == null) {
                        if (getInventory().contains("Logs")) {
                            getInventory().getItem("Logs").interact("Use");
                            sleep(random(600, 1200));
                            getInventory().getItem("Tinderbox").interact("Use");
                            sleep(20000);
                        } else {
                            getObjects().closest("Tree").interact("Chop down");
                            sleep(10000);
                        }
                    } else {
                        getInventory().getItem(raw_food).interact("Use");
                        sleep(random(800, 1500));
                        getObjects().closest("Fire").interact("Use");
                        sleep(random(800, 1500));
                        getMouse().click(255, 431, false);
                        sleep(30000);
                    }
                } else if (getInventory().contains("Burnt shrimp")){
                    getInventory().drop("Burnt shrimp");
                    sleep(random(1200, 2000));
                } else if (getInventory().contains("Shrimps")){
                    getInventory().drop("Shrimps");
                    sleep(random(1200, 2000));
                } else {
                    getWalking().walkPath(Arrays.asList(path_to_shrimp));
                    if (getNpcs().closest("Fishing spot") != null){
                        fish_flag = 0;
                    }
                }
                break;
        }



        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("I hope you learnt cookn/fishn skills");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

 

Link to comment
Share on other sites

Few general thing,

1. Look into conditional sleeps

2. Look into task based scripts, this will help you in the future to save time on new scripts

3. You are going to get a LOT of null pointers because you are basically running no checks.

Something like:
getInventory().getItem("Tinderbox").interact("Use");

Should actualy look like:

Item tinderbox = getInventory().getItem("Tinderbox");

if (tinderbox != null) {
    tinderbox.interact("Use")

(TBH, you should also add a conditional sleep that checks that the tinderbox was selected successfully.)

4. Look into webwalking

 

Other than that, pretty nice script structer for a first script, keep it going and keep improving :) 

Edited by HunterRS
  • Like 2
Link to comment
Share on other sites

@HunterRS, @Gunman Thanks for the tips!!

The conditional sleep will sure make it more efficient, i was actually wondering if something like that exists.

I thought that webwalking was less reliable, but ill look more into it. I had used it in my very first script and sometimes it did weird stuff.

Ill write some of this down actually :D thanks!!!

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