jasiv 1 Posted July 15, 2021 Hi all, I started scripting following alot of guides on this website. I am working on a bot that will start from 0 and trains it's way up all by itself. The problem I am having is I am trying to use this piece of script on multiple nodes I use. I tried putting all the "data" in a separate file/class and tried too acces that "data" from every class that needs it. But it will only update after I restart my bot. My question is can I change my code so I would be able to acces it (updated) from all my nodes. public static int defSkill = Skills.getRealLevel(Skill.DEFENCE); public static String getNameOfLegs(){ if(defSkill < 5){ return "Bronze platelegs"; }else if(defSkill < 20){ return "Steel platelegs"; }else if(defSkill < 30){ return "Mithril platelegs"; }else if(defSkill < 40){ return "Adamant platelegs"; } return "Rune platelegs"; } I would use this to define what legs my bot needs at the current level. But I would reference it from for example my "equip gear node", "buy from GE node" and "withdrawel from bank". Sorry if it's a stupid question, I started coding about a week ago. Thanks in advance
TheCloakdOne 389 Posted July 15, 2021 you could create a "Utils" class that you keep all your common static methods in and reference it from there. To make sure its always giving you the correct info make sure you re-call getting the level so it updates as soon as you level up: class Utils { public static String getNameOfLegs(){ int defSkill = Skills.getRealLevel(Skill.DEFENCE); //Call it here so its allways refreshed if(defSkill < 5){ return "Bronze platelegs"; }else if(defSkill < 20){ return "Steel platelegs"; }else if(defSkill < 30){ return "Mithril platelegs"; }else if(defSkill < 40){ return "Adamant platelegs"; } return "Rune platelegs"; } } Then you can call from wherever (remember to import Utils class): class TaskNode { public void main() { Utils.getNameOfLegs(); } }
jasiv 1 Author Posted July 15, 2021 @TheCloakdOne Thank you very much going to look into that! Will update if I get it working! Works like a charm thanks again!
jasiv 1 Author Posted July 15, 2021 @TheCloakdOne I've got one more question if I may, I am switching combat styles using a snippet I found here but I do it based on the same way I do the "armor selection" would there be a better way to script it instead of making 2 different integers and a string? I have to change my code 3x now if I want to tweak something. I do it like this now : @Override public int onLoop(MethodContext context) { if (PlayerSettings.getConfig(43) != getCombatStyleConfigId()) { changeCombatStyle(43, getCombatStyle(), getCombatStyleString()); } return Calculations.random(1200, 3000); } //Change Combat style public static boolean changeCombatStyle(int config, int childID, String style) { WidgetChild accurateWidget = Widgets.getWidget(593).getChild(childID); if (PlayerSettings.getConfig(43) != config) { MethodContext.log("Switching to: " + style + " | Config: " + config); if (Tabs.isOpen(Tab.COMBAT)) { sleep(500, 800); return accurateWidget.interact() ? Tabs.openWithFKey(Tab.INVENTORY) : Tabs.openWithFKey(Tab.COMBAT); } else { Tabs.openWithFKey(Tab.COMBAT); } } return false; } //Output String attack style. public String getCombatStyleString() { if (Skills.getRealLevel(Skill.STRENGTH) < minStrLevel || (Skills.getRealLevel(Skill.STRENGTH) < (averageLevel + 6))) { return "Slash"; } else if (Skills.getRealLevel(Skill.ATTACK) < (averageLevel -1)) { return "Chop"; } else if (Skills.getRealLevel(Skill.DEFENCE) < (averageLevel +1)) { return "Block"; } return "Slash"; } //Output config value widget. public int getCombatStyle() { if (Skills.getRealLevel(Skill.STRENGTH) < minStrLevel || (Skills.getRealLevel(Skill.STRENGTH) < (averageLevel + 6))) { return 8; } else if (Skills.getRealLevel(Skill.ATTACK) < (averageLevel -1)) { return 4; } else if (Skills.getRealLevel(Skill.DEFENCE) < (averageLevel +1)) { return 16; } return 8; } //Output configID current attack mode. public int getCombatStyleConfigId() { if (Skills.getRealLevel(Skill.STRENGTH) < minStrLevel || (Skills.getRealLevel(Skill.STRENGTH) < (averageLevel + 6))) { return 1; } else if (Skills.getRealLevel(Skill.ATTACK) < (averageLevel -1)) { return 0; } else if (Skills.getRealLevel(Skill.DEFENCE) < (averageLevel +1)) { return 3; } return 1; } }
Bonfire 334 Posted July 15, 2021 39 minutes ago, jasiv said: ... I can't speak to how you should implement your combat style code, but I think you'll be very happy to know that within the "Combat" class there exists a "Combat.getCombatStyle()" method and a "Combat.setCombatStyle()" method
jasiv 1 Author Posted July 15, 2021 @BonfireThank you that will help alot, see that's the lack of experience I got in my one week of coding !
Recommended Posts
Archived
This topic is now archived and is closed to further replies.