Jump to content

First Script, Poor Scripting, Running Slowly


GamerNation101

Recommended Posts

Hi, this is my first post. I've had no experience with coding but I gave it a go. I tried to write a script that works in my logic, and it does, kinda. I know that it is messy. I'm looking for guidance on how to improve the script because the main reason being after about 5 seconds of it loading it starts to lag a whole lot from a certain point.

package FisherPack;

import java.awt.Graphics2D;

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Cal", info = "fisher", name = "Fisher", version = 0, logo = "")
public class CalsFish extends Script {
    
    private int animateChange;
    private int getNet;
    @Override
    public void onStart() {
        animateChange = 0;
        log("Let's get started!");
    }

    @Override
    public int onLoop() throws InterruptedException {
        
//////////////////////////////////////////////////////////////////////////////////////////////////////////
        if (getInventory().contains("Small fishing net")) {
            getNet = 2;
        }
        if (inventory.isEmpty()) {
            animateChange = 10;
            getNet = 1;
        }
        
        while (((getInventory().contains("Raw shrimps")) || (getInventory().contains("Raw anchovies"))) && (animateChange == 0)){
            objects.closest("Cooking range").interact("Cook");
            sleep(2000);
            widgets.interact(270, 14, "Cook");
            
            if (myPlayer().isAnimating()) {
                animateChange = animateChange + 1;
                log(animateChange);
                log("animate Change");                   //Sees if any raw anch or shrimp and cooks them
            }
            if (!myPlayer().isAnimating()) {
                animateChange = 0;                       //ill need to put this at end also
                sleep(100);
            }
        }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////    
        if ((getInventory().contains("Shrimps")) || (getInventory().contains("Anchovies"))){
            if ((!getInventory().contains("Raw shrimps")) || (!getInventory().contains("Raw anchovies"))){                
            }    
            walking.webWalk(new Position(3208,3218,2));
            sleep(random(100,500));
            objects.closest("Bank booth").interact("Bank");
            sleep(random(991,2873));                                  //when cook complete go and bank all
            widgets.interact(12, 42, "Deposit inventory");
            sleep(random(798,981));
        }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////        
        if (getNet == 1) {
            walking.webWalk(new Position(3208,3218,2));
            sleep(random(100,500));                           //walk to bank for net if none
            objects.closest("Bank booth").interact("Bank");
            sleep(random(1289,2101));
            bank.withdraw("Small fishing net", 1);
            sleep(random(867,1245));                         
            walking.webWalk(new Position(3242,3154,0));
            sleep(random(100,498));
            getNet = 0;
        }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
        bank.withdraw("Small fishing net", 1);
        sleep(random(867,1245));                                     //withdraw net
        walking.webWalk(new Position(3242,3154,0));
        sleep(random(100,498));
///////////////////////////////////////////////////////////////////////////////////////////////////////////
        //fishing begins here
        if (getNet == 2) {
            walking.webWalk(new Position(3241,3152,0));        //if start with fish net
            sleep(random(809,1109));    
            getNet = 0;
        }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
        npcs.closest(1530).interact("Net");
        sleep(random(2003,3001));
        while (myPlayer().isAnimating()){
            sleep(random(3506,5007));
        }
        if ((!myPlayer().isAnimating()) && (!inventory.isFull())) {
            npcs.closest(1530).interact("Net");
        }
        
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////        
            return random(500, 1000);
            }

    @Override
    public void onExit() {
        log("Thanks for running my Tree Cutter!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

Link to comment
Share on other sites

  • 2 weeks later...

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