ikespiv 1 Posted May 8, 2023 Tried to make a script that combines alching, chopping and burning wood, but can't figure out how to do firemaking right. Also I need to add automatic price checking/adjusting for buying new items to alch. I'm very new to scripting, so sorry if this is stupid lol public static final Area GE = new Area(3162, 3487, 3167, 3485); private final Timer t = new Timer(); private final Player PLAYER = Players.getLocal(); Tile playerTile = Players.getLocal().getTile(); String treeName = "Tree"; String logsName = "Logs"; Condition animatingCondition = () -> !PLAYER.isAnimating(); public enum State { WOODCUTTING, FIREMAKING, BANK, ALCH, RETURN, MOVE } private State getState() { if (Inventory.contains(logsName) && (GameObjects.getTopObjectOnTile(playerTile) != null)) { return State.MOVE; } if(Inventory.contains(logsName) && (GameObjects.getTopObjectOnTile(playerTile) == null)) { return State.FIREMAKING; } else if (Inventory.contains("Green d'hide body") || Inventory.contains("Adamant platebody") && Inventory.contains("Nature rune")) { return State.ALCH; } else if (GrandExchange.isReadyToCollect() && !GE.contains(Players.getLocal())) { return State.RETURN; } else if (GrandExchange.isReadyToCollect() && GE.contains(Players.getLocal())) { return State.BANK; } else { return State.WOODCUTTING; } } private State state = null; @Override public int onLoop() { if (!Client.isLoggedIn()) { return 600; } if (!Walking.isRunEnabled() && Walking.getRunEnergy() > Calculations.random(30, 70)) { Walking.toggleRun(); } state = getState(); switch (state) { case RETURN: { Walking.walk(GE.getRandomTile()); } break; case WOODCUTTING: if (PLAYER.isAnimating()) { sleepUntil(animatingCondition, 60000L, 1000L); } else while (!PLAYER.isMoving() && !PLAYER.isAnimating() && !Inventory.isFull()) { GameObject tree = GameObjects.closest(treeName); tree.interact("Chop down"); sleepUntil(animatingCondition, 60000L, 1000L); } if (Inventory.isFull()) { state = State.FIREMAKING; } break; case MOVE: int playerX = Players.getLocal().getLocalX(); int playerY = Players.getLocal().getLocalY(); Tile nextTileRight = new Tile(playerX + 1, playerY); Tile nextTileLeft = new Tile(playerX - 1, playerY); Tile nextTileTop = new Tile(playerX, playerY + 1); Tile nextTileBottom = new Tile(playerX, playerY - 1); Tile nextTileRightTop = new Tile(playerX + 1, playerY + 1); Tile nextTileRightBottom = new Tile(playerX + 1, playerY - 1); Tile nextTileLeftTop = new Tile(playerX - 1, playerY + 1); Tile nextTileLeftBottom = new Tile(playerX - 1, playerY - 1); if ((Walking.canWalk(nextTileRight)) && (GameObjects.getTopObjectOnTile(nextTileRight) == null)) { Walking.walk(nextTileRight); } else if ((Walking.canWalk(nextTileLeft)) && (GameObjects.getTopObjectOnTile(nextTileLeft) == null)) { Walking.walk(nextTileLeft); } else if ((Walking.canWalk(nextTileTop)) && (GameObjects.getTopObjectOnTile(nextTileTop) == null)) { Walking.walk(nextTileTop); } else if ((Walking.canWalk(nextTileBottom)) && (GameObjects.getTopObjectOnTile(nextTileBottom) == null)) { Walking.walk(nextTileBottom); } else if ((Walking.canWalk(nextTileRightTop)) && (GameObjects.getTopObjectOnTile(nextTileRightTop) == null)) { Walking.walk(nextTileRightTop); } else if ((Walking.canWalk(nextTileRightBottom)) && (GameObjects.getTopObjectOnTile(nextTileRightBottom) == null)) { Walking.walk(nextTileRightBottom); } else if ((Walking.canWalk(nextTileLeftTop)) && (GameObjects.getTopObjectOnTile(nextTileLeftTop) == null)) { Walking.walk(nextTileLeftTop); } else if ((Walking.canWalk(nextTileLeftBottom)) && (GameObjects.getTopObjectOnTile(nextTileLeftBottom) == null)) { Walking.walk(nextTileLeftBottom); } sleep(3000); state = State.FIREMAKING; break; case FIREMAKING: { Inventory.get("Tinderbox").useOn(logsName); sleepUntil(animatingCondition, 60000L, 3000L); } if(GameObjects.getTopObjectOnTile(playerTile) != null) state = State.MOVE; break; case BANK: if (GrandExchange.isReadyToCollect() || !Inventory.contains("Nature rune")) { GrandExchange.open(); sleep(1000); } if (GrandExchange.isOpen()) { GrandExchange.collect(); sleep(500L, 1223L); } if (!Inventory.contains("Nature rune")) { GrandExchange.buyItem("Nature rune", 1000, 93); sleep(2000); GrandExchange.confirm(); sleep(4000); } if (Inventory.contains("Nature rune") && !Inventory.contains("Green d'hide body")) { GrandExchange.buyItem("Green d'hide body", 300, 4340); sleep(2000); GrandExchange.confirm(); sleep(4000); } if (Inventory.contains("Nature rune") && !Inventory.contains("Adamant platebody")) { GrandExchange.buyItem("Adamant platebody", 300, 9550); GrandExchange.confirm(); sleep(4000); GrandExchange.collect(); sleep(2000); } GrandExchange.close(); sleep(200); break; case ALCH: while (Inventory.contains("Green d'hide body")) { Inventory.getRandom("Green d'hide body"); sleep(1000); Magic.castSpellOn(Normal.HIGH_LEVEL_ALCHEMY, Inventory.getRandom("Green d'hide body")); sleep(2000); } while (Inventory.contains("Adamant platebody")) { Inventory.getRandom("Adamant platebody"); sleep(1000); Magic.castSpellOn(Normal.HIGH_LEVEL_ALCHEMY, Inventory.getRandom("Adamant platebody")); sleep(2000); } break; } return Calculations.random(300, 600); } public void onPaint(Graphics g) { g.setColor(Color.WHITE); g.setFont(new Font("Arial", Font.BOLD, 11)); g.drawString("Time Running: " + t.formatTime(), 25, 50); if (state != null) g.drawString("State: " + state, 25, 95); } }
Diggington 20 Posted May 9, 2023 I'd recommend splitting your scripts up if you're learning rather than trying to do too much at once. What exactly is the problem you're having?
ikespiv 1 Author Posted May 9, 2023 (edited) 15 hours ago, Diggington said: I'd recommend splitting your scripts up if you're learning rather than trying to do too much at once. What exactly is the problem you're having? Hey, thanks for the response, I'm a big fan of your cow killer script! It would probably help if i just made a basic firemaking script seperately, but I have been seeing a lot of scripts with packages containing multiple files that work together too. Not sure exactly how that works since I'm a noob, but would love to find out if you know what I'm talking about. Other than that, the main issue was that it would get stuck trying to make fire when standing on top of an already lit fire. Now I've deleted the MOVE state and just used this for the FIREMAKING state, and it walks to a random tile in my area, but immediately goes to light a fire while running around. So it stops randomly in it's path and scatters fires about. Looks like this: (also i tried adding !PLAYER.isMoving() to the animating condition but doesn't seem to be working, since it's still deciding to light fire in the middle of running around. if(GameObjects.getTopObjectOnTile(playerTile) != null) { Walking.walk(GE.getRandomTile()); sleepUntil(animatingCondition, 60000L, 1000L); Inventory.get("Tinderbox").useOn(logsName); sleep(1000); sleepUntil(animatingCondition, 60000L, 1000L); sleep(2000); I'm also wondering, does isReadyToCollect only work if the transaction went through while you're logged in? And does it have to be open for getOpenSlots to work? My BANK state sort of works, but I want to add more functionality incase there's no order already placed to buy more items. Edited May 9, 2023 by ikespiv
Diggington 20 Posted May 10, 2023 4 hours ago, ikespiv said: Hey, thanks for the response, I'm a big fan of your cow killer script! Cool, thanks man 4 hours ago, ikespiv said: It would probably help if i just made a basic firemaking script seperately, but I have been seeing a lot of scripts with packages containing multiple files that work together too. Not sure exactly how that works since I'm a noob, but would love to find out if you know what I'm talking about. It sounds like you're talking about something like the AIO scripts that are floating around - there's definitely ways to do this (like using the Tree/Leaf framework) but I'd recommend doing one at a time while you're learning. You need to crawl before you can run. Split your scripts into a woodcutter/firemaker, alcher, and item buyer at first. Then once they're all working individually, you can look at consolodating them. 4 hours ago, ikespiv said: Other than that, the main issue was that it would get stuck trying to make fire when standing on top of an already lit fire. Now I've deleted the MOVE state and just used this for the FIREMAKING state, and it walks to a random tile in my area, but immediately goes to light a fire while running around. So it stops randomly in it's path and scatters fires about. Looks like this: (also i tried adding !PLAYER.isMoving() to the animating condition but doesn't seem to be working, since it's still deciding to light fire in the middle of running around. if(GameObjects.getTopObjectOnTile(playerTile) != null) { Walking.walk(GE.getRandomTile()); sleepUntil(animatingCondition, 60000L, 1000L); Inventory.get("Tinderbox").useOn(logsName); sleep(1000); sleepUntil(animatingCondition, 60000L, 1000L); sleep(2000); I think your problem here is the definition of animatingCondition. Looking at your code above it's defined at the Class level (outside any methods) which means it will be set as soon as the call to the class is made (i.e when the script starts running) and the value of it never gets updated. So the condition is likely always true. I'd recommend calling in dynamically rather than using a static value. For example Sleep.sleepUntil(() -> !Player.isAnimating, Calculations.random(6000,10000)) It's also good practice to randomize any sleeps you use in your code. Here's the code I use for lighting fires if you want to take it. It's not very elegant when it comes to movement, but 80% of the time it works every time void LightLogs(){ Player player = Players.getLocal(); if (Inventory.contains("Logs") && Inventory.contains("Tinderbox")){ if (!IsFireUnderPlayer()){ if (!IsObjectUnderPlayer()){ Inventory.get("Tinderbox").useOn("Logs"); Sleep.sleepUntil(() -> !player.isAnimating(), Calculations.random(7000,9000)); } else{ Tile tile = new Tile(player.getX() + 1, player.getY()); int flag = Map.getFlag(tile); if (CollisionMap.isBlocked(flag)) { tile = new Tile(player.getX(), player.getY() + 1); } Walking.walkOnScreen(tile); } } else{ Tile tile = new Tile(player.getX() + 1, player.getY()); int flag = Map.getFlag(tile); if (CollisionMap.isBlocked(flag)) { tile = new Tile(player.getX(), player.getY() + 1); } Walking.walkOnScreen(tile); } } } Boolean IsFireUnderPlayer(){ GameObject fire = GameObjects.closest("Fire"); if (fire != null){ return fire.getTile().equals(Players.getLocal().getTile()); } else{ return false; } } Boolean IsObjectUnderPlayer(){ if (GameObjects.getTopObjectOnTile(Players.getLocal().getTile()) != null){ if (GameObjects.getTopObjectOnTile(Players.getLocal().getTile()).getName().equals("null")){ return false; } else{ return true; } } else{ return false; } } 4 hours ago, ikespiv said: I'm also wondering, does isReadyToCollect only work if the transaction went through while you're logged in? And does it have to be open for getOpenSlots to work? My BANK state sort of works, but I want to add more functionality incase there's no order already placed to buy more items. I don't know, I don't really use the GE functions that much
ikespiv 1 Author Posted May 10, 2023 @Diggington Hell yeah, this is great. Thanks for your help! Diggington 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now