Jump to content

liverare

Scripter II
  • Posts

    1300
  • Joined

  • Last visited

  • Days Won

    3
  • Feedback

    0%

Everything posted by liverare

  1. This was rushed a little and it's nearly 2am, so I've probably naffed a few things up, or there may be room for much greater improvement. I might continue working on it tomorrow. The main foundation for the stuff is there, and I need to fix my crafting script sometimes soon. But I'd like for there to be an official API first.
  2. I blinked, then.. Version 2 Example code: public class Test extends Script { AmountAPI amount; RS2Widget vambracesButton; RS2Widget chapsButton; RS2Widget bodyButton; RS2Widget superCombatButton; @Override public void onStart() throws InterruptedException { amount = new AmountAPI(); amount.exchangeContext(bot); amount.initializeModule(); } @Override public int onLoop() throws InterruptedException { if (amount.isValid()) { vambracesButton = amount.getButton("Green d'hide vamb"); chapsButton = amount.getButton("Green d'hide chaps"); bodyButton = amount.getButton("Green d'hide body"); superCombatButton = amount.getButton("Super combat potion(4)"); } else { // open the interface... } return 250; } } Functions: public Map<ItemDefinition, RS2Widget> getItemButtons() public RS2Widget getButton(int... itemIds) public RS2Widget getButton(int itemId) public RS2Widget getButton(String... itemNames) public RS2Widget getButton(String itemName) public RS2Widget getButton(Predicate<ItemDefinition> itemDefinitionFilter) public RS2Widget getButton(ItemDefinition itemDefinition) public boolean isVisible() public boolean isValid() private Map<ItemDefinition, RS2Widget> findItemButtons() private boolean isRootOf(RS2Widget widget) private RS2Widget findAmountWidget() private static ItemDefinition getItem(RS2Widget parent) private static int getItemId(RS2Widget parent) private static RS2Widget getItemIdWidget(RS2Widget parent) private static boolean isItemIdValid(RS2Widget child) private static boolean isWidgetMakeAction(RS2Widget child) Source: V1 Source
  3. Computers do stuff very quick like. Before you can blink, the computer's already spun around in circles 1000s of times. You gotta tell your computer to slow down, brah.
  4. I've expanded upon my CLI Support Made Easy to build a fully functional file reader/writer for each script. So assume you're launching a fighting script with the following CLI: -script Fighter:scrub.ini.noob.ini.body.green-d'hide-body.legs.green-d'hide-chaps That'll get converted to: scrub.ini -to- OSBot/data/Fighter/scrub.ini noob.ini -to- OSBot/data/Fighter/noob.ini body:green d'hide body legs:green d'hide chaps Also, there'll be a OSBot/data/Fighter/default.ini created too. The default.ini file is where you specify parameters you want to share for every bot. These files will be created automatically (if they're not already present) and loaded: Anything that you put in the CLI that isn't a .ini file, those will be added (and override) all the key/values plucked from the files. This is similar to when you add inline CSS to HTML elements and how that potentially overrides the CSS loaded in from .css files. Example script code: @ScriptManifest(author = "", info = "", logo = "", name = "Fighter", version = 0) public class CLITest extends Script { NPC npc; ScriptFile scriptFile; Properties cli; @Override public void onStart() throws InterruptedException { String parameters = getParameters(); try { if (parameters != null && !parameters.isEmpty()) { scriptFile = ScriptFile.compileAndCollateScriptIniFiles(getName(), getVersion(), getParameters()); cli = scriptFile.getProperties(); } } catch (IOException e) { e.printStackTrace(); } } @Override public int onLoop() throws InterruptedException { npc = npcs.closest(cli.getProperty("target", "Guard")); return 250; } } So let's say we had noob.ini and we wanted to target a tramp The script will then use that But let's say you didn't specify "target", probably because you misspelled it The CLI parameter "target" isn't specified, so the script will look for a guard instead Source code:
  5. I like it! I've updated the main post with it. However, I've tweeked it a slight bit for my use.
  6. I do like yours too, however, what I dislike is the forced rounding (which happens as a result of the format), how your forced to two decimal places even when that remaining digit is a "0" (such as 5.40M), and (as a personal preference), when denoting values, I like to have at least one decimal value even if that value's "0", because it signifies that the number's not a 100% accurate reflection of the actual number.
  7. Your's does exactly what I need it to do (and no doubt more efficient as you're not splitting strings). However, you're damn right mine's more readable. I'm stealing your code. >:) I'm going to reformat it so I can actually comprehend in full what's actually happening, then I'm replacing my method with yours. (will credit where due). :edit: I found just one flaw: you round up your number. So in a test case, if 17,965,432 was used, I'd get 17.96M whereas you would get 18.00M. But I've figured out how to solve that and have modified the original thread with your code that I've modified.
  8. Test case: logger.debug(formatRSUnit(559546000000l)); // 559.54B logger.debug(formatRSUnit(19546000000l)); // 19.54B logger.debug(formatRSUnit(1954600000l)); // 1.95B logger.debug(formatRSUnit(155400000l)); // 155.4M logger.debug(formatRSUnit(70000000l)); // 70.0M logger.debug(formatRSUnit(5400000l)); // 5.40M logger.debug(formatRSUnit(450000l)); // 450.0K logger.debug(formatRSUnit(12000l)); // 12.0K logger.debug(formatRSUnit(8000l)); // 8.0K logger.debug(formatRSUnit(600l)); // 600 logger.debug(formatRSUnit(50l)); // 50 logger.debug(formatRSUnit(2l)); // 2 Source code: private static final DecimalFormat UNIT_FORMAT = new DecimalFormat(".0#"); /** * @author Explv (https://osbot.org/forum/profile/192661-explv/) * @author LiveRare (https://osbot.org/forum/profile/23977-liverare/) * * @param value * - An amount * @return Formatted RS unit */ public static String formatRSUnit(final long value) { String suffix; double convertedValue; if (value >= 1_000_000_000) { convertedValue = ((double) value / 1_000_000_000); suffix = "B"; } else if (value >= 1_000_000) { convertedValue = ((double) value / 1_000_000); suffix = "M"; } else if (value >= 1000) { convertedValue = ((double) value / 1000); suffix = "K"; } else { return String.valueOf(value); } convertedValue = Math.floor(convertedValue * 100) / 100; return UNIT_FORMAT.format(convertedValue) + suffix; } I think I've over-complicated something here. If I have, please tell me how.
  9. Sure if your script finds what best tier axe you can use and then just assumes you have it. Because otherwise, you'll need a few more lines to find the best of the axes you have available to you.
  10. You haven't made a mistake, but you have massively over-complicated such a simple procedure. Understand your audience, because @mbuzz13 will likely use your code not understanding how or why it's doing what it does, especially the Lambda stuff. Also, you've got a whole lot of post-processing happening at run time, such as your getTier and getName methods. This stuff should already be compiled and available in the memory. I've modified your code: public enum Axe implements Filter<Item> { BRONZE("Bronze axe", 1), IRON("Iron axe", 1), RUNE("Rune axe", 41); private final String name; private final int level; Axe(String name, int level) { this.name = name; this.level = level; } @Override public String toString() { return name; } public int getLevel() { return level; } @Override public boolean match(Item item) { return item.getName().equals(name); } public static Axe valueOf(Item item) { Axe axe = null; for (Axe next : values()) { if (next.match(item)) { axe = next; break; } } return axe; } } The only fancy function here is the implementation of the Filter<Item> and the static method valueOf(Item). You'll see why.. private static int sortByTier(Item item1, Item item2) { Axe axe1 = Axe.valueOf(item1); Axe axe2 = Axe.valueOf(item2); return axe2.compareTo(axe1); // reverse order (best to worst) } This is just a way for us to order the items. Notice how we're using Axe.valueOf(Item). Then you can chose to either use or not use Lambda to find the best item (that is an axe): private static Item getBestAxeUsingLambda(ItemContainer itemContainer) { return itemContainer.filter(Axe.values()) .stream() .sorted(Test::sortByTier) .findFirst() .orElse(null); } private static Item getBestAxe(ItemContainer itemContainer) { Item bestAxe = null; List<Item> axes = itemContainer.filter(Axe.values()); // Axe implements Filter<Item> if (axes != null && !axes.isEmpty()) { axes.sort(Test::sortByTier); bestAxe = axes.get(0); } return bestAxe; } Then you can get the best axes: @Override public int onLoop() throws InterruptedException { Item bestAxeInTheBank = getBestAxe(bank); Item bestAxeInTheInventory = getBestAxe(inventory); Item bestAxeEquipped = getBestAxe(equipment); return 0; } However, you'll need to compare and contrast the best axes found to figure out which of them is truly the best.
  11. Because that is a variable. If you set a variable, it'll never be updated unless you set it again. That's why we have functions.
  12. Bigger scripts have bigger moving parts, which can be broken down into APIs and additional classes. The loop function should only contain a series of checks and calls, like I've demonstrated, so anyone can easily analyse what the script does and where problems are likely occurring.
  13. Whoever keeps telling new scripters to use states - stop it. You've made this new guy's script so fucking unreadable and overly complicated that I would be aghast if he can even get it to work. States are horrible! Stop using them! Here's what I can do without states; compare for yourself: String status = "Ready" Position cowTile = new Position(3259, 3269, 0); NPC banker; NPC cow; @Override public void onLoop() throws InterruptedException { if (shouldGoToBank()) { goToBank(); } else if (shouldWithdrawFood()) { withdrawFood(); } else if (shouldGoToCows()) { goToCows(); } else if (shouldKillCows()) { killCows(); } } private boolean shouldGoBank() { return inventory.isEmpty(); } private void goToBank() { status = "Going to the bank"; getWalking().webWalk(Banks.LUMBRIDGE_UPPER); } private boolean shouldWithdrawFood() { return Banks.LUMBRIDGE_UPPER.contains(myPosition()); } private void withdrawFood() { status = "Withdrawing food"; banker = npcs.closest("Banker"); if (banker != null && banker.interact("Bank")) { // now sleep until the bank interface opens // hint: https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html } } private boolean shouldGoToCows() { return inventory.isFull(); } private void goToCows() { status = "Going to the cows"; getWalking().walk(cowTile); } private boolean shouldKillCows() { return inventory.contains("Salmon"); } private void killCows() { status = "Killing cows"; cow = npcs.closest("Cow"); // better filtering needed - you might attack a cow someone else is already attacking, or you might be fighting a cow and attempt to attack another cow in non-multi zone if (cow != null && cow.interact("Attack")) { // now sleep until you've killed the cow or are running low on health // hint: https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html } }
  14. I can't be of much help without seeing the entire script.
  15. Here's a quick way to get key/value pairs from your CLI parameters. We can take: -script TestScript:body.green-d'hide-body.legs.preists-robes.location.varrock.mode.attack And convert it to: BODY:green d'hide body LEGS:priests robes LOCATION:varrock MODE:attack You're probably wondering 'why are the keys uppercase?', well that's to signify what the bot thinks are keys. A little debugging and you'll be able to see what your bot sees. The full-stop "." is our delimiter, and the hyphen "-" is our replacement for the space " " key. Example code + template: public class Test extends Script { Map<String, String> parameters; String mode; @Override public void onStart() throws InterruptedException { compileParameters(); mode = parameters.get("mode"); } @Override public int onLoop() throws InterruptedException { // log out the parameters for debugging purposes logger.debug(parameters); // use parameters if (mode != null && !mode.isEmpty()) { if (mode.equals("attack")) { // TODO - attack something } } return 1000; } /** * Compiles OSBot parameters into key/value pairs */ private void compileParameters() { String rawParameterString = getParameters(); String[] contents; String key; String value; parameters = new HashMap<>(); if (rawParameterString != null && !rawParameterString.isEmpty()) { logger.debug(rawParameterString); contents = rawParameterString.split("\\."); if (contents != null && contents.length > 0) { for (int i = 0; i < contents.length; i += 2) { key = contents[i]; key = key.toUpperCase(); value = (i + 1 < contents.length ? contents[i + 1] : ""); value = value.replaceAll("-", " "); parameters.put(key, value); } } } } } Have fun!
  16. There's your problem, the switch case isn't being reached. If you need help then you'll need to post us more of the code, namely the bit of code that decides the switch case.
  17. I did have a guide on how to set up Eclipse, but I can't find it. I'll probably write another up later.
  18. Doeth thou use environment variablaroos?
  19. If you're looking to find the closest bank and keep a reference to it, then you could definitely trim down your code bigly: /** * * @return Closest WebBank */ public WebBank getClosest() { return Stream.of(WebBank.values()) .sorted(this::sortByDistance) .findFirst() .orElse(null); } /** * Calculate distance to WebBank * * @param webBank * - WebWalk object * @return Distance to WebBank */ private int distance(WebBank webBank) { return webBank.area.getPositions().get(0).distance(myPlayer()); } /** * Compare distances to two WebWalks * * @param a * - first WebWalk * @param b * - second WebWalk * @return Array sort */ private int sortByDistance(WebBank a, WebBank b) { return Integer.compare(distance(a), distance(b)); } You don't need to map out distances or any of that non-sense.
  20. Well written, concise, and fit for purpose. Ideally, 10 years from now when your script eventually breaks, one of the devs (whoever that is) should be able to pick up and fix your script easily.
  21. You don't have to give up, you know. Learn to write your own scripts and build up from scratch. One of the main reasons why bots get banned is because the scripts they use are shit, and there are a bunch of other botters using that exact same shit script. In fact, this is how I got into scripting; back on another bot client before the bot nuke, I had used a shitty script even after I received a 2-day ban. I tested my luck and fell short. I also got sick and tired of there not being the kinds of scripts I wanted, or there were, but they were expensive af (and I had 0 cash at the time). If you write your own scripts, not only will you gain a new valuable skill, you will also rebuild your next account with a lower chance of getting banned, as your script will be wholly unique to you. And if you get banned once more (because I'm assuming your IP address is flagged to high hell), then you can keep making new accounts and using scripts you've already written. Call you ISP and tell them you have been threatened with DDOS attacks and that you think your internet's suffering at the worst of times and that you need a new IP address. :P
  22. liverare

    Paint API

    That's lovely! I've made two updates: The 'box' parameter in the drawEntity function will now draw a 3D wireframe box around the 'floor' and 'ceiling' tiles of an entity. I've added another drawEntity function which takes a Function<T extends Entity, String> instead of a String. This means you can render text over single entities more consistently with how you'd render text over a bunch of entities, but also, you don't have to worry about the entity being null.
  23. Calm down, this is Jagex simply doing what they can to protect accounts. If you create an account on one IP address and access it from a completely different IP address, this flags up in Jagex's system and they, out of precaution, will lock you account until you prove you are the owner. How do I know this? Because they locked mine after I logged in from a completely new address.
  24. List<RS2Object> objectsUnderCursor = getMouse().getEntitiesOnCursor() .stream() .filter(RS2Object.class::isInstance) .map(RS2Object.class::cast) .collect(Collectors.toList()); Try that.
  25. liverare

    Paint API

    I've made a minor change to the drawEntity function, because it would only render the entity on the minimap if it was also visible. Now it'll render it so long as it's on the minimap. There's one thing I dislike and that's when something will render, but it'll be stretched to the top-left of the screen because it's partially visible, like a partially visible tile. That's down to some core OSBot functions. I'll have to add in some checks to avoid rendering those later.
×
×
  • Create New...