Jump to content

Karamja knife smither source


Twin

Recommended Posts

This script never went anywhere, and not going to release something only 5 people can use at a time.

 

Code is really sloppy, and I wrote it a while ago, but maybe someone will find use out of it, as it works and it covers a few elements. World hopping, buying from a store, interface interaction, and interacting with an object in your inventory, then having that interact with an object.

 

Main class

import org.osbot.rs07.api.Store;
import org.osbot.rs07.api.filter.Filter;
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.ui.Message;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.World;
import org.osbot.rs07.api.util.GraphicUtilities;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;
import org.osbot.rs07.api.Worlds;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.osbot.rs07.api.ui.World;

import Timer.Timer;

import java.awt.*;

@ScriptManifest(author = "Twin 763", info = "Karamja Knife Maker", name = "Twins Karamja Knives", version = 1, logo = "")
public class BronzeBuyer extends Script {
	private Timer animationTimer;
	private int currentLevel;
	private int beginningLevel;
	private int levelsGained;
	private int beginningXP;
	private int currentXp;
	private int xpGained;
	private Position posToOutline = new Position(0, 0, 0);
	private int gp;
	private int knivesMade;
	@Override
	public void onStart() {
	
		animationTimer = new Timer(0L);
		timeBegan = System.currentTimeMillis();
		beginningLevel = skills.getStatic(Skill.SMITHING);
		beginningXP = skills.getExperience(Skill.SMITHING);
	}
	private long timeBegan;
	private long timeRan;

	Position[] pathToPaint = new Position[] {};
	Position[] toSmith = { new Position(2765, 3124, 0),
			new Position(2768, 3120, 0), new Position(2771, 3116, 0),
			new Position(2774, 3112, 0), new Position(2778, 3109, 0),
			new Position(2782, 3106, 0), new Position(2787, 3104, 0),
			new Position(2792, 3102, 0) };

	Position[] leaveSmith = { new Position(2793, 3099, 0),
			new Position(2788, 3101, 0), new Position(2785, 3105, 0),
			new Position(2781, 3108, 0), new Position(2777, 3112, 0),
			new Position(2773, 3115, 0), new Position(2769, 3118, 0),
			new Position(2765, 3121, 0) };

	Area GENERALSTORE = new Area(2761, 3117, 2772, 3126);
	Area SMITH = new Area(2794, 3106, 2786, 3096);
	
	private enum State {
		SMITH, BUY, WALKTOANVIL, WALKTOSTORE, WAIT
	};

	private State getState() {
		Entity anvil = objects.closest("Anvil");
		NPC jim = npcs.closest("Jiminua");
		if (anvil != null && inventory.contains("Bronze bar")
				&& SMITH.contains(myPlayer())
				&& needToResume(4000L, animationTimer)
				&& !myPlayer().isAnimating())
			return State.SMITH;
		if (!inventory.isFull() && GENERALSTORE.contains(myPlayer())
				&& jim != null)
			return State.BUY;
		if (inventory.isFull() && !SMITH.contains(myPlayer()))
			return State.WALKTOANVIL;
		if (!inventory.contains("Bronze bar")
				&& !GENERALSTORE.contains(myPlayer()))
			return State.WALKTOSTORE;
		return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case SMITH:
			Entity anvil = objects.closest("Anvil");
			RS2Widget k = widgets.get(312, 24, 2);
			if (anvil != null) {
				inventory.interact("Use", "Bronze bar");
				sleep(random(500, 1000));
			}
			if (inventory.isItemSelected() == true) {
				anvil.interact("Use");
				sleep(random(500, 1000));
			}
			if (k != null && k.isVisible() && !myPlayer().isAnimating()) {
				k.interact("Smith X Sets");
				sleep(random(500, 1000));
				keyboard.typeString("" + random(28, 100000));
				sleep(random(1000, 1500));
			}
			break;
		case BUY:
			NPC jim = npcs.closest("Jiminua");
			if (jim != null) {
				jim.interact("Trade");
				sleep(random(2000, 2500));
				store.buy(2349, 10);
				sleep(random(500, 1000));
			}
			if (store.getAmount("Bronze bar") == 0)
			{
			
				  worlds.hopToP2PWorld();
				  	break;
			}
			if (inventory.isFull())
				break;
		case WAIT:
			sleep(random(500, 700));
			break;
		case WALKTOANVIL:
			if (!SMITH.contains(myPlayer()))
				localWalker.walkPath(toSmith);
			if (SMITH.contains(myPlayer()))
				break;
		case WALKTOSTORE:
			if (!GENERALSTORE.contains(myPlayer())&&!inventory.contains("Bronze bar"))
				localWalker.walkPath(leaveSmith);
			if (GENERALSTORE.contains(myPlayer()))
				break;
		default:
			break;
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		
	}
	@Override
	public void onMessage(Message message) throws InterruptedException
	{
	if(message.getMessage().toString().contains("You hammer the bronze"))
	{
	
		knivesMade++;
		knivesMade++;
		knivesMade++;
		knivesMade++;
		knivesMade++;
	}
	}
	@Override
	public void onPaint(Graphics2D g) 
	{
		Graphics2D gr = g;
		
		currentLevel = skills.getStatic(Skill.SMITHING);
		levelsGained = currentLevel - beginningLevel;
		g.drawString("Starting level " + beginningLevel + " / Current Level "
				+ currentLevel + " ( +" + levelsGained + " )", 40, 290);
		timeRan = System.currentTimeMillis() - this.timeBegan;
		g.drawString(ft(timeRan), 40, 230);
		currentXp = skills.getExperience(Skill.SMITHING);
		xpGained = currentXp - beginningXP;
		gp = knivesMade*44;
		g.drawString("Money made "+gp,40,250);
		g.drawString("Experience gained " + xpGained, 40, 310);
		g.drawString("Bronze knives made "+knivesMade,40,270);
		if (posToOutline != null)
			drawTileIngame(this, g, posToOutline, Color.WHITE);
		if (pathToPaint != null)
			for (Position p : pathToPaint) {
				drawMinimapPosition(this, g, p, Color.ORANGE, true);
			}
		g.setColor(Color.green);
		g.fillRect((int) getMouse().getPosition().getX() - 5, (int) getMouse()
		    .getPosition().getY(), 13, 3);
		  g.fillRect((int) getMouse().getPosition().getX(), (int) getMouse()
		    .getPosition().getY() - 5, 3, 13);
	}

