Defiled 406 Share Posted November 15, 2019 (edited) 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! Edited November 25, 2019 by ItsDefiled Updated the first method and update the second code to go with the first method 7804364 and im trob 2 Link to comment Share on other sites More sharing options...
Pseudo 177 Share Posted November 15, 2019 Good job on the contribution pal, but that first method in particular could be written far better. Defiled 1 Link to comment Share on other sites More sharing options...
Defiled 406 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 2517 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 Defiled and yeeter01 2 Link to comment Share on other sites More sharing options...
yeeter01 445 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 (edited) 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())); } } } Edited November 16, 2019 by NovaGTX yeeter01 and Defiled 1 1 Link to comment Share on other sites More sharing options...
yeeter01 445 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 NovaGTX 1 Link to comment Share on other sites More sharing options...
Defiled 406 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 (edited) 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. Edited November 26, 2019 by NovaGTX Link to comment Share on other sites More sharing options...
Defiled 406 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. im trob 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now