GenericMeme46 13 Share Posted August 15, 2019 For my first script I decided it'd be best to go small so I've made this first draft of a rock crab script. Just any general feedback as to how I can optimize some things or go about doing things in a better way would be great. Some of the things I've done are precursors to an antiban system I'm working on. I should also mention I don't know how the bot detection system works, from what I've gathered is it makes a profile for each player and if you're flagged as a bot then it bans you. Link to comment Share on other sites More sharing options...
GenericMeme46 13 Author Share Posted August 15, 2019 Can't edit posts, that's tuff. Also this is for Rellekka rock crabs. And I've built it with the idea in mind to have the whole script able to have certain parts be ran under certain conditions and I think I've done a decent job at it but like I said, I'm not aware of very many coding techniques. I only know enough to get what I want done haha package main; import java.awt.Graphics; import java.util.concurrent.TimeUnit; import org.dreambot.api.methods.input.mouse.MouseSettings; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.tabs.Tab; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.Character; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.Item; import org.dreambot.api.methods.tabs.Tabs; import org.dreambot.api.methods.map.Area; @ScriptManifest(category = Category.COMBAT, name = "GenericRockCrabs", author = "GenericMeme", version = 0.1) public class main extends AbstractScript { private long scriptBT; private long scriptRT; private String currentTask; private String currentState; private Tile Walker; private NPC rockcrab; private Area rockCrabReAggroSpot = new Area(2690,3687, 2686, 3684); private Area rockCrabAggroSpot = new Area(2676,3709,2673,3711); private Area rockCrabArea = new Area(2662,3712,2689,3726); private Area RC1 = new Area(2675,3712,2677,3714); private Area RC2 = new Area(2682,3715,2684,3717); private Area RC3 = new Area(2685,3714,2687,3713); private Area RC4 = new Area(2685,3719,2683,3721); private Area RC5 = new Area(2678,3722,2676,3720); private Area RC6 = new Area(2676,3718,2678,3716); private Area RC7 = new Area(2674,3715,2672,3717); private Area WalkArea = new Area(2676, 3715,2679,3717); private int idleCount; private int myHealth; private int crabCount; public void onStart() { getMouse().setAlwaysHop(true); scriptBT = System.currentTimeMillis(); currentTask = "Idle"; currentState = "Idle"; } public void onPaint(Graphics g) { scriptRT = System.currentTimeMillis() - this.scriptBT; g.drawString("Some timer: " + conVer(scriptRT), 1, 20); g.drawString("Current Task: " + currentTask,1,75); g.drawString("Current State: " + currentState,1,100); g.drawString("Idle Counter: " + idleCount,250,100); } @Override public int onLoop() { healthSetup(); //If the player is not interacting with anything and the task is idle if ((getLocalPlayer().getInteractingCharacter() != null) && currentTask == "Idle") { currentTask = "Fighting"; currentState = "Fighting"; idleCount = 0; } //If the player is interacting and the state is idle if ((getLocalPlayer().getInteractingCharacter() != null) && (currentTask == "Fighting") && (currentState == "Idle")) { currentState = "Fighting"; idleCount = 0; } //If the player is not interacting with anything and we're idle but fighting still if ((getLocalPlayer().getInteractingCharacter() == null) && (currentTask == "Fighting") && (currentState == "Idle")) { currentState = "Idle"; } //If the player is not interacting with anything and the task/state is fighting if ((getLocalPlayer().getInteractingCharacter() == null) && (currentTask == "Fighting") && (currentState == "Fighting")) { currentState = "Idle"; } if ((currentTask == "Fighting") && (currentState == "Idle")) { idleCount++; } if ((currentTask == "Idle") && (currentState == "Idle")) { currentTask = "ReAggro"; idleCount = 0; } if ((idleCount == 25)) { currentState = "MoveToCrabs"; idleCount = 26; } else if (idleCount >= 50) { currentTask = "ReAggro"; } //If the task is ReAggro and it's walking to then constantly do it until we arrive if ((currentTask == "ReAggro")) { currentState = "Walking"; getWalking().walk(rockCrabReAggroSpot.getRandomTile()); sleep(2000); if (rockCrabReAggroSpot.contains(getLocalPlayer())) { currentTask = "Idle"; currentState = "MoveToCrabs"; } } //If we're Idle and also moving to walk crabs if ((currentState == "MoveToCrabs")) { getWalking().walk(rockCrabAggroSpot.getRandomTile()); sleep(2000); if (rockCrabAggroSpot.contains(getLocalPlayer())) { currentTask = "MoveCrabs"; currentState = "MoveCrab1"; crabCount = 0; } } //AGGRO THE CRABS if ((currentTask == "MoveCrabs") && (currentState == "MoveCrab1")) { log("R1"); if (getNpcs().closest(r -> r != null && RC1.contains(r) && r.getName().contains("Rocks")) != null) { moveToTile(RC1.getRandomTile()); crabCount++; sleep(4000); } currentState = "MoveCrab2"; } else if ((currentTask == "MoveCrabs") && (currentState == "MoveCrab2")) { log("R2"); if (getNpcs().closest(r -> r != null && RC2.contains(r) && r.getName().contains("Rocks")) != null) { moveToTile(RC2.getRandomTile()); crabCount++; sleep(4000); } currentState = "MoveCrab3"; } else if ((currentTask == "MoveCrabs") && (currentState == "MoveCrab3")) { log("R3"); if (getNpcs().closest(r -> r != null && RC3.contains(r) && r.getName().contains("Rocks")) != null) { moveToTile(RC3.getRandomTile()); crabCount++; sleep(4000); } currentState = "MoveCrab4"; } else if ((currentTask == "MoveCrabs") && (currentState == "MoveCrab4")) { log("R4"); if (getNpcs().closest(r -> r != null && RC4.contains(r) && r.getName().contains("Rocks")) != null) { moveToTile(RC4.getRandomTile()); crabCount++; sleep(4000); } currentState = "MoveCrab5"; } else if ((currentTask == "MoveCrabs") && (currentState == "MoveCrab5")) { log("R5"); if (getNpcs().closest(r -> r != null && RC5.contains(r) && r.getName().contains("Rocks")) != null) { moveToTile(RC5.getRandomTile()); crabCount++; sleep(4000); } currentState = "MoveCrab6"; } else if ((currentTask == "MoveCrabs") && (currentState == "MoveCrab6")) { log("R6"); if (getNpcs().closest(r -> r != null && RC6.contains(r) && r.getName().contains("Rocks")) != null) { moveToTile(RC6.getRandomTile()); crabCount++; sleep(4000); } currentState = "Walker"; } else if ((currentTask == "MoveCrabs") && (currentState == "Walker")) { if (crabCount >= 3) { Walker = WalkArea.getRandomTile(); log("Walker"); moveToTile(Walker); sleep(4000); Walker = new Tile(Walker.getX() + 1, Walker.getY() - 1); moveToTile(Walker); sleep(4000); Walker = new Tile(Walker.getX() - 1, Walker.getY() - 1); moveToTile(Walker); } else { rockcrab = (getNpcs().closest(r -> r != null && rockCrabArea.contains(r) && r.getName().contains("Rock Crab"))); if (rockcrab != null) { rockcrab.interact("Attack"); } } currentTask = "Fighting"; currentState = "Idle"; sleep(1000); } return 100; } private String conVer(long duration) { String retu = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)); if (days == 0) { retu = (hours + ":" + minutes + ":" + seconds); } else { retu = (days + ":" + hours + ":" + minutes + ":" + seconds); } return retu; } public boolean isTileOnScreen(Tile t){ return getClient().getViewport().isOnGameScreen(getMap().tileToScreen(t)); } public void moveToTile(Tile t) { if (!isTileOnScreen(t)) { getCamera().rotateToTile(t); } getWalking().walkOnScreen(t); } public void healthSetup() { //Get MY health myHealth = getLocalPlayer().getHealthPercent(); //Eat FIRST if low if (myHealth <= 33) { log("EAT NOW"); } } } Link to comment Share on other sites More sharing options...
Lem0nz 33 Share Posted August 15, 2019 Haven't paid a lot of attention to your code, but I noticed that you're using getLocalPlayer().getHealthPercent(). In the past, this method revealed as not completly functional for me. That for, if you even encounter problems with it, I suggest a simple change to: getSkills().getBoostedLevels(Skill.HITPOINTS) / (float)getSkills().getRealLevel(Skill.HITPOINTS) It returns in a form of [0; 1] but you can change that to [0, 100]% by just multiplying the whole thing by 100 (and maybe cast it to int, rounding it down if necessary). Good job with the script anyway! getSkills().getBoostedLevels(Skill.HITPOINTS) returns the number in the blue circle getSkills().getRealLevel(Skill.HITPOINTS) returns the number in the green circle Your HP % is the decimal division between them, and since both methods return ints, convert one of the params to float, and a float is what you'll get as a result. Ez. Link to comment Share on other sites More sharing options...
GenericMeme46 13 Author Share Posted August 16, 2019 1 hour ago, Lem0nz said: Haven't paid a lot of attention to your code, but I noticed that you're using getLocalPlayer().getHealthPercent(). In the past, this method revealed as not completly functional for me. That for, if you even encounter problems with it, I suggest a simple change to: getSkills().getBoostedLevels(Skill.HITPOINTS) / (float)getSkills().getRealLevel(Skill.HITPOINTS) It returns in a form of [0; 1] but you can change that to [0, 100]% by just multiplying the whole thing by 100 (and maybe cast it to int, rounding it down if necessary). Good job with the script anyway! Reveal hidden contents getSkills().getBoostedLevels(Skill.HITPOINTS) returns the number in the blue circle getSkills().getRealLevel(Skill.HITPOINTS) returns the number in the green circle Your HP % is the decimal division between them, and since both methods return ints, convert one of the params to float, and a float is what you'll get as a result. Ez. Okay I'll look into that. Thanks for the feedback Link to comment Share on other sites More sharing options...
C20H25N3O 0 Share Posted August 16, 2019 Maybe start using a task-based script base Link to comment Share on other sites More sharing options...
GenericMeme46 13 Author Share Posted August 16, 2019 13 hours ago, C20H25N3O said: Maybe start using a task-based script base That's what I'm looking to get feedback on. I don't have any other ideas on how to go about doing this. Is there anything I can do to improve such a system? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.