liverare Posted October 11, 2017 Share Posted October 11, 2017 (edited) 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! Edited October 12, 2017 by liverare 7 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted October 12, 2017 Share Posted October 12, 2017 Awesome work ! love all your work as of late, so many useful snippets Quote Link to comment Share on other sites More sharing options...
Chris Posted October 12, 2017 Share Posted October 12, 2017 have my fucking children thanks cutie Quote Link to comment Share on other sites More sharing options...
Super Posted October 12, 2017 Share Posted October 12, 2017 Spoiler liverare aka the snippet god Quote Link to comment Share on other sites More sharing options...
sp3cpk Posted October 12, 2017 Share Posted October 12, 2017 I appreciate the contribution of all your snippets! Learning a lot Keep it up Quote Link to comment Share on other sites More sharing options...