May 24, 20187 yr 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
May 24, 20187 yr https://osbot.org/api/org/osbot/rs07/api/Equipment.html script.getEquipment().getItemInSlot(EquipmentSlot.SLOT);
May 24, 20187 yr 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(); }
May 24, 20187 yr 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 May 24, 20187 yr by HeyImJamie
May 24, 20187 yr Author 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)
May 24, 20187 yr 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
May 24, 20187 yr Author Line 113 is as so : wornItems.add(i.getName()); 42 minutes ago, HeyImJamie said: Probably need to null check getName(), show me what line 113 is and I'll tell you You were correct, works fine now with null check. Thank u sir Edited May 24, 20187 yr by shaba123
May 24, 20187 yr 21 minutes ago, shaba123 said: Line 113 is as so : wornItems.add(i.getName()); String itemName = i.getName(); if (itemName != null){ wornItems.add(itemName); } If you can't figure out how to implement a null check though having an equipment handler seems a little out of your depth for now.
May 24, 20187 yr Author 1 hour ago, HeyImJamie said: String itemName = i.getName(); if (itemName != null){ wornItems.add(itemName); } If you can't figure out how to implement a null check though having an equipment handler seems a little out of your depth for now. I said i added the null check, thanks
May 24, 20187 yr 6 hours ago, shaba123 said: I said i added the null check, thanks My bad, I didn't see the edit. Happy scripting!
May 25, 20187 yr Author 9 hours ago, HeyImJamie said: My bad, I didn't see the edit. Happy scripting! Thank you sir
Create an account or sign in to comment