Jump to content

Warrior Guild tokens script


Megagozer

Recommended Posts

Hi guys, I made this little script today that collects tokens for the defenders at warrior guild by summoning an Animated Armour. Its very very basic, probably extremely poor written as I have very little experience with java but hey, it works. In the current settings it eats lobster and uses mithril armour tho by changing the ints in the code you can change it to whatever you like. It does not bank, so you'll have to get some food yourself every now and then. Don't expect any fancy, no paint, no updates, I was just too lazy to collect the tokens myself and thought it would be nice to share it with you guys:) 

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.util.Random;

import org.osbot.rs07.api.Skills; 
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.NPCS;

import java.awt.*;
 
@ScriptManifest(author = "You", info = "My first script", name = "MegaWGuild", version = 0, logo = "")
public class MegaWGuild extends Script {
	int randomHealth = random(30, 40);
	public static int foodId = 379;
	public static int helmId = 1159;
	public static int bodyId = 1121;
	public static int legsId = 1071;
	public static int tokenId = 8851;
	public static String goatName = "Animated Mithril Armour";
	
    @Override
    public void onStart() {
        log("Let's get started!");
    }
 
    @Override
    public int onLoop() throws InterruptedException {
    	if ((this.inventory.contains(new int[] { foodId })) && (!myPlayer().isMoving())) {
	    	if (!myPlayer().isMoving())
	       	{
	    		NPC goat = (NPC)this.npcs.closest(new String[] {goatName});
	    		GroundItem helm = (GroundItem)this.groundItems.closest(new int[] {helmId });
	    		GroundItem body = (GroundItem)this.groundItems.closest(new int[] {bodyId });
	    		GroundItem legs = (GroundItem)this.groundItems.closest(new int[] {legsId });
	    		GroundItem token = (GroundItem)this.groundItems.closest(new int[] {tokenId });
	    		if (currentHealth() < randomHealth) {
	    	          eat();
	    	          sleep(random(300, 500));
	     	        }
	    		else if ((goat != null) && (!goat.isUnderAttack())) {
	    			goat.interact(new String[] { "Attack" });
    	            sleep(random(1000, 1500));
	    		}
	    		else if (body != null){ 
	    			takeGroundItem(bodyId);
	    		}
	    		else if (helm != null){ 
	    			takeGroundItem(helmId);
	    	    }
	    		else if (legs != null){ 
	    			takeGroundItem(legsId);
	    	    }
	    		else if (token != null){ 
	    			takeGroundItem(tokenId);
	    			sleep(random(100, 400));
	    	    }
	    		else if ((helm == null) && (legs == null) && (body == null) && (token == null))  {
	    			Item use = this.inventory.getItem(new int[] {bodyId });
	    			use.interact(new String[] { "Use"});
	    			sleep(random(100, 500));
	    			RS2Object tile = this.objects.closest(new String[] { "Magical Animator" });
	    			tile.interact(new String[] { "Use"});
	    			sleep(random(2000, 3000));
	    		}	
	    	}
    	}
    	 return random(200, 300);
    }
    

	private void eat() {
		Item food = this.inventory.getItem(new int[] {foodId });
		food.interact(new String[] { "Eat" });
	}
	
	int currentHealth()	{
		int percperone = 100 / this.skills.getStatic(Skill.HITPOINTS);
		return percperone * this.skills.getDynamic(Skill.HITPOINTS);
	}	    	

	private void takeGroundItem(int id)
    {
      try
      { 
        GroundItem horn = (GroundItem)this.groundItems.closest(new int[] { id });
        
        horn.interact(new String[] { "Take" });
        
        sleep(random(1200, 1500));
      }
      catch (Exception localException) {}
    }
	
    @Override
    public void onExit() {
        log("Thanks for running my Warrior Guild script!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}
Edited by Megagozer
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 3 weeks later...
  • 2 weeks later...
  • 2 months later...
  • 2 months later...
  • 1 year later...

if anyone was interested, I have fixed this script so that it works now: below is proggy and code:

image.png.1c48130392d34926211e4df9444a11a2.png

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;

@ScriptManifest(name = "Animator by RickyD", author = "RickyD", version = 1.0, info = "Animates your armour to farm warrior guild tokens", logo = "")

public class Warriorguild  extends Script {

    String[] foodName = {"Monkfish"};
    NPC anim;
    GroundItem lootables;
    private String armorType = "Mithril";
    String [] lootNames = {armorType + " platebody", "Warrior guild token", armorType + " platelegs", armorType + " full helm"};


    @Override

    public void onStart() {
        startTime = System.currentTimeMillis();
        if(hasArmour()!=true){
            log("false");
        }
    }


    @Override

    public void onExit() {
        log("Script has exited successfully");
    }
    private long startTime;

/*    public boolean hasArmour(){
        if(getInventory().contains(armorType + " platebody") && getInventory().contains(armorType + " platelegs") && getInventory().contains(armorType + " full helm")){
            log("hasarmour is true");
            return true;

        }
        return false;
    }
*/

    public boolean hasArmour(){
     return getInventory().contains(armorType + " platebody") && getInventory().contains(armorType + " platelegs") && getInventory().contains(armorType + " full helm");
     }

    @Override

    public int onLoop() throws InterruptedException{

        // anim = getNpcs().closest(2454);


        anim = getNpcs().closest("Animated " + armorType + " armour");

        lootables = getGroundItems().closest(lootNames);

        if(getInventory().contains(foodName) && getInventory().getAmount("Warrior guild token") < 1000){
            if(anim != null && anim.isInteracting(myPlayer())){
                if(myPlayer().getHealthPercent() < 50){

                    getInventory().interact("Eat", foodName);
                    //DTiming.waitCondition(() -> myPlayer().getAnimation() == 829, 2000);
                    new ConditionalSleep(2000){
                        @ Override
                        public boolean condition() throws InterruptedException
                        {
                            return myPlayer().getAnimation() == 829;
                        }
                    }.sleep();
                    sleep(random(400, 650));
                }else{
                    if(myPlayer().getInteracting() == null){
                        anim.interact("Attack");
                        sleep(random(800, 1100));
                    }
                }
            }else{
                if(lootables != null){
                    if (lootables.interact("Take")) {
                        sleep(random(1200, 1500));
                    }
                }else{
                    if(hasArmour()){
                        if (getObjects().closest("Magical Animator").interact("Animate")) {
                            sleep(random(1200, 2000));
                        }
                    }
                }
            }
        }else{
            stop(false);
            JOptionPane.showMessageDialog(null,
                    "NO FOOD or 1k Tokens",
                    "Alert",
                    JOptionPane.WARNING_MESSAGE);

        }


        return random(400, 700); //The amount of time in milliseconds before the loop starts over

    }

    @Override

    public void onPaint(Graphics2D g) {
        long millis = System.currentTimeMillis() - startTime;
        String timeStr = String.format("%02d min, %02d sec",
                TimeUnit.MILLISECONDS.toMinutes(millis),
                TimeUnit.MILLISECONDS.toSeconds(millis) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
        );

        g.setFont(new Font("Trebuchet MS", Font.PLAIN, 14));
        g.setColor(Color.WHITE);
        g.drawString("Time running: " + timeStr, 10, 250);
    }

}
  • Like 1
Link to comment
Share on other sites

Hi again, would someone be able to explain GUI to me.

All the GUI needs to be is very simple: Take in armour type, food type and token value.

Then pass this into the original java file above.

I however, have no idea what i'm doing.  Below is my attempt, i'd be really grateful if someone would be able to have a look and fix it or atleast point me in the right direction.

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
public class GuiSetup {
    private final JFrame jFrame;

    /*
    private JLabel armourType;
    private JLabel foodLabel;
    private JLabel tokenAmount;
    private JTextField foodName;
    private JTextField tokenName;
    private JTextField TokenAmount;
    */



         public GuiSetup() {
        jFrame = new JFrame("WarriorGuild Tokens");
        JPanel mainPanel = new JPanel();
        JLabel armourType;
        JLabel foodLabel;
        JLabel tokenAmounta;
        JTextField food;
        JTextField armourName;
        JTextField tokenAmount;

    }
/*
    public static String getFoodName()
    {
        return foodName;
    }

    public static String getArmourName()
    {
        return armourName;
    }

    public static String getTokenAmount()
    {
        return tokenAmount;
    }
    */
}

 

Link to comment
Share on other sites

12 minutes ago, scriptersteve said:

Hi again, would someone be able to explain GUI to me.

All the GUI needs to be is very simple: Take in armour type, food type and token value.

Then pass this into the original java file above.

I however, have no idea what i'm doing.  Below is my attempt, i'd be really grateful if someone would be able to have a look and fix it or atleast point me in the right direction.


import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
public class GuiSetup {
    private final JFrame jFrame;

    /*
    private JLabel armourType;
    private JLabel foodLabel;
    private JLabel tokenAmount;
    private JTextField foodName;
    private JTextField tokenName;
    private JTextField TokenAmount;
    */



         public GuiSetup() {
        jFrame = new JFrame("WarriorGuild Tokens");
        JPanel mainPanel = new JPanel();
        JLabel armourType;
        JLabel foodLabel;
        JLabel tokenAmounta;
        JTextField food;
        JTextField armourName;
        JTextField tokenAmount;

    }
/*
    public static String getFoodName()
    {
        return foodName;
    }

    public static String getArmourName()
    {
        return armourName;
    }

    public static String getTokenAmount()
    {
        return tokenAmount;
    }
    */
}

 

Create a thread in this section :)

https://osbot.org/forum/forum/249-scripting-help/

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...