Defiled 423 Share Posted November 15, 2019 Hello, This snippet gets your items from the spot you died at and equips the items you had equipped. Get Items that you are equipping (execute in the onStart method): Credit for suggestion: @Nex Credit for the getItems() code: @NovaGTX private HashMap<EquipmentSlot, Item> slots = new HashMap<EquipmentSlot, Item>(); private void getItems() { for(EquipmentSlot i : EquipmentSlot.values()) { if(getEquipment().getItemInSlot(i.getSlot()) != null) { slots.put(i, getEquipment().getItemInSlot(i.getSlot())); } } } Get Death Location: private static Tile deathTile; deathTile = getLocalPlayer().getTile(); Know when the player dies: if(getLocalPlayer().getHealthPercent() == 0) { Death Method (Executed when player dies): private void death() { if(deathTile.getArea(2).contains(getLocalPlayer())) { GroundItem[] deathItems = getGroundItems().getGroundItems(deathTile); if(deathItems != null) { for(GroundItem deathItem : deathItems) { if(deathItem != null) { deathItem.interact("Take"); sleepUntil(()->!deathItem.exists(), 2000); } } } if(getTabs().isOpen(Tab.INVENTORY)) { if(!getEquipment().containsAll(slots.values())) { for(Item equippedItem : slots.values()) { if(getInventory().contains(equippedItem) && equippedItem != null) { String action = null; if(equippedItem.hasAction("Equip")) { action = "Equip"; } else if(equippedItem.hasAction("Wear")) { action = "Wear"; } else if(equippedItem.hasAction("Wield")) { action = "Wield"; } if(action != null) { getInventory().interact(equippedItem.getName(), action); } } } } } else { getTabs().open(Tab.INVENTORY); } } else { if(getWalking().shouldWalk()) { getWalking().walk(deathTile); } } } There it is! Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted November 15, 2019 Good job on the contribution pal, but that first method in particular could be written far better. Link to comment Share on other sites More sharing options...
Defiled 423 Author Share Posted November 15, 2019 35 minutes ago, Pseudo said: Good job on the contribution pal, but that first method in particular could be written far better. Thank you! I agree, I could add all the slots to an array then loop through them to check if they are empty or not.. OR just simply minimize the size of it ... suggestions are welcome! Link to comment Share on other sites More sharing options...
Nex 2542 Share Posted November 16, 2019 5 hours ago, ItsDefiled said: Thank you! I agree, I could add all the slots to an array then loop through them to check if they are empty or not.. OR just simply minimize the size of it ... suggestions are welcome! Would suggest a hashmap for this Link to comment Share on other sites More sharing options...
yeeter 522 Share Posted November 16, 2019 2 hours ago, Nex said: Would suggest a hashmap for this hashmap for da win Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted November 16, 2019 Suggested edit for your first function. private HashMap<EquipmentSlot, Item> slots = new HashMap<EquipmentSlot, Item>(); private void getItems() { for(EquipmentSlot i : EquipmentSlot.values()) { if(getEquipment().getItemInSlot(i.getSlot()) != null) { slots.put(i, getEquipment().getItemInSlot(i.getSlot())); } } } Link to comment Share on other sites More sharing options...
yeeter 522 Share Posted November 16, 2019 59 minutes ago, NovaGTX said: Suggested edit for your first function. private HashMap<EquipmentSlot, Item> slots = new HashMap<EquipmentSlot, Item>(); private void getItems() { for(EquipmentSlot i : EquipmentSlot.values()) { if(getEquipment().getItemInSlot(i.getSlot()) != null) { slots.put(i, getEquipment().getItemInSlot(i.getSlot())); } } } Exactly how I do it in a couple scripts I've made. Iterative process do I dont have to write 20 if statements for each slot. Quality snippet @NovaGTX Link to comment Share on other sites More sharing options...
Defiled 423 Author Share Posted November 25, 2019 @Nex Thank you for the Hashmap Suggestion! @NovaGTX Thank you for the contribution, I've added your method in. Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted November 26, 2019 Also you should change this if(getInventory().contains(equippedItem) && equippedItem != null) { String action = null; if(equippedItem.hasAction("Equip")) { action = "Equip"; } else if(equippedItem.hasAction("Wear")) { action = "Wear"; } else if(equippedItem.hasAction("Wield")) { action = "Wield"; } if(action != null) { getInventory().interact(equippedItem.getName(), action); } } to a utilize a lambda expression: for(Item equippedItem : slots.values()) { if(getInventory().get(item -> item != null && item.equals(equippedItem)).interact()) { //Equipped item } } Each of the actions you listed are left click, you can just interact with the object to equip it regardless of which it is. You could make it check each action but it's not as clean and not 100% necessary. Link to comment Share on other sites More sharing options...
Defiled 423 Author Share Posted November 26, 2019 10 hours ago, NovaGTX said: Also you should change this if(getInventory().contains(equippedItem) && equippedItem != null) { String action = null; if(equippedItem.hasAction("Equip")) { action = "Equip"; } else if(equippedItem.hasAction("Wear")) { action = "Wear"; } else if(equippedItem.hasAction("Wield")) { action = "Wield"; } if(action != null) { getInventory().interact(equippedItem.getName(), action); } } to a utilize a lambda statement: for(Item equippedItem : slots.values()) { if(getInventory().get(item -> item != null && item.equals(equippedItem)).interact()) { //Equipped item } } Each of the actions you listed are left click, you can just interact with the object to equip it regardless of which it is. You could make it check each action but it's not as clean and not 100% necessary. Yeah, uhm i wrote the last code in regards with an older version where itll pick up all the items and interact with the items that have the actions wield, equip, and wear.. didnt update it when i changed the way i went around redoing it because it just worked fine. Thank you for the edit, I will edit it in once i reach my pc. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.