Jump to content

How is my script?


tzhaarown

Recommended Posts

http://pastebin.com/0TmpyquE

 

I will implement node structure later.

package kfc;
 
import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.util.GraphicUtilities;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Condition;
 
import java.awt.*;
 
@ScriptManifest(author = "t", info = "Start at the Falador chicken farm", name = "KFC", logo = "", version = 1.00)
public class KFC extends Script {
 
    private static final Filter TARGET_FILTER = new Filter<NPC>() {
        @Override
        public boolean match(NPC npc) {
            return npc.getName().equals(Constants.TARGET_NAME) && npc.isAttackable()
                    && Constants.FALADOR_CHICKEN_FARM.contains(npc);
        }
    };
 
    private NPC target;
    private long lastAttack = System.currentTimeMillis();
 
    @Override
    public int onLoop() throws InterruptedException {
        final Player player = myPlayer();
 
        if (target == null) {
            getNewTarget();
        } else {
            if (target.exists() && target.getHealth() > 0 && Constants.FALADOR_CHICKEN_FARM.contains(target)) {
                if (target.isVisible()) {
                    if (!player.isInteracting(target)) {
                        if (player.isUnderAttack()) {
                            getCurrentTarget();
                        } else {
                            attack();
                        }
                    } else if (idle()) {
                        getNewTarget();
                    }
                } else {
                    reposition();
                }
            } else {
                getNewTarget();
            }
        }
 
        return random(10, 15);
    }
 
    private boolean idle() {
        return System.currentTimeMillis() - lastAttack > random((int) (Constants.FAIL_SAFE_TIMEOUT - (Constants.FAIL_SAFE_TIMEOUT * 0.1)), Constants.FAIL_SAFE_TIMEOUT) * 1000;
    }
 
    private void attack() {
        lastAttack = System.currentTimeMillis();
        if (!target.isUnderAttack()) {
            if (target.interact("Attack")) {
                dynamicSleep(new Condition() {
                    @Override
                    public boolean evaluate() {
                        return myPlayer().isInteracting(target);
                    }
                }, random(800, 1000));
            }
        } else {
            getNewTarget();
        }
    }
 
    private void reposition() {
        camera.toEntity(target);
        dynamicSleep(new Condition() {
            @Override
            public boolean evaluate() {
                return target.isVisible();
            }
        }, random(4000, 5000));
        if (!target.isVisible()) {
            getLocalWalker().walk(target);
            dynamicSleep(new Condition() {
                @Override
                public boolean evaluate() {
                    return myPlayer().isMoving();
                }
            }, random(4000, 5000));
        }
    }
 
    private void getCurrentTarget() {
        target = npcs.singleFilter(npcs.getAll(), new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                return npc.isInteracting(myPlayer()) && npc.getName().equals(Constants.TARGET_NAME)
                        && Constants.FALADOR_CHICKEN_FARM.contains(npc);
            }
        });
    }
 
    private void getNewTarget() {
        try {
            sleep(random(300, 400));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        target = npcs.closest(TARGET_FILTER);
    }
 
    public boolean dynamicSleep(Condition c, long timeout) {
        long start = System.currentTimeMillis();
        while (System.currentTimeMillis() - start < timeout && !c.evaluate()) {
            try {
                sleep(random(100, 110));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return c.evaluate();
    }
 
    @Override
    public void onPaint(Graphics2D g) {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
       
        if (target != null && target.isVisible()) {
            g.setColor(Color.CYAN);
            g.draw(GraphicUtilities.getModelArea(this.bot, target.getGridX(), target.getGridY(), target.getZ(), target.getModel()));
        }
    }
}
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...