Viston Posted August 7, 2017 Share Posted August 7, 2017 (edited) So I'm getting this error thrown whenever the script detects more than 1 player near me. This doesn't happen if it detects 1 player > [ERROR][Bot #1][08/07 03:50:59 AM]: Error in script executor! java.lang.NumberFormatException: For input string: "-----" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at org.osbot.rs07.api.Map.getWildernessLevel(dn:80) at vAlert.onLoop(vAlert.java:37) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(un:19) at java.lang.Thread.run(Unknown Source) Never seen that before, I did some research, I found this is a common issue when parsing integers. However, I'm not parsing anything. Code: Spoiler @Override public int onLoop() throws InterruptedException { for (Player p : getPlayers().getAll()) { int wildernessLevel = getMap().getWildernessLevel(); if (whenVisible && wildernessLevel >= 1) { if (p != myPlayer() && p.exists()) { log("===================================================================="); log("DANGER! Logging Out >" + " " + "Name:" + " " + p.getName() + " " + "-" + " " + "Combat:" + " " + p.getCombatLevel()); log("===================================================================="); logoutTab.logOut(); } } else if (whenAttackable && wildernessLevel >= 1) { if (p != myPlayer() && p.exists()) { int enemyCombatPosi = p.getCombatLevel() + wildernessLevel; int enemyCombatNeg = p.getCombatLevel() - wildernessLevel; if (enemyCombatPosi >= myPlayer().getCombatLevel() && enemyCombatNeg <= myPlayer().getCombatLevel()) { log("===================================================================="); log("DANGER! Logging Out >" + " " + "Name:" + " " + p.getName() + " " + "-" + " " + "Combat:" + " " + p.getCombatLevel()); log("===================================================================="); logoutTab.logOut(); } } } } return 100; } The issue is coming from getWildernessLevel() which is weird, but meh. Edited August 7, 2017 by Visty Quote Link to comment Share on other sites More sharing options...
Chris Posted August 7, 2017 Share Posted August 7, 2017 p != null !p.equals(myPlayer()) Quote Link to comment Share on other sites More sharing options...
Viston Posted August 7, 2017 Author Share Posted August 7, 2017 3 minutes ago, Chris said: p != null !p.equals(myPlayer()) Same error Quote Link to comment Share on other sites More sharing options...
Chris Posted August 7, 2017 Share Posted August 7, 2017 getWildernessLevel() is 0 when not in wilderness Quote Link to comment Share on other sites More sharing options...
Viston Posted August 7, 2017 Author Share Posted August 7, 2017 2 minutes ago, Chris said: getWildernessLevel() is 0 when not in wilderness Yeah. The if statements only executes when inside the wilderness anyways Quote Link to comment Share on other sites More sharing options...
Chris Posted August 7, 2017 Share Posted August 7, 2017 where dis vAlert.java:37) Quote Link to comment Share on other sites More sharing options...
Viston Posted August 7, 2017 Author Share Posted August 7, 2017 1 minute ago, Chris said: where dis vAlert.java:37) int wildernessLevel = getMap().getWildernessLevel(); Quote Link to comment Share on other sites More sharing options...
Team Cape Posted August 7, 2017 Share Posted August 7, 2017 (edited) 16 minutes ago, Visty said: int wildernessLevel = getMap().getWildernessLevel(); Firstly, fix the two errors that Chris stated above, but it's likely that the actual method has an issue. Secondly, grab your wildy level outside of the loop (no need to repeatedly call it when chances are that your wildy level will not change in the span of < 50ms). Thirdly, I would recommend making this into a method like shouldLogOut(), instead of having your log outs inside of a loop like that. Fourthly, it should be easy to remake that method if it's giving you problems (issue a bug report though, is my recommendation). Check if the widget displaying the wilderness level is there, and if it is and it's visible, that means that you're in the wilderness (so otherwise return 0). From there, parse the text from the widget and you'll get the wildy level Edited August 7, 2017 by Imateamcape 2 Quote Link to comment Share on other sites More sharing options...
liverare Posted August 7, 2017 Share Posted August 7, 2017 I wrote a Wilderness API a very long time ago. I'll re-write it at some point, but until then, here: /** * Calculate Y coordinate by wilderness level. * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param wildernessLevel * - Wilderness level * @param upperBound * - Upper-most tile for that Wilderness level * @return Y coordinate * @see {@link WildernessAPI#calculateYCoordinate(int, boolean)} */ public static int calculateYCoordinate(Vector3D vector3d, boolean upperBound) { return calculateYCoordinate(vector3d.getY(), upperBound); } /** * Calculate Y coordinate by wilderness level. * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param vector3d * - 3D vector * @param upperBound * - Upper-most tile for that Wilderness level * @return Y coordinate */ public static int calculateYCoordinate(int wildernessLevel, boolean upperBound) { int yCoordinate; if (wildernessLevel <= 0) { yCoordinate = 3524; } else if (wildernessLevel <= 1) { yCoordinate = 3527; } else if (wildernessLevel <= 2) { yCoordinate = 3535; } else { wildernessLevel -= 3; yCoordinate = 3535; yCoordinate += (wildernessLevel * 8); if (upperBound) { yCoordinate += 8; } else { yCoordinate++; } } return yCoordinate; } /** * Calculates Wilderness level by Y coordinate * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param vector3d * - 3D vector * @return Wilderness level * @see {@link WildernessAPI#calculateWildernessLevel(int)} */ public static int calculateWildernessLevel(Vector3D vector3d) { return calculateWildernessLevel(vector3d.getY()); } /** * Calculates Wilderness level by Y coordinate * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param yCoordinate * - Y coordinate * @return Wilderness level */ public static int calculateWildernessLevel(int yCoordinate) { int wildernessLevel; if (yCoordinate <= 3524) { // not in wilderness wildernessLevel = 0; } else if (yCoordinate <= 3527) { // Level 1 wilderness wildernessLevel = 1; } else if (yCoordinate <= 3535) { // Level 2 wilderness wildernessLevel = 2; } else { wildernessLevel = (yCoordinate - 3535); wildernessLevel = (int) Math.ceil(wildernessLevel / 8D); wildernessLevel += 2; // can't remember why... } return wildernessLevel; } With this, you can begin to assess stuff like: What level must I be in before player X can attack me? Who can I attack? Where's the nearest/furthest safe Y coordinate? etc. I sprung up quite a beefy API around this, it could do all kinds of checks. Quote Link to comment Share on other sites More sharing options...