Jump to content

2-Tick Cooker [Open Source][F2P Friendly]


Lol_marcus

Recommended Posts

Hi all,

I've missed writing osrs scripts, so I sat down today and came up with this little guy. In short, it will ask you to input whatever fish you want to cook through a simple GUI, and then it'll use the lumbridge cooking range (burns less fish) to drop all the fish, picking them up 1 by 1 to cook them at a 2-tick cycle.

 

The only requirement is cooks assistant to be completed, and to have the level to cook whichever fish you input.

 

I've pasted the full script, feel free to use it/leech it/customize it! I've left a lot of // commentary to help me remember what I was doing. :D

 

I've been running it for about 2 hours now and it's run flawlessly, I've even added failsafes for when it picks up 2 fish by mistake, or a few other things that can go wrong.

 

package osrs;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import javax.swing.*;
import java.awt.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

@ScriptManifest(name = "Efficient 2-tick Cooker", author = "Marcus", version = 1.0, info = "A script that drops fish in order to 2-tick cook them", logo = "")
public class Main extends Script {

    private String itemName; // Item to cook
    private Area dropArea = new Area(3211, 3215, 3211, 3215); // Area of itemName on the ground

    private long startTime;
    private int startingXP;
    private int currentXP;
    private int xpGained;
    long amountLeft;

    private final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    private final DecimalFormat decimalFormat = new DecimalFormat("#,###");

    @Override
    public void onStart() {
        // Prompt user to input item name through a simple GUI
        itemName = JOptionPane.showInputDialog("Enter the item name to cook:");
        startTime = System.currentTimeMillis();
        startingXP = getSkills().getExperience(Skill.COOKING);
        xpGained = 0;
        getExperienceTracker().start(Skill.COOKING);
    }

    @Override
    public int onLoop() throws InterruptedException {
        GroundItem groundItem = getGroundItems().closest(itemName);
        if (getInventory().contains(itemName) && getInventory().getAmount(itemName) >= 2) {
            // If inventory is full, drop all items at the collection area
            if (dropArea.contains(myPosition())) {
                getInventory().dropAll(itemName);
                // Conditional sleep
                Sleep.sleepUntil(() -> getInventory().getAmount(itemName) == 1, random(500, 1000));
            } else {
                getWalking().webWalk(dropArea);
                sleep(random(500, 1000)); // Sleep between 0.5-1 seconds
            }
        } else if (!getInventory().contains(itemName) && groundItem != null) {
            // If inventory is empty and item found on the ground, take 1 item
            groundItem.interact("Take");
            // Conditional sleep
            Sleep.sleepUntil(() -> getInventory().contains(itemName), random(500, 1000));
        } else if (getInventory().contains(itemName) && getInventory().getAmount(itemName) == 1) {
            getObjects().closest("Cooking range").interact("Cook");
            // Conditional sleep
            Sleep.sleepUntil(() -> !getInventory().contains(itemName), random(500, 1000));
        } else {
            // If no item on the ground and inventory is not full, walk to the collection area
            if (Banks.LUMBRIDGE_UPPER.contains(myPosition())) {
                getBank().open();
                // Conditional sleep
                Sleep.sleepUntil(() -> getBank().isOpen(), random(500, 1000));
                if (!getBank().contains(itemName)) {
                    log("Item not found in the bank. Stopping script...");
                    stop(false);
                }
                getBank().depositAll();
                // Conditional sleep
                Sleep.sleepUntil(() -> getInventory().isEmpty(), random(500, 1000));
                if (getBank().contains(itemName)) {
                    getBank().withdraw(itemName, 28);
                    amountLeft = getBank().getAmount(itemName);
                    // Conditional sleep
                    Sleep.sleepUntil(() -> getInventory().contains(itemName) && getInventory().getAmount(itemName) == 28, random(500, 1000));
                }
                getBank().close();
                // Conditional sleep
                Sleep.sleepUntil(() -> !getBank().isOpen(), random(500, 1000));
            } else {
                getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
                sleep(random(500, 1000)); // Sleep between 0.5-1 seconds
            }
        }
        return 0; // Return 0
    }
    
    @Override
    public void onExit() {
        log("Thank you for using Efficient 2-tick Cooker!");
    }


    @Override
    public void onPaint(Graphics2D g) {
    	
        currentXP = getSkills().getExperience(Skill.COOKING);
        xpGained = currentXP - startingXP;
        int xpHour = getExperienceTracker().getGainedXPPerHour(Skill.COOKING);
        
        Point mP = getMouse().getPosition();
        g.drawLine(mP.x, 501, mP.x, 0);
        g.drawLine(0, mP.y, 764, mP.y);
        g.setColor(Color.white);
        
        // Paint background
        g.setColor(Color.BLACK);
        g.fillRect(5, 5, 200, 110);

        // Paint border
        g.setColor(Color.WHITE);
        g.drawRect(5, 5, 200, 110);

        // Paint text
        g.setColor(Color.WHITE);
        g.drawString("Efficient 2-tick Cooker", 15, 25);
        g.drawString("Time Running: " + formatTime(System.currentTimeMillis() - startTime), 15, 45);
        g.drawString("Total XP Gained: " + decimalFormat.format(xpGained), 15, 65);
        g.drawString("Total XP Per hour: " + decimalFormat.format(xpHour), 15, 85);
        g.drawString(itemName + " in Bank: " + numberFormat.format(amountLeft), 15, 105);
    }

    private String formatTime(long ms) {
        long seconds = ms / 1000;
        long minutes = seconds / 60;
        long hours = minutes / 60;
        minutes %= 60;
        seconds %= 60;
        return String.format("%02d:%02d:%02d", hours, minutes, seconds);
    }
}

 

  • Like 3
  • Boge 2
Link to comment
Share on other sites

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