Mephisto Posted July 31, 2019 Share Posted July 31, 2019 (edited) Hello everyone! I'm trying to make my first task based script, but am experiencing some issues with a task. I want my EquipGear task to eguip items based on the bots defence level, so everytime I run the task it will check the defence level and based on the defence level he will choose what piece/variable to pick from. This is my Task superclass: package Test.account.skills; import org.osbot.rs07.script.MethodProvider; public abstract class CombatTask { protected MethodProvider mp; public CombatTask(MethodProvider mp) { this.mp = mp; } public abstract boolean canProcess(); public abstract void process(); public void run() { if (canProcess()) process(); } } And this is my EquipGear task: package Test.account.skills; import org.osbot.rs07.api.ui.EquipmentSlot; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.utility.ConditionalSleep; public class EquipGear extends CombatTask { public EquipGear(MethodProvider mp) { super(mp); } @Override public boolean canProcess() { // If the bot isn't wearing a piece or multiple pieces of equipment -> Statement = true. if (!mp.getEquipment().isWearingItem(EquipmentSlot.AMULET, amuletGear) || !mp.getEquipment().isWearingItem(EquipmentSlot.HAT, headGear) ||!mp.getEquipment().isWearingItem(EquipmentSlot.CHEST, bodyGear) || !mp.getEquipment().isWearingItem(EquipmentSlot.LEGS, legGear) || !mp.getEquipment().isWearingItem(EquipmentSlot.SHIELD, shieldGear) || !mp.getEquipment().isWearingItem(EquipmentSlot.WEAPON, mainHandGear)); mp.log("Isn't wearing set"); return true; } @Override public void process() { setGear(); if (mp.getInventory().contains(headGear) && mp.getInventory().contains(bodyGear) && mp.getInventory().contains(legGear) && mp.getInventory().contains(amuletGear) && mp.getInventory().contains(shieldGear) && mp.getInventory().contains(mainHandGear)){ mp.log("Equiping " +headGear); mp.getInventory().interact(headGear,"Wear"); new ConditionalSleep(2500, 500) { @Override public boolean condition() throws InterruptedException { return mp.getEquipment().isWearingItem(EquipmentSlot.HAT, headGear); } }.sleep(); mp.getInventory().interact(bodyGear,"Wear"); new ConditionalSleep(2500, 500) { @Override public boolean condition() throws InterruptedException { return mp.getEquipment().isWearingItem(EquipmentSlot.CHEST, bodyGear); } }.sleep(); mp.getInventory().interact(legGear,"Wear"); new ConditionalSleep(2500, 500) { @Override public boolean condition() throws InterruptedException { return mp.getEquipment().isWearingItem(EquipmentSlot.LEGS, legGear); } }.sleep(); mp.getInventory().interact(amuletGear, "Wear"); new ConditionalSleep(2500, 500) { @Override public boolean condition() throws InterruptedException { return mp.getEquipment().isWearingItem(EquipmentSlot.AMULET, amuletGear); } }.sleep(); mp.getInventory().interact(shieldGear, "Wear"); new ConditionalSleep(2500, 500) { @Override public boolean condition() throws InterruptedException { return mp.getEquipment().isWearingItem(EquipmentSlot.SHIELD, shieldGear); } }.sleep(); mp.getInventory().interact(mainHandGear,"Wield"); new ConditionalSleep(2500, 500) { @Override public boolean condition() throws InterruptedException { return mp.getEquipment().isWearingItem(EquipmentSlot.WEAPON, mainHandGear); } }.sleep(); } } } Is there anyway I can implement something like this?: if (mp.getSkills().getStatic(Skill.DEFENCE) < 10) { String headGear = "Iron full helm"; String bodyGear = "Iron platebody"; String legGear = "Iron platelegs"; String amuletGear = "Amulet of power"; String shieldGear = "Iron kiteshield"; String mainHandGear = "Iron scimitar"; }else if (mp.getSkills().getStatic(Skill.DEFENCE)>= 10 && mp.getSkills().getStatic(Skill.DEFENCE) < 20){ String headGear = "Steel full helm"; String bodyGear = "Steel platebody"; String legGear = "Steel platelegs"; String amuletGear = "Amulet of power"; String shieldGear = "Steel kiteshield"; String mainHandGear = "Steel scimitar"; } I have tried making another class SetGear: package Test.account.skills; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.MethodProvider; public class SetGear { protected MethodProvider mp; public SetGear(MethodProvider mp) { this.mp = mp; } public void gear() { if (mp.getSkills().getStatic(Skill.DEFENCE) < 10) { String headGear = "Iron full helm"; String bodyGear = "Iron platebody"; String legGear = "Iron platelegs"; String amuletGear = "Amulet of power"; String shieldGear = "Iron kiteshield"; String mainHandGear = "Iron scimitar"; }else if (mp.getSkills().getStatic(Skill.DEFENCE)>= 10 && mp.getSkills().getStatic(Skill.DEFENCE) < 20){ String headGear = "Steel full helm"; String bodyGear = "Steel platebody"; String legGear = "Steel platelegs"; String amuletGear = "Amulet of power"; String shieldGear = "Steel kiteshield"; String mainHandGear = "Steel scimitar"; } } } And try to run it inside the EquipGear task like this: (but that didn't work). SetGear set = new SetGear(MethodProvider mp); set.gear(); Do I have to make seperate tasks for each level spectrum or can this be implemented in one task? Can anyone help me out? Thanks in advance! Btw: I'm not experienced with programming, I recently watched this course on yt: https://www.youtube.com/watch?v=8cm1x4bC610&t=148s to understand the basics and am now practicing with it. Edited July 31, 2019 by Mephisto Quote Link to comment Share on other sites More sharing options...
Apaec Posted July 31, 2019 Share Posted July 31, 2019 Hey, There are quite a few syntax issues and bad practices throughout your code. Instead of pointing them out one by one, i'd suggest falling back to the basics. There's no need to complicate your script with object orientation which you don't need, especially if you're not very confident with object oriented concepts just yet. The more scripts you write and programming you do, the more your skills will develop, and at some point you will naturally get a feel for which design patterns you need and what approach to take when structuring your scripts. If I were in your position, i'd stick with if/else statements inside your onLoop, and perhaps experiment with moving your equipment data into an enum. Don't make a mountain out of a mole hill! Good luck -Apa 1 Quote Link to comment Share on other sites More sharing options...
Mephisto Posted July 31, 2019 Author Share Posted July 31, 2019 (edited) 20 minutes ago, Apaec said: Hey, There are quite a few syntax issues and bad practices throughout your code. Instead of pointing them out one by one, i'd suggest falling back to the basics. There's no need to complicate your script with object orientation which you don't need, especially if you're not very confident with object oriented concepts just yet. The more scripts you write and programming you do, the more your skills will develop, and at some point you will naturally get a feel for which design patterns you need and what approach to take when structuring your scripts. If I were in your position, i'd stick with if/else statements inside your onLoop, and perhaps experiment with moving your equipment data into an enum. Don't make a mountain out of a mole hill! Good luck -Apa I guess you're right! I have made some simple scripts in the past and recently trying to create some bigger/longer scripts. The reason I looked into task based scripts is because I think that with tasks I can organise my script better, making it better to oversee. Making whole scripts with if & else statements inside my onLoop(); method makes it complicated to read when the scripts get bigger. (I have thrown away many scripts I made because I can't read them quickly a couple days after I made them. Though I agree with you, I guess my first step is to get my own structure/patterns to keep these scripts organised and leave task based scripts for what it is now. Thanks for replying, Mephisto Edited July 31, 2019 by Mephisto Quote Link to comment Share on other sites More sharing options...
Apaec Posted August 1, 2019 Share Posted August 1, 2019 9 hours ago, Mephisto said: I guess you're right! I have made some simple scripts in the past and recently trying to create some bigger/longer scripts. The reason I looked into task based scripts is because I think that with tasks I can organise my script better, making it better to oversee. Making whole scripts with if & else statements inside my onLoop(); method makes it complicated to read when the scripts get bigger. (I have thrown away many scripts I made because I can't read them quickly a couple days after I made them. Though I agree with you, I guess my first step is to get my own structure/patterns to keep these scripts organised and leave task based scripts for what it is now. Thanks for replying, Mephisto I'd actually contest this and say that scripts with simple if/else statements are much easier to read than those with these if/else statements in lots of other classes, wrapped in unnecessary objects. For bigger and longer scripts, you're right - you're going to need more than a single class. But using this 'task' framework that everyone is obsessed with really doesn't use object orientation for anything useful. As an example, take a look at my open source AIO Herblore script: https://github.com/apaec/aio-herblore. It supports activity queueing along with every potion, unf potion, tar making and herb cleaning, and yet it doesn't use this 'task' system. The OO design isn't perfect, I can think of a few flaws, but for the most part the OO makes it more concise and readable, in a way that wouldn't be possible with just if/else statements in the onLoop. I'd reiterate what I said before in suggesting just writing scripts with if/else statements. Eventually you will end up with a situation where you are doing something messy, or repeating yourself lots, at which point you can take the opportunity to find an OO solution to the problem Apa 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 5, 2019 Share Posted August 5, 2019 Spoiler Spoiler Spoiler jk Looking at apaec's repo is probably gonna be difficult for you. One thing i'd say is that if you wanted to make multiple classes, make use of extending rather than passing reference to method provider. The second part to that is that you have to exchangeContext() of your classes with the bot. This won't make sense until you come to actually doing it. Spoiler myClass.exchangeContext(getBot()); /* This might be the way, can't recall. myClass would derive from MyClass which inherits from MethodProvider */ Quote Link to comment Share on other sites More sharing options...