Jump to content

Grab equipment on start


shaba123

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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

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