abouhanafy87 6 Posted March 21, 2023 hi every one . i hope this script help . public void SolveGeniLamp(Skill skill){ Item item = Inventory.get(it-> it.getName().equals("Lamp") && it.hasAction("Rub")); if(item != null ){ if(item.interact("Rub")){ Sleep.sleep(1000,1500); Widget choiseSkill = Widgets.getWidget(240); if(choiseSkill != null && choiseSkill.isVisible()){ switch (skill){ case ATTACK: wig = Widgets.getChildWidget(240,2); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case STRENGTH: wig = Widgets.getChildWidget(240,3); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case RANGED: wig = Widgets.getChildWidget(240,4); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case MAGIC: wig = Widgets.getChildWidget(240,5); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case DEFENCE: wig = Widgets.getChildWidget(240,6); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case HITPOINTS: wig = Widgets.getChildWidget(240,7); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case PRAYER: wig = Widgets.getChildWidget(240,8); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case AGILITY: wig = Widgets.getChildWidget(240,9); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case HERBLORE: wig = Widgets.getChildWidget(240,10); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case THIEVING: wig = Widgets.getChildWidget(240,11); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case CRAFTING: wig = Widgets.getChildWidget(240,12); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case RUNECRAFTING: wig = Widgets.getChildWidget(240,13); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case SLAYER: wig = Widgets.getChildWidget(240,14); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case FARMING: wig = Widgets.getChildWidget(240,15); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case MINING: wig = Widgets.getChildWidget(240,16); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case SMITHING: wig = Widgets.getChildWidget(240,17); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case FISHING: wig = Widgets.getChildWidget(240,18); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case COOKING: wig = Widgets.getChildWidget(240,19); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case FIREMAKING: wig = Widgets.getChildWidget(240,20); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case WOODCUTTING: wig = Widgets.getChildWidget(240,21); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case FLETCHING: wig = Widgets.getChildWidget(240,22); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case CONSTRUCTION: wig = Widgets.getChildWidget(240,23); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; case HUNTER: wig = Widgets.getChildWidget(240,24); widg = Widgets.getChildWidget(240,26); if(wig != null && wig.isVisible()){ if(wig.interact()){ Sleep.sleep(500,1200); widg.interact(); } }else Widgets.closeAll(); break; default: Logger.log("ther is no widgit like this"); choiseSkill.close(); } } } } }
hashbang 8 Posted March 22, 2023 Nice first attempt. There is a huge amount of repeated code in there, each case of the switch statement is basically the same code. One way you could simplify this is by storing a map of Skills & their corresponding WidgetChild Ids, then you can grab the child widget id as a variable and pass it into the widget interaction block. static Map<Skill, Integer> SKILL_WIDGETID_MAP = new HashMap<>(){{ put(Skill.ATTACK, 2); put(Skill.STRENGTH, 3); put(Skill.RANGED, 4); //TODO: Add all other skills here }}; public void SolveGeniLamp(Skill skill) { Item item = Inventory.get(it-> it.getName().equals("Lamp") && it.hasAction("Rub")); if (item == null) { return; // Return early, nothing to do. } if (item.interact("Rub")) { Sleep.sleep(1000, 1500); / Widget chooseSkillWidget = Widgets.getWidget(240); if (chooseSkillWidget != null && chooseSkillWidget.isVisible()){ Integer childId = SKILL_WIDGETID_MAP.get(skill); if (childId == null) { Logger.error("Unknown Child Widget id for Skill " + skill.toString()); return; } WidgetChild wig = Widgets.getChildWidget(240, childId); WidgetChild widg = Widgets.getChildWidget(240, 26); if (wig != null && wig.isVisible()) { if (wig.interact()) { Sleep.sleep(500,1200); widg.interact(); } } else { Widgets.closeAll(); } } } }
abouhanafy87 6 Author Posted March 22, 2023 20 hours ago, hashbang said: Nice first attempt. There is a huge amount of repeated code in there, each case of the switch statement is basically the same code. One way you could simplify this is by storing a map of Skills & their corresponding WidgetChild Ids, then you can grab the child widget id as a variable and pass it into the widget interaction block. static Map<Skill, Integer> SKILL_WIDGETID_MAP = new HashMap<>(){{ put(Skill.ATTACK, 2); put(Skill.STRENGTH, 3); put(Skill.RANGED, 4); //TODO: Add all other skills here }}; public void SolveGeniLamp(Skill skill) { Item item = Inventory.get(it-> it.getName().equals("Lamp") && it.hasAction("Rub")); if (item == null) { return; // Return early, nothing to do. } if (item.interact("Rub")) { Sleep.sleep(1000, 1500); / Widget chooseSkillWidget = Widgets.getWidget(240); if (chooseSkillWidget != null && chooseSkillWidget.isVisible()){ Integer childId = SKILL_WIDGETID_MAP.get(skill); if (childId == null) { Logger.error("Unknown Child Widget id for Skill " + skill.toString()); return; } WidgetChild wig = Widgets.getChildWidget(240, childId); WidgetChild widg = Widgets.getChildWidget(240, 26); if (wig != null && wig.isVisible()) { if (wig.interact()) { Sleep.sleep(500,1200); widg.interact(); } } else { Widgets.closeAll(); } } } } good job man 👏
Recommended Posts
Archived
This topic is now archived and is closed to further replies.