Jump to content

Grab equipment on start


Recommended Posts

Posted

I want to get worn equipment onStart and save the items to a string so i can re gear later on. Is this possible?

Something like :

String wornItems = getEquipment().getItems();

then later on i can do, if not wearing wornItems then bank, withdraw and equip wornItems.

Is it possible to use strings in this way, thanks in advance any help is appreciated

Posted
7 minutes ago, shaba123 said:

I want to get worn equipment onStart and save the items to a string so i can re gear later on. Is this possible?

Something like :

String wornItems = getEquipment().getItems();

then later on i can do, if not wearing wornItems then bank, withdraw and equip wornItems.

Is it possible to use strings in this way, thanks in advance any help is appreciated

Something like this may help you out :)

 

if (getEquipment().getItemInSlot(0) != null) {
                       String helmet = getEquipment().getItemInSlot(0).getName();

                    } 

  • Like 1
Posted (edited)
private ArrayList<String> wornItems = new ArrayList<>();
  
private void grabEquipment() {
  
  Item[] items = getEquipment().getItems(); // Grabs our equipment
  
  for (Item i : items) { // for each item in the items array, loop
  	wornItems.add(i.getName()); // add the item to the array
  	log("Equipment Item Added: " + i.getName());
  }
  
 }

It's been a while since I've used the OSBot API, but this should do. Just put the grabEquipment() method in your onStart and store your wornItems as a variable somewhere.

Edited by HeyImJamie
  • Heart 1
Posted
57 minutes ago, HeyImJamie said:

private ArrayList<String> wornItems = new ArrayList<>();
  
private void grabEquipment() {
  
  Item[] items = getEquipment().getItems(); // Grabs our equipment
  
  for (Item i : items) { // for each item in the items array, loop
  	wornItems.add(i.getName()); // add the item to the array
  	log("Equipment Item Added: " + i.getName());
  }
  
 }

It's been a while since I've used the OSBot API, but this should do. Just put the grabEquipment() method in your onStart and store your wornItems as a variable somewhere.

Hey that example worked but threw up some errors. Do you know why?

[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Blue wizard hat
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Fire cape
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Amulet of strength
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Granite maul
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Monk's robe top
[ERROR][Bot #1][05/24 03:09:45 PM]: Error in script onStart(): newScript
java.lang.NullPointerException
	at core.Main.grabEquipment(Main.java:113)
	at core.Main.onStart(Main.java:103)
	at org.osbot.rs07.event.ScriptExecutor.iiIiiiiiIiiI(kl:120)
	at org.osbot.rs07.event.ScriptExecutor.start(kl:129)
	at org.osbot.UB.run(dw:194)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

 

Posted
24 minutes ago, shaba123 said:

Hey that example worked but threw up some errors. Do you know why?


[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Blue wizard hat
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Fire cape
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Amulet of strength
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Granite maul
[INFO][Bot #1][05/24 03:09:45 PM]: Equipment Item Added: Monk's robe top
[ERROR][Bot #1][05/24 03:09:45 PM]: Error in script onStart(): newScript
java.lang.NullPointerException
	at core.Main.grabEquipment(Main.java:113)
	at core.Main.onStart(Main.java:103)
	at org.osbot.rs07.event.ScriptExecutor.iiIiiiiiIiiI(kl:120)
	at org.osbot.rs07.event.ScriptExecutor.start(kl:129)
	at org.osbot.UB.run(dw:194)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

  

Probably need to null check getName(), show me what line 113 is and I'll tell you

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...