Jump to content

Tasemu

Members
  • Posts

    69
  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by Tasemu

  1. Hey guys, here is my first script for OSBot. The first of hopefully many more. I have open sourced it and you can find the script and the link to Github online. Please feel free to post any comments and constructive criticism of my script right here and don't be shy as I hope to get a few new techniques out of this share to improve my future scripts. If you wanna say thanks for the script then that would also make me pretty happy haha. Welp enjoy ^^

    Credits to so many awesome people on this forum. If you have posted on one of my threads, or if I have used a method you shared then please post below and i'll credit you for sure!

    Progress reports coming soon... running it now.

    Github: https://github.com/Tasemu/osbot_descrete_gulls (fork me baby)

    package descrete_gulls;
    
    import org.osbot.rs07.api.map.Area;
    import org.osbot.rs07.api.model.NPC;
    import org.osbot.rs07.api.ui.Skill;
    import org.osbot.rs07.api.util.GraphicUtilities;
    import org.osbot.rs07.script.Script;
    import org.osbot.rs07.script.ScriptManifest;
    import org.osbot.rs07.utility.ConditionalSleep;
    
    import java.awt.*;
    import java.util.EnumSet;
    
    @ScriptManifest(author = "Tasemu", info = "Kill seagulls at Port Sarim", name = "Descrete Gulls", version = 1.1, logo = "")
    public class main extends Script {
    	private Area docks = new Area(
    	    new int[][]{
    	        { 3026, 3241 },
    	        { 3030, 3241 },
    	        { 3030, 3238 },
    	        { 3047, 3238 },
    	        { 3047, 3234 },
    	        { 3030, 3234 },
    	        { 3030, 3211 },
    	        { 3026, 3211 },
    	        { 3026, 3216 },
    	        { 3018, 3216 },
    	        { 3018, 3220 },
    	        { 3026, 3220 }
    	    }
    	);
    	private NPC target;
    	private enum State {
    		WAIT,
    		WALK,
    		ATTACK
    	};
    	private EnumSet<Skill> skillToTrain = EnumSet.of(Skill.ATTACK, Skill.STRENGTH, Skill.DEFENCE, Skill.HITPOINTS);
    	private long startTime;
    	private int gullsKilled = 0;
    	
    	@Override
    	public void onStart() {
    		log("Welcome to Descrete Gulls.");
    		log("version: " + getVersion());
    		startTime = System.currentTimeMillis();
    		
    		for (Skill skill : skillToTrain) {
    			getExperienceTracker().start(skill);
    		}
    	}
    
    	private State getState() {
    		NPC gull = getNpcs().closest("Seagull");
    		
    		if (target != null && myPlayer().isInteracting(target))
    			return State.WAIT;
    		
    		if (!docks.contains(myPlayer()))
    			return State.WALK;
    		
    		if (
    			gull != null &&
    			!gull.isUnderAttack() &&
    			!gull.isHitBarVisible()
    		)
    			return State.ATTACK;
    		
    		return State.WAIT;
    	}
    
    	@Override
    	public int onLoop() throws InterruptedException {
    		switch (getState()) {
    		case ATTACK:
    			target = getNpcs().closest("Seagull");
    			if (target != null) {
    				if (target.interact("Attack")) {
    					new ConditionalSleep(random(3000, 5000)) {
    						@Override
    						public boolean condition() throws InterruptedException {
    							return target != null &&
    								   target.getHealthPercent() > 0;
    						}
    					}.sleep();
    				}
    			}
    			break;
    		case WALK:
    			getWalking().webWalk(docks);
    			break;
    		case WAIT:
    			
    			if (target != null && target.getHealthPercent() == 0) {
    				this.gullsKilled++;
    				this.target = null;
    			}
    			
    			if (this.getDialogues().isPendingContinuation()) {
    				this.getDialogues().clickContinue();
    			}
    			
    			sleep(random(500, 700));
    			break;
    		}
    		return random(200, 300);
    	}
    
    	@Override
    	public void onExit() {
    		log("Bye!");
    	}
    
    	@Override
    	public void onPaint(Graphics2D g) {
    		final long runTime = System.currentTimeMillis() - startTime;
    		drawMouse(g);
    		g.setColor(Color.WHITE);
    		g.drawString("Descrete Gulls Public v" + this.getVersion(), 10, 40);
    		g.drawString("Status:  " + getState().toString().toLowerCase() + "ing", 10, 55);
    		g.drawString("Time running: " + formatTime(runTime), 10, 70);
    		g.drawString("Gulls Wasted: " + this.gullsKilled, 10, 85);
    		int trainingPaintMargin = 0;
    		
    		for (Skill skill : skillToTrain) {
    			if (getExperienceTracker().getGainedXP(skill) > 0) {
    				g.drawString(skill.toString().toLowerCase() + " xp: " + getExperienceTracker().getGainedXP(skill), 10, 100 + trainingPaintMargin);
    				trainingPaintMargin += 15;
    			}
    		}
    		
    		if (target != null && target.exists()) {
    			g.setColor(Color.RED);
    			GraphicUtilities.drawWireframe(getBot(), g, target);
    		}
    	}
    	
    	public final String formatTime(final long ms){
            long s = ms / 1000, m = s / 60, h = m / 60;
            s %= 60; m %= 60; h %= 24;
            return String.format("%02d:%02d:%02d", h, m, s);
        }
        
        private void drawMouse(Graphics graphics) {
    		((Graphics2D) graphics).setRenderingHints(
    			new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
    		Point pointer = mouse.getPosition();
    		Graphics2D spinG = (Graphics2D) graphics.create();
    		Graphics2D spinGRev = (Graphics2D) graphics.create();
    		spinG.setColor(new Color(255, 255, 255));
    		spinGRev.setColor(Color.cyan);
    		spinG.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
    		spinGRev.rotate(System.currentTimeMillis() % 2000d / 2000d * (-360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
    		final int outerSize = 20;
    		final int innerSize = 12;
    		spinG.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    		spinGRev.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, 100, 75);
    		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, -100, 75);
    		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, 100, 75);
    		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, -100, 75);
    	}
    
    }

     

    • Like 2
  2. I want to have a paint over my current target npc. I have had a look through the NPC api and have found information regarding their coordinates on the map, but am unsure how to get the coordinates to paint over the model. Does anyone have any advice on this subject? Cheers!

  3. Hey there, is there a decent check for my player being in or out of combat? And what about other players? I'm seeing spash bots in the chicken areas and I cannot find any combination of checks (yet) in the api to handle it. My current home-made combat checking is pretty flakey, and if people are splashing spells then my script is trying to take their chickens haha ^^

  4. Also if you dont mind my asking, what is wrong with splitting up the script into multiple classes, even if the script is small? Also what is wrong with the task based approach? as a developer i saw it as a nice way to split up code and have each task responsible for its own running. Are java programming patterns different?

  5. I am having a slight encapsulation problem with my chicken counter. i am tracking the chicken entity within another task class so i need to track the number of killed chickens within the task class don't i? if this is the case then how would i pass the data to my Main.onPaint() function?

    KillChickens.java

    package tasks;
    
    import org.osbot.rs07.api.filter.Filter;
    import org.osbot.rs07.api.map.Area;
    import org.osbot.rs07.api.model.NPC;
    import org.osbot.rs07.script.Script;
    import org.osbot.rs07.utility.ConditionalSleep;
    
    import static org.osbot.rs07.script.MethodProvider.random;
    
    public class KillChickens extends Task {
    	private Area farm;
    	public Filter<NPC> chickenFilter = new Filter<NPC>() {
    		@Override
    		public boolean match(final NPC entity) {
    			return entity.getName().equalsIgnoreCase("chicken") &&
    				   !entity.isUnderAttack() &&
    				   entity.isAttackable() &&
    				   farm.contains(entity);
    		}
    	};
    
    	public KillChickens(Script script, Area farm) {
    		super(script);
    		this.farm = farm;
    	}
    	
    	@Override
    	public boolean verify() {
    		return !script.myPlayer().isAnimating() && !script.myPlayer().isHitBarVisible();
    	}
    
    	@Override
    	public int execute() {
    		if (farm.contains(script.myPlayer())) {
    			script.log("Finding chicken...");
    			NPC chicken = script.getNpcs().singleFilter(script.getNpcs().getAll(), chickenFilter);
    			
    			if (!script.myPlayer().isAnimating() && chicken != null) {
    				script.getCamera().toEntity(chicken);
    				if (chicken.interact("Attack")) {
    					new ConditionalSleep(5000) {
    						@Override
    						public boolean condition() throws InterruptedException {
    							return chicken.exists() &&
    								   chicken.getHealthPercent() > 0 &&
    								   script.myPlayer().isInteracting(chicken);
    						}
    					}.sleep();
    				};
    			}
    		} else {
    			script.getWalking().webWalk(farm);
    		}
    		
    		return random(300, 1200);
    	}
    
    	@Override
    	public String describe() {
    		return "Attacking Chickens.";
    	}
    }

    Main.java

    import org.osbot.rs07.api.map.Area;
    import org.osbot.rs07.api.ui.Skill;
    import org.osbot.rs07.script.Script;
    import org.osbot.rs07.script.ScriptManifest;
    
    import tasks.*;
    
    import java.awt.*;
    import java.util.ArrayList;
     
    @ScriptManifest(author = "Tasemu", info = "Chicken killing script", name = "Chicken Killer", version = 1.0, logo = "")
    public class Main extends Script {
    	
    	private long startTime;
    	private ArrayList<Task> tasks = new ArrayList<>();
    	private Area farm = new Area(
    		    new int[][]{
    		        { 3184, 3276 },
    		        { 3184, 3278 },
    		        { 3183, 3281 },
    		        { 3179, 3288 },
    		        { 3179, 3289 },
    		        { 3178, 3289 },
    		        { 3177, 3288 },
    		        { 3175, 3288 },
    		        { 3174, 3289 },
    		        { 3171, 3289 },
    		        { 3169, 3291 },
    		        { 3169, 3295 },
    		        { 3170, 3296 },
    		        { 3170, 3298 },
    		        { 3169, 3299 },
    		        { 3169, 3300 },
    		        { 3173, 3304 },
    		        { 3173, 3308 },
    		        { 3180, 3308 },
    		        { 3180, 3304 },
    		        { 3182, 3304 },
    		        { 3183, 3303 },
    		        { 3184, 3303 },
    		        { 3186, 3301 },
    		        { 3186, 3299 },
    		        { 3187, 3298 },
    		        { 3187, 3296 },
    		        { 3186, 3295 },
    		        { 3186, 3291 },
    		        { 3184, 3289 },
    		        { 3190, 3280 },
    		        { 3192, 3280 },
    		        { 3193, 3279 },
    		        { 3193, 3276 },
    		    }
    		);
     
        @Override
        public void onStart() {
            log("Welcome to Chicken Killer!");
            log("Current version: " + getVersion());
            
            startTime = System.currentTimeMillis();
            
            getExperienceTracker().start(Skill.ATTACK);
            getExperienceTracker().start(Skill.STRENGTH);
            getExperienceTracker().start(Skill.DEFENCE);
            getExperienceTracker().start(Skill.HITPOINTS);
            getExperienceTracker().start(Skill.RANGED);
            getExperienceTracker().start(Skill.MAGIC);
            
            tasks.add(new KillChickens(this, farm));
            tasks.add(new Loot(this, farm));
        }
        
        public int getChickenCount() {
        	int xpPerChicken = 12;
        	int totalXp = getExperienceTracker().getGainedXP(Skill.ATTACK)
        				+ getExperienceTracker().getGainedXP(Skill.STRENGTH)
        				+ getExperienceTracker().getGainedXP(Skill.DEFENCE)
        				+ getExperienceTracker().getGainedXP(Skill.RANGED)
        				+ getExperienceTracker().getGainedXP(Skill.MAGIC);
        	
        	return totalXp / xpPerChicken;
        }
     
        @Override
        public int onLoop() throws InterruptedException {
        	for (Task task : tasks) {
                if (task.verify())
                    return task.execute();
            }
        	
            return random(600, 1600);
        }
     
        @Override
        public void onExit() {
            log("Bye!");
        }
     
        @Override
        public void onPaint(Graphics2D g) {
        	final long runTime = System.currentTimeMillis() - startTime;
        	int xpDrawMarker = 0;
        	
        	drawMouse(g);
        	
        	g.setColor(Color.WHITE);
        	g.drawString("Chicken Killer", 10, 40);
        	g.drawString("Time running: " + formatTime(runTime), 10, 55);
        	g.drawString("Chickens Killed: " + getChickenCount(), 10, 70);
        	
        	if (getExperienceTracker().getGainedXP(Skill.ATTACK) > 0) {
        		g.drawString("ATT XP gained: " + getExperienceTracker().getGainedXP(Skill.ATTACK) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.ATTACK)) + ")", 10, 85 + xpDrawMarker);
        		xpDrawMarker += 15;
        	}
        	
        	if (getExperienceTracker().getGainedXP(Skill.STRENGTH) > 0) {
        		g.drawString("STR XP gained: " + getExperienceTracker().getGainedXP(Skill.STRENGTH) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.STRENGTH)) + ")", 10, 85 + xpDrawMarker);
        		xpDrawMarker += 15;
        	}
        	
        	if (getExperienceTracker().getGainedXP(Skill.DEFENCE) > 0) {
        		g.drawString("DEF XP gained: " + getExperienceTracker().getGainedXP(Skill.DEFENCE) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.DEFENCE)) + ")", 10, 85 + xpDrawMarker);
        		xpDrawMarker += 15;
        	}
        	
        	if (getExperienceTracker().getGainedXP(Skill.HITPOINTS) > 0) {
        		g.drawString("HP XP gained: " + getExperienceTracker().getGainedXP(Skill.HITPOINTS) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.HITPOINTS)) + ")", 10, 85 + xpDrawMarker);
        		xpDrawMarker += 15;
        	}
        	
        	if (getExperienceTracker().getGainedXP(Skill.RANGED) > 0) {
        		g.drawString("RANGED XP gained: " + getExperienceTracker().getGainedXP(Skill.RANGED) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.RANGED)) + ")", 10, 85 + xpDrawMarker);
        		xpDrawMarker += 15;
        	}
        	
        	if (getExperienceTracker().getGainedXP(Skill.MAGIC) > 0) {
        		g.drawString("MAGIC XP gained: " + getExperienceTracker().getGainedXP(Skill.MAGIC) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.MAGIC)) + ")", 10, 85 + xpDrawMarker);
        		xpDrawMarker += 15;
        	}
        	
        }
        
        public final String formatTime(final long ms){
            long s = ms / 1000, m = s / 60, h = m / 60;
            s %= 60; m %= 60; h %= 24;
            return String.format("%02d:%02d:%02d", h, m, s);
        }
        
        private void drawMouse(Graphics graphics) {
    		((Graphics2D) graphics).setRenderingHints(
    			new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
    		Point pointer = mouse.getPosition();
    		Graphics2D spinG = (Graphics2D) graphics.create();
    		Graphics2D spinGRev = (Graphics2D) graphics.create();
    		spinG.setColor(new Color(255, 255, 255));
    		spinGRev.setColor(Color.cyan);
    		spinG.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
    		spinGRev.rotate(System.currentTimeMillis() % 2000d / 2000d * (-360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
    		final int outerSize = 20;
    		final int innerSize = 12;
    		spinG.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    		spinGRev.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, 100, 75);
    		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, -100, 75);
    		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, 100, 75);
    		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, -100, 75);
    	}
     
    }

     

×
×
  • Create New...