	public void checkAnimationTimer(Timer timerToUpdate) {
		if (this.myPlayer().isAnimating()) {
			timerToUpdate.reset();
		}
	}

	public boolean needToResume(long idleTimeout, Timer t) {
		checkAnimationTimer(t);
		if (t.getElapsed() >= idleTimeout)
			return true;
		else
			return false;
	}

	
	public void drawTileIngame(Script script, Graphics g, Position p,
			Color positionColor) {
		g.setColor(positionColor);
		Polygon PosHighlight = p.getPolygon(script.getBot());
		g.drawPolygon(PosHighlight);
	}

	private String ft(long duration) {
		String res = "";
		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) {
			res = (hours + ":" + minutes + ":" + seconds);
		} else {
			res = (days + ":" + hours + ":" + minutes + ":" + seconds);
		}
		return res;
	}

	public static void drawMinimapPosition(Script script, Graphics g,
			Position p, Color positionColor, boolean fill) {
		if (p != null) {
			short[] minimapP = GraphicUtilities.getMinimapScreenCoordinate(
					script.getBot(), p.getX(), p.getY());
			if (minimapP[0] > 0) {
				g.setColor(positionColor);
				if (fill) {
					g.fillRect(minimapP[0] - 2, minimapP[1] - 2, 4, 4);
				} else {
					g.drawRect(minimapP[0] - 2, minimapP[1] - 2, 4, 4);
				}
			}
		}
	}
}

Timer class(credit to apaec)

package Timer;

public class Timer
{

    private long period;
    private long start;
 
    public Timer(long period)
    {
        this.period = period;
        start = System.currentTimeMillis();
    }

    public long getElapsed()
    {
        return System.currentTimeMillis() - start;
    }

    public long getRemaining()
    {
        return period - getElapsed();
    }

    public boolean isRunning()
    {
        return getElapsed() <= period;
    }

    public void reset()
    {
        start = System.currentTimeMillis();
    }
    
    public void stop()
    {
        period = 0;
    }

    public static String format(long milliSeconds)
    {
        long secs = milliSeconds / 1000L;
        return String.format("%02d:%02d:%02d", new Object[] {
            Long.valueOf(secs / 3600L), Long.valueOf((secs % 3600L) / 60L), Long.valueOf(secs % 60L)
        });
    }
}

 

I will not compile this for anyone, or send you the local version, you can do that yourself if you want to use it.

Edited by twin 763
  • Like 1
Link to comment
Share on other sites

that's pretty cool, would it be much more profitable with karamja gloves?

I think karamja gloves only let you sell things for more. Bronze bars are only like 12gp, and 5 bronze knives are 200gp, so it's 188gp profit a smith no matter what.

might just be me but i read this as karambit knife slaughter xD

I read your comment as karambawn knife smither. GG. If you wanna pass a kata but my way though I wouldn't complain ;). :doge:

Edited by twin 763
Link to comment
Share on other sites

could you explain your drawMinimapPosition and drawTitleIngame methods? 

 

The first one will highlight the current path it's walking on the minimap, the second one will put a white box around whatever the bot is interacting with.

 

I don't think I ever actually used it in this though, I just had the methods there that I copy/pasted from other scripts.

Edited by twin 763
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...