Jump to content

Ghoul killer :)


Rare scripts

Recommended Posts

1 hour ago, Rare scripts said:

Simple but does the trick!

Did not see one around and had to make one real quick, so why not share it?

-Start @ Canifis bank or ghouls, Pick food from the GUI.

Enjoy!
-Rare.

GhoulKiller.jar

Thanks for sharing! Would you mind pasting the source code so I can learn from it? :D

 

  • Like 1
Link to comment
Share on other sites

9 hours ago, D Bolter said:

Thanks for sharing! Would you mind pasting the source code so I can learn from it? :D

 

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.function.BooleanSupplier;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;


@ScriptManifest(author = "Rare Scripts", name = "Ghoul killer", info = "Start in bank or @ Ghouls", version = 1, logo = "")
public final class GhoulKiller extends Script {
	
	public final Area GhoulArea = new Area(3425, 3467, 3438, 3457);
	public final Area BankArea = new Area(3509, 3483, 3513, 3476);
	
	String CurrentState, FoodName;
	private long startTime;
	private MouseTrail trail = new MouseTrail(0, 255, 255, 2000, this);
	private MouseCursor cursor = new MouseCursor(52, 4, Color.red, this);
	public Boolean finishedGUI = false;
	private JPanel ScriptName;
	private JTextField textField;
	int eatOn;

	public void JFrame() {

		JFrame ScriptName;
		ScriptName = new JFrame();
		ScriptName.setTitle("Rare Ghoul killer");
		ScriptName.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		ScriptName.setBounds(100, 100, 406, 155);
		ScriptName.getContentPane();
		ScriptName.setLayout(null);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"- Food -", "Trout", "Salmon", "Lobster"}));
		comboBox.setBounds(10, 11, 100, 20);
		ScriptName.add(comboBox);
		
		JLabel lblEatOn = new JLabel("Eat on:");
		lblEatOn.setBounds(10, 42, 35, 14);
		ScriptName.add(lblEatOn);
		
		textField = new JTextField();
		textField.setText("56");
		textField.setBounds(55, 39, 22, 20);
		ScriptName.add(textField);
		textField.setColumns(10);
		
		JLabel label = new JLabel("%");
		label.setBounds(83, 42, 11, 14);
		ScriptName.add(label);
		
		JButton btnNewButton = new JButton("Start");
		btnNewButton.setBounds(10, 114, 100, 23);
		ScriptName.add(btnNewButton);
		
		ScriptName.getContentPane().add(btnNewButton);
		ScriptName.setVisible(true);
		btnNewButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			ScriptName.setVisible(false);
			ScriptName.dispose();
		    FoodName = comboBox.getSelectedItem().toString();
			eatOn = Integer.parseInt(textField.getText());
			finishedGUI = true;
		}
	});
}
	
@Override
public final void onStart() {
	CurrentState = "Starting script...";
	startTime = System.currentTimeMillis();
	JFrame();
}
	
public void TerminateScript(String reason) {
	log("[Terminate - Reason]: "+reason);
	 widgets.closeOpenInterface(); 
	 stop();
}

public boolean needEating() {
	return myPlayer().getHealthPercent() < eatOn;
}	

public void EatFood() {
	if (getInventory().contains(FoodName)) {
		int oldHealth = myPlayer().getHealthPercent();
		if (getInventory().getItem(FoodName).interact("Eat")) {
			Sleep.sleepUntil(() -> myPlayer().getHealthPercent() > oldHealth, 5000);
		}
	}
}

public void FightMonster(String name) {
	if (needEating()) {
		return;
	}

	
	if (myPlayer().isUnderAttack()) {
		Sleep.sleepUntil(() -> !myPlayer().isUnderAttack() || needEating(), 85000);
		return;
	}
	
	NPC theNpc = getNpcs().closest(name);
	if (theNpc != null && map.canReach(theNpc) && theNpc.isAttackable()) {
		if (theNpc.isVisible()) {
		if (!myPlayer().isUnderAttack() && !theNpc.isUnderAttack() && theNpc.hasAction("Attack")) {
			if (theNpc.interact("Attack")) {
				Sleep.sleepUntil(() -> myPlayer().isUnderAttack() || !theNpc.exists(), 9000);
				Sleep.sleepUntil(() -> !theNpc.exists() || !myPlayer().isUnderAttack() || needEating(), 85000);
			}
		}
	 } else {
		 if (map.isWithinRange(theNpc, 8)) {
				getCamera().toPosition(theNpc.getPosition());
			} else {
				getWalking().webWalk(theNpc.getPosition());
			}
	 }
	}
}

public void WithdrawItem(String name, int amount, boolean StopNotFound) {
if (getBank().contains(name)) {
		getBank().withdraw(name, amount);
	} else {
		if (StopNotFound == true) {
			getBank().close();
			Sleep.sleepUntil(() -> !getBank().isOpen(), 9000);
			TerminateScript("No "+name+" found in bank");
		}
	}	
}

public void HandleBank() throws InterruptedException {
if (getBank().isOpen()) {
	getBank().depositAll();
	WithdrawItem(FoodName, -1, true);
	getBank().close();
	Sleep.sleepUntil(() -> !getBank().isOpen() && getInventory().contains(FoodName), 9000);
} else {
	getBank().open();
}
}

@Override
public final int onLoop() throws InterruptedException {
if (finishedGUI == true) {
	if (getInventory().contains(FoodName)) {
		if (GhoulArea.contains(myPlayer())) {
		if (needEating()) {
			CurrentState = "Eating "+FoodName+"...";
			EatFood();
		} else {
			CurrentState = "Fighting...";
			FightMonster("Ghoul");
		}
		} else {
			CurrentState = "Running to Ghouls...";
			getWalking().webWalk(GhoulArea);
		}
	} else {
		if (BankArea.contains(myPlayer())) {
			CurrentState = "Banking...";
			HandleBank();
		} else {
			CurrentState = "Running to Bank...";
			getWalking().webWalk(BankArea);
		}
	}
}
	return random(50, 500);
}
	
	
@Override
public final void onExit() {
    log("Script terminated! :)");
    ScriptName.setVisible(false);
}		
@Override
public final void onMessage(final Message message) {
    //log("New msg: " + message.getMessage());
}
	
@Override
public void onPaint(final Graphics2D g) {
	trail.paint(g);
	cursor.paint(g);
    g.drawString("Rare Ghoul killer", 12, 130);
	g.drawString("Time running: "+formatTime(System.currentTimeMillis() - startTime), 12, 150);
	g.drawString("State: "+CurrentState, 12, 170);
}

public final String formatTime(final long ms) {
long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
s %= 60;
m %= 60;
h %= 24;

return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s)
: h > 0 ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s);
}
	
}

If u have any questions feel free to shoot me a PM :)

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