Hey everyone,
Here is the source code of my bone burier script, do with it whatever you want. Hopefully i can help someone out with this code.
Check out this topic to see how the bot works or if you want to use it.
This script also contains information about how to use user input before a script starts, see this topic for specific information.
import org.rspeer.runetek.adapter.component.Item;
import org.rspeer.runetek.api.commons.Time;
import org.rspeer.runetek.api.component.Bank;
import org.rspeer.runetek.api.component.tab.Inventory;
import org.rspeer.script.Script;
import org.rspeer.script.ScriptMeta;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
@ScriptMeta(name = "[LUX] Bones burier", desc = "Buries all bones", developer = "Luxiflex", version = 1.0)
public class LuxBonesBurier extends Script {
String bones = "";
@Override
public void onStart() {
//Create a JFrame
JFrame frame;
frame = new JFrame("Select bones");
frame.setLayout(null);
frame.setSize(245, 80);
frame.setVisible(true);
//Creating a label
final JLabel label = new JLabel();
label.setSize(400, 100);
label.setText("Select bones to bury:");
//Creating a button to start the script
JButton btnStart = new JButton("Start");
//Creating a combobox
String availableBones[] = {"Bones", "Big bones", "Baby dragon bones", "Dragon bones", "Wyvern bones", "Wolf bones", "Monkey bones", "Bat bones", "Joge bones", "Zogre bones", "Fayrg bones", "Lava dragon bones", "Raurg bones", "Dagannoth bones", "Ourg bones", "Superior dragon bones"};
final JComboBox cb = new JComboBox(availableBones);
//Positioning all components
label.setVerticalAlignment(JLabel.TOP);
label.setHorizontalAlignment(JLabel.LEFT);
btnStart.setBounds(160, 25, 75, 20);
cb.setBounds(5, 25, 150, 20);
//Add all the components to the frame
frame.add(cb);
frame.add(label);
frame.add(btnStart);
//Create the button action
btnStart.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
//Set 'bones' to the selected value
bones = ""+cb.getItemAt(cb.getSelectedIndex());
//Close the frame and the script will start
frame.dispatchEvent(new WindowEvent(frame,WindowEvent.WINDOW_CLOSING));
}
});
}
@Override
public int loop() {
if(!bones.equals("")){
if(!Inventory.contains(bones)){
System.out.println("Banking...");
Bank.open();
Time.sleepUntil( () -> Bank.isOpen(), 2000);
if(Bank.isOpen()){
if(!Inventory.isEmpty()){
Bank.depositInventory();
Time.sleepUntil( () -> Inventory.isEmpty(), 2000);
}
if(Bank.contains(bones)){
Bank.withdrawAll(bones);
Time.sleepUntil( () -> !Inventory.isEmpty(), 2000);
Bank.close();
}else{
//stop script
System.out.println("Couldn't find " + bones + " in your bank, stopping script...");
this.setStopping(true);
}
}
}
else{
System.out.println("Burying bones...");
Item[] items = Inventory.getItems();
for(Item item : items){
if(item.getName().equals(bones)&&!item.isNoted()){
item.interact("Bury");
Time.sleep(1000,1100);
}
if (this.isPaused() || this.isStopping()) {
break;
}
}
}
}
return 0;
}
@Override
public void onStop() {
System.out.println("Script stopped.");
super.onStop();
}
}
As always, I would love to see suggestions and improvements for this script, let me know in the comments.
Enjoy!