Jump to content

Developing a "making pie shells" script


Recommended Posts

Enjoy.

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;

import com.epicbot.api.shared.script.LoopScript;
import com.epicbot.api.shared.script.ScriptManifest;
import com.epicbot.api.shared.util.paint.frame.PaintFrame;
import com.epicbot.api.shared.util.time.Time;

import java.awt.*;

@ScriptManifest(name = "Pie Sheller", gameType = GameType.OS)
public class PieSheller extends LoopScript {

	private long startTime;

	@Override
	public boolean onStart(String... strings) {
		startTime = System.currentTimeMillis();
		return true;
	}

	@Override
	protected int loop() {
		if (!getAPIContext().inventory().contains("Pastry dough", "Pie dish")) {
			bank();
		} else {
			combine();
		}
		return 700;
	}

	private void bank() {
		if (!getAPIContext().bank().isOpen()) {
			getAPIContext().bank().open();
			Time.sleep(5_000, () -> getAPIContext().bank().isOpen());
		}

		else if (getAPIContext().bank().isOpen()) {
			getAPIContext().bank().depositInventory();
			Time.sleep(5_000, () -> getAPIContext().bank().isOpen());
			getAPIContext().bank().withdraw(14, "Pastry dough");
			Time.sleep(5_000, () -> getAPIContext().inventory().contains("Pastry dough"));
			getAPIContext().bank().withdraw(14, "Pie dish");
			Time.sleep(5_000, () -> getAPIContext().inventory().contains("Pie dish"));
			getAPIContext().bank().close();

		}

	}

	private void combine() {
		if (getAPIContext().inventory().contains("Pastry dough", "Pie dish")) {
			getAPIContext().inventory().selectItem("Pastry dough", "Use");
			Time.sleep(5_000, () -> getAPIContext().inventory().isItemSelected());
			getAPIContext().inventory().selectItem("Pie dish");
			Time.sleep(5_000, () -> !getAPIContext().dialogues().isChatOpen());
			getAPIContext().keyboard().sendText(" ", true);
			Time.sleep(30_000, () -> getAPIContext().localPlayer().isAnimating()
					|| !getAPIContext().inventory().contains("Pastry dough", "Pie dish"));

		}
	}

	@Override
	protected void onPaint(Graphics2D g, APIContext ctx) {
		PaintFrame pf = new PaintFrame();
		pf.setTitle("Pie Sheller Script by Marcus");
		pf.addLine("Runtime: ", Time.getFormattedRuntime(startTime));
		pf.draw(g, 0, 90, ctx);
	}
}

 

  • Sad 1
Link to comment
Share on other sites

7 hours ago, lol_marcus said:

Enjoy.

 

No need to add sleeps after every action 😛 Most functions return you a boolean based on if it was successful or not.

I'd also add some more checks, for example, if you lag for a sec, you'll be missing steps and you're not confirming your functions actually succeeded or not, waiting 5 seconds between each one because it's not doing what the code is expecting etc

Link to comment
Share on other sites

13 hours ago, Proto said:

No need to add sleeps after every action 😛 Most functions return you a boolean based on if it was successful or not.

I'd also add some more checks, for example, if you lag for a sec, you'll be missing steps and you're not confirming your functions actually succeeded or not, waiting 5 seconds between each one because it's not doing what the code is expecting etc

 

The lambda expression would solve the lag example. That`s why I have it wait 5 seconds. If the condition doesn't happen after 5 seconds, it should loop again, no?

Anyway, it's just something quick that I wrote up for the guy who asked for the specific script. Ran it for about an hour and it was fine. 😛

It wouldn't be something I would submit to the script repository.

Link to comment
Share on other sites

On 4/22/2021 at 12:23 AM, lol_marcus said:

Enjoy.


import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;

import com.epicbot.api.shared.script.LoopScript;
import com.epicbot.api.shared.script.ScriptManifest;
import com.epicbot.api.shared.util.paint.frame.PaintFrame;
import com.epicbot.api.shared.util.time.Time;

import java.awt.*;

@ScriptManifest(name = "Pie Sheller", gameType = GameType.OS)
public class PieSheller extends LoopScript {

	private long startTime;

	@Override
	public boolean onStart(String... strings) {
		startTime = System.currentTimeMillis();
		return true;
	}

	@Override
	protected int loop() {
		if (!getAPIContext().inventory().contains("Pastry dough", "Pie dish")) {
			bank();
		} else {
			combine();
		}
		return 700;
	}

	private void bank() {
		if (!getAPIContext().bank().isOpen()) {
			getAPIContext().bank().open();
			Time.sleep(5_000, () -> getAPIContext().bank().isOpen());
		}

		else if (getAPIContext().bank().isOpen()) {
			getAPIContext().bank().depositInventory();
			Time.sleep(5_000, () -> getAPIContext().bank().isOpen());
			getAPIContext().bank().withdraw(14, "Pastry dough");
			Time.sleep(5_000, () -> getAPIContext().inventory().contains("Pastry dough"));
			getAPIContext().bank().withdraw(14, "Pie dish");
			Time.sleep(5_000, () -> getAPIContext().inventory().contains("Pie dish"));
			getAPIContext().bank().close();

		}

	}

	private void combine() {
		if (getAPIContext().inventory().contains("Pastry dough", "Pie dish")) {
			getAPIContext().inventory().selectItem("Pastry dough", "Use");
			Time.sleep(5_000, () -> getAPIContext().inventory().isItemSelected());
			getAPIContext().inventory().selectItem("Pie dish");
			Time.sleep(5_000, () -> !getAPIContext().dialogues().isChatOpen());
			getAPIContext().keyboard().sendText(" ", true);
			Time.sleep(30_000, () -> getAPIContext().localPlayer().isAnimating()
					|| !getAPIContext().inventory().contains("Pastry dough", "Pie dish"));

		}
	}

	@Override
	protected void onPaint(Graphics2D g, APIContext ctx) {
		PaintFrame pf = new PaintFrame();
		pf.setTitle("Pie Sheller Script by Marcus");
		pf.addLine("Runtime: ", Time.getFormattedRuntime(startTime));
		pf.draw(g, 0, 90, ctx);
	}
}

 

oof

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

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.

×
×
  • Create New...