Jump to content

Help with script


scriptersteve

Recommended Posts

There was a warriorguild tokens script that didn't work and the code was lying around so i am trying to fix it:

The first method works, however the second method doesn't. Mouse just hovers animate and was wondering why: help would be greatly appreciated.

Can copy paste full code if that wouldhelp but pretty sure it'sthis else statement that is broken.

Thanks :)

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));
        }
    }
}
Link to comment
Share on other sites

14 minutes ago, scriptersteve said:

There was a warriorguild tokens script that didn't work and the code was lying around so i am trying to fix it:

The first method works, however the second method doesn't. Mouse just hovers animate and was wondering why: help would be greatly appreciated.

Can copy paste full code if that wouldhelp but pretty sure it'sthis else statement that is broken.

Thanks :)


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));
        }
    }
}

 

Check that the hasArmour function returns true

Check that the object is actually called "Magical Animator", and is an object not an NPC

Check that the interaction is actually called "Animate"

Link to comment
Share on other sites

It's definately not an NPC, so think it is an object. hasArmour function must be true? as it loots mithril platebodies if they are on the floor which requires this function to be true (i think, how else could i check this?).

image.thumb.png.53cd8a72dbfaaa81271b7e0633e58bfd.png 

The object is called Magical Animator (case sensitive) IKR second one caps too. Left click option is called Animate in front off.

image.png.604b9d91f3530388a4dc86641b3c0b27.png

Bit stuck

Link to comment
Share on other sites

1 minute ago, scriptersteve said:

It's definately not an NPC, so think it is an object. hasArmour function must be true? as it loots mithril platebodies if they are on the floor which requires this function to be true (i think, how else could i check this?).

image.thumb.png.53cd8a72dbfaaa81271b7e0633e58bfd.png 

The object is called Magical Animator (case sensitive) IKR second one caps too. Left click option is called Animate in front off.

image.png.604b9d91f3530388a4dc86641b3c0b27.png

Bit stuck

 

Put a log statement inside hasArmour:

log("hasArmour is true")

Just to make sure it is infact returning true.

 

Are you sure you don't have to "Use" a piece of the armour *before* clicking on the Magical Animator?

Link to comment
Share on other sites

ah think i understand, when i did the followoing nothing was input into the logger

image.thumb.png.785e7148833534a6d29c2c7d479a7fa0.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";
    private String a1 = " platebody";
    private String a2 = "  full helm";
    private String a3 = " platelegs";
    String [] lootNames = {armorType.concat("a1"), "Warrior guild token", armorType.concat("a2"), armorType.concat("a3")};


    @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);
        if(hasArmour()!=true){
            log("false");
        }


        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);
    }

}

So, i think then the hasarmour function is incorrect, unable to quite see why though

 

Link to comment
Share on other sites

Yeah, just trying to fix that animated armour's script because it doesn't work at the moment. Have tried the changing but again it just hovers over the animate armour and doesn't click.

 

It's not the end of the world for me as I have d-defenders on all my accs and alts but it's a script i thought would be useful to get running again ;(.

 

if (getObjects().closest("Magical Animator").interact("Animate")) {
                            sleep(random(1200, 2000));

My only thought now is, is there a different way to write this so it left clicks on something?

Link to comment
Share on other sites

3 hours ago, scriptersteve said:

Okay, sorry everyone - turns out i was rebuilding the project and not the artefact which meant the jar wasn't being updated :'(. Now correctly attacks the warrior just doesn't look the mith so going to have a look at that later

The lootNames array is wrong. According to the code you last posted, it would contain this:

{"Mithril a1", "Mithril a2", "Mithril a3"}. Hint: This is wrong

Even if you fixed the concatenation, there's still a typo in the mithril full helm

Edited by FrostBug
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...