shaba123 Posted May 24, 2018 Posted May 24, 2018 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
01053 Posted May 24, 2018 Posted May 24, 2018 https://osbot.org/api/org/osbot/rs07/api/Equipment.html script.getEquipment().getItemInSlot(EquipmentSlot.SLOT); 1
CasDeBlanco Posted May 24, 2018 Posted May 24, 2018 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(); } 1
HeyImJamie Posted May 24, 2018 Posted May 24, 2018 (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 May 24, 2018 by HeyImJamie 1
shaba123 Posted May 24, 2018 Author Posted May 24, 2018 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)
HeyImJamie Posted May 24, 2018 Posted May 24, 2018 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
shaba123 Posted May 24, 2018 Author Posted May 24, 2018 (edited) 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, 2018 by shaba123
HeyImJamie Posted May 24, 2018 Posted May 24, 2018 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.
shaba123 Posted May 24, 2018 Author Posted May 24, 2018 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
HeyImJamie Posted May 24, 2018 Posted May 24, 2018 6 hours ago, shaba123 said: I said i added the null check, thanks My bad, I didn't see the edit. Happy scripting!
shaba123 Posted May 25, 2018 Author Posted May 25, 2018 9 hours ago, HeyImJamie said: My bad, I didn't see the edit. Happy scripting! Thank you sir