Alek Posted May 9, 2016 Share Posted May 9, 2016 Haven't seen a Castle Wars script on either here or a competitor bot. This is something I wrote up real quick; you could just AFK outside the spawn room but I added some basic logic to prevent some reports. Features: -Waits for game -Grabs bandages, finds enemies, attacks people -Leaves spawn zone, walks to high-traffic areas This is an open-source script, written so its easy to understand for some of you newer guys. If you are a VIP+ member you get the convenience of the script being on the SDN. Source: import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.api.util.GraphicUtilities; import org.osbot.rs07.api.util.LocalPathFinder; import org.osbot.rs07.event.InteractionEvent; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import java.awt.*; import java.util.Collection; import java.util.LinkedList; import java.util.Optional; import java.util.stream.Collectors; /** * Created by Alek on 5/8/2016. */ @ScriptManifest(name = "Castle Wars", author = "Alek", version = 1.0, info = "Castle Wars Script", logo = "") public class CastleWars extends Script { ScriptState scriptState = ScriptState.PENDING; private Team myTeam = null; private Player enemyPlayer = null; private final Area ZAMORAK_SPAWN_ROOM = new Area(2368, 3127, 2376, 3135).setPlane(1); private final Area SARADOMIN_SPAWN_ROOM = new Area(2423, 3072, 2431, 3080).setPlane(1); private final Area ZAMORAK_WAITING_ROOM = new Area(2403, 9510, 2437, 9543); private final Area SARADOMIN_WAITING_ROOM = new Area(2363, 9478, 2394, 9502); private final Area SARADOMIN_SPAWN_AREA = new Area(2420, 3072, 2431, 3083).setPlane(1); private final Area ZAMORAK_SPAWN_AREA = new Area(2368, 3124, 2379, 3135).setPlane(1); private final Position ZAMORAK_STAIRS_DOWN = new Position(2380, 3127, 1); private final Position SARADOMIN_STAIRS_DOWN = new Position(2419, 3080, 1); private final Position ZAMORAK_LADDER_DOWN = new Position(2378, 3134, 1); private final Position SARADOMIN_LADDER_DOWN = new Position(2421, 3073, 1); private final Position ZAMORAK_BARRIER = new Position(2377, 3131, 1); private final Position SARADOMIN_BARRIER = new Position(2422, 3076, 1); private final Position CENTER_ISLAND = new Position(2400, 3104, 0); private final Position ZAMORAK_CASTLE_FRONT = new Position(2387, 3115, 0); private final Position SARADOMIN_CASTLE_FRONT = new Position(2411, 3092, 0); private enum Team { SARADOMIN(1), ZAMORAK(2); int teamId; Team(int teamId) { this.teamId = teamId; } int getTeamId() { return teamId; } } private enum ScriptState {FIND_PORTAL, WAIT_FOR_GAME, GRAB_SUPPLIES, LEAVE_SPAWN, FIND_OPPONENT, FIGHT_OPPONENT, PENDING} @Override public void onPaint(Graphics2D g) { g.setColor(Color.WHITE); g.drawString(scriptState.name(), 10, 120); } @Override public int onLoop() { scriptState = getScriptState(); switch (scriptState) { case FIND_PORTAL: myTeam = null; Optional<RS2Object> optionalPortal = getObjects().getAll().stream().filter(o -> o.getName().equals("Guthix Portal")).findFirst(); if (optionalPortal.isPresent()) { if (optionalPortal.get().interact("Enter")) { new ConditionalSleep(5000, 500) { @Override public boolean condition() throws InterruptedException { return SARADOMIN_WAITING_ROOM.contains(myPlayer()) || ZAMORAK_WAITING_ROOM.contains(myPlayer()); } }.sleep(); } } else { log("Please start the script in Castle Wars!"); stop(false); } break; case WAIT_FOR_GAME: if (getDialogues().isPendingOption()) { getDialogues().selectOption("Yes please!"); } else if (myPlayer().getArea(2).getRandomPosition().interact(getBot(), "Walk here")) { getMouse().moveOutsideScreen(); new ConditionalSleep(MethodProvider.random(30000, 60000), 3000) { @Override public boolean condition() throws InterruptedException { return getDialogues().isPendingOption() || (SARADOMIN_SPAWN_ROOM.contains(myPosition()) || ZAMORAK_SPAWN_ROOM.contains(myPosition())); } }.sleep(); } break; case GRAB_SUPPLIES: Optional<RS2Object> optionalTable = getObjects().getAll().stream().filter(o -> o.getName().equals("Table") && (ZAMORAK_SPAWN_ROOM.contains(o) || SARADOMIN_SPAWN_ROOM.contains(o))).findFirst(); if (optionalTable.isPresent()) { for (int i = 0; i < MethodProvider.random(1, 5); i++) { if (optionalTable.get().interact("Take-5")) { final int slots = getInventory().getEmptySlots(); new ConditionalSleep(5000, 500) { @Override public boolean condition() throws InterruptedException { return slots != getInventory().getEmptySlots(); } }.sleep(); } } } break; case LEAVE_SPAWN: boolean successfullyLeftSpawnArea = false; if (SARADOMIN_SPAWN_ROOM.contains(myPosition()) || ZAMORAK_SPAWN_ROOM.contains(myPosition())) { Optional<RS2Object> optionalBarrier; if (getMyTeam().equals(Team.ZAMORAK)) optionalBarrier = getObjects().getAll().stream().filter(o -> o.getPosition().equals(ZAMORAK_BARRIER)).findFirst(); else optionalBarrier = getObjects().getAll().stream().filter(o -> o.getPosition().equals(SARADOMIN_BARRIER)).findFirst(); if (optionalBarrier.isPresent()) { if (optionalBarrier.get().interact("Pass")) { new ConditionalSleep(5000, 500) { @Override public boolean condition() throws InterruptedException { return !SARADOMIN_SPAWN_ROOM.contains(myPosition()) && !ZAMORAK_SPAWN_ROOM.contains(myPosition()); } }.sleep(); } } } else { Optional<RS2Object> optionalStairs; if (getMyTeam().equals(Team.ZAMORAK)) optionalStairs = getObjects().getAll().stream().filter(o -> o.getPosition().equals(ZAMORAK_STAIRS_DOWN)).findFirst(); else optionalStairs = getObjects().getAll().stream().filter(o -> o.getPosition().equals(SARADOMIN_STAIRS_DOWN)).findFirst(); if (optionalStairs.isPresent()) { if (!isPathBlocked(optionalStairs.get())) { if (optionalStairs.get().interact("Climb")) { successfullyLeftSpawnArea = true; new ConditionalSleep(5000, 500) { @Override public boolean condition() throws InterruptedException { return myPosition().getZ() == 0; } }.sleep(); } } else { Optional<RS2Object> optionalLadder; if (getMyTeam().equals(Team.ZAMORAK)) optionalLadder = getObjects().getAll().stream().filter(o -> o.getPosition().equals(ZAMORAK_LADDER_DOWN)).findFirst(); else optionalLadder = getObjects().getAll().stream().filter(o -> o.getPosition().equals(SARADOMIN_LADDER_DOWN)).findFirst(); if (optionalLadder.isPresent()) { if (!isPathBlocked(optionalLadder.get())) { if (optionalLadder.get().interact("Climb-down")) { successfullyLeftSpawnArea = true; new ConditionalSleep(5000, 500) { @Override public boolean condition() throws InterruptedException { return myPosition().getZ() == 0; } }.sleep(); } } else { NPC barricade = getNpcs().closest("Barricade"); if (barricade != null) { if (barricade.interact("Attack")) { new ConditionalSleep(5000, 500) { @Override public boolean condition() throws InterruptedException { return !barricade.exists(); } }.sleep(); } } } } } } if (successfullyLeftSpawnArea) { switch (MethodProvider.random(0, 2)) { case 1: getWalking().webWalk(CENTER_ISLAND); break; case 2: if (getMyTeam().equals(Team.ZAMORAK)) getWalking().webWalk(ZAMORAK_CASTLE_FRONT); else getWalking().webWalk(SARADOMIN_CASTLE_FRONT); break; } } } break; case FIND_OPPONENT: Collection<Player> enemies = getPlayers().getAll().stream().filter(p -> p.getTeam() != getMyTeam().getTeamId()).collect(Collectors.toList()); if (!enemies.isEmpty()) { for (Player enemy : enemies) { Rectangle enemyBounds = GraphicUtilities.getModelBoundingBox(getBot(), enemy.getGridX(), enemy.getGridY(), enemy.getZ(), enemy.getModel()); if (getMap().canReach(enemy)) { if (enemyBounds.intersects(GraphicUtilities.MAIN_SCREEN_CLIP)) { InteractionEvent event = new InteractionEvent(enemy, "Attack").setWalkTo(false); execute(event); if (event.hasFinished()) { enemyPlayer = enemy; break; } } else if (MethodProvider.random(0, 1) == 1) { getWalking().walk(enemy); break; } } } } break; case FIGHT_OPPONENT: if (enemyPlayer.exists()) { if (myPlayer().isInteracting(enemyPlayer)) { if (getInventory().contains("Bandages") && (getSkills().getStatic(Skill.HITPOINTS) - getSkills().getDynamic(Skill.HITPOINTS) > 10)) getInventory().getItem("Bandages").interact("Heal"); new ConditionalSleep(MethodProvider.random(2000, 5000), 500) { @Override public boolean condition() throws InterruptedException { return enemyPlayer.exists(); } }.sleep(); } else if (getMap().canReach(enemyPlayer)) { enemyPlayer.interact("Attack"); } else { enemyPlayer = null; } } else { enemyPlayer = null; } break; } return 1000; } private ScriptState getScriptState() { if (getConfigs().get(1021) == 0) return ScriptState.FIND_PORTAL; if (ZAMORAK_WAITING_ROOM.contains(myPlayer()) || SARADOMIN_WAITING_ROOM.contains(myPlayer())) return ScriptState.WAIT_FOR_GAME; if (SARADOMIN_SPAWN_AREA.contains(myPlayer()) || ZAMORAK_SPAWN_AREA.contains(myPlayer())) if (!getInventory().contains("Bandages")) return ScriptState.GRAB_SUPPLIES; else return ScriptState.LEAVE_SPAWN; if (enemyPlayer == null) return ScriptState.FIND_OPPONENT; return ScriptState.FIGHT_OPPONENT; } private Team getMyTeam() { if (myTeam == null) myTeam = myPlayer().getTeam() == 1 ? Team.SARADOMIN : Team.ZAMORAK; return myTeam; } private boolean isPathBlocked(Entity entity) { LocalPathFinder pf = new LocalPathFinder(bot); LinkedList<Position> path = pf.findPath(entity); if (pf.foundPath()) { Collection<NPC> barricades = getNpcs().getAll().stream().filter(o -> o.getName().equals("Barricade")).collect(Collectors.toList()); for (Position position : path) for (NPC barricade : barricades) if (barricade.getPosition().equals(position)) return true; return false; } return true; } } 16 Quote Link to comment Share on other sites More sharing options...
Czar Posted May 9, 2016 Share Posted May 9, 2016 Wow, good job on a castle wars script, how surprising XD Quote Link to comment Share on other sites More sharing options...
GoNode5 Posted May 9, 2016 Share Posted May 9, 2016 That's pretty usable once I start botting ill use it for sure whenever that might be. Quote Link to comment Share on other sites More sharing options...
Southperk Posted May 9, 2016 Share Posted May 9, 2016 Interesting idea, keen to try this out! Quote Link to comment Share on other sites More sharing options...
Kittens Posted May 9, 2016 Share Posted May 9, 2016 (edited) I have enough knowledge of java to use this even though I am not VIP and can't add it through the SDN. Thank you Aleky. I would like to thank TheScrub for this. Edited May 9, 2016 by Gh0st Quote Link to comment Share on other sites More sharing options...
Scotty Posted May 9, 2016 Share Posted May 9, 2016 Quote Link to comment Share on other sites More sharing options...
Alek Posted May 9, 2016 Author Share Posted May 9, 2016 Originally I wanted to do that or make a Catapult Sniper; it would grab a list of players, adjust coordinates, and fire. Not enough time though, have to get back to some of my real work now. Quote Link to comment Share on other sites More sharing options...
Pak Yak Posted May 9, 2016 Share Posted May 9, 2016 (edited) Only does one game, then goes back in portal and script stops, R.I.P Edited May 9, 2016 by Pak A Yak Newb Quote Link to comment Share on other sites More sharing options...
Tevez Posted May 9, 2016 Share Posted May 9, 2016 (edited) How is this VIP if the script is open source? Edited May 9, 2016 by Desluh 1 Quote Link to comment Share on other sites More sharing options...
Alek Posted May 9, 2016 Author Share Posted May 9, 2016 How is this VIP if the script is open source? If you are a VIP+ member you get the convenience of the script being on the SDN. You also get updates automatically if I make any. Quote Link to comment Share on other sites More sharing options...
Pak Yak Posted May 9, 2016 Share Posted May 9, 2016 You also get updates automatically if I make any. script only does one game then script stops, i thought to be on SDN it has to run for atleast 2hours? Quote Link to comment Share on other sites More sharing options...
Alek Posted May 9, 2016 Author Share Posted May 9, 2016 script only does one game then script stops, i thought to be on SDN it has to run for atleast 2hours? Runs multiple games for me; I have 19 tickets in one run so far. Quote Link to comment Share on other sites More sharing options...
Zerker Posted May 9, 2016 Share Posted May 9, 2016 would it be possible to disable combat features? I'd like to do this on a skiller but wearing a bow and trying to attack loads of people will make it more obvious that it's a bot. Quote Link to comment Share on other sites More sharing options...
Aiban Posted May 9, 2016 Share Posted May 9, 2016 Good release Quote Link to comment Share on other sites More sharing options...
Tater Posted May 9, 2016 Share Posted May 9, 2016 good job on the vip+ release keeps the community growing Quote Link to comment Share on other sites More sharing options...