sesamest
Members-
Posts
8 -
Joined
-
Last visited
-
Feedback
0%
Profile Information
-
Gender
Male
Recent Profile Visitors
591 profile views
sesamest's Achievements
Newbie (1/10)
0
Reputation
-
I cannot seem to find isInCombat() in the API. I can only seem to find isUnderAttack(). I think I will check if the character is facing the NPC, and I will just have to store the NPC a variable outside the loop.
-
Does that directly affect why it is not recognizing that the area contains the player?
-
My KillCows Class: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tasks; import core.Constants; import core.Task; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.osbot.script.MethodProvider; import static org.osbot.script.MethodProvider.random; import org.osbot.script.Script; import org.osbot.script.ScriptManifest; import org.osbot.script.mouse.RectangleDestination; import org.osbot.script.rs2.map.Position; import org.osbot.script.rs2.model.GroundItem; import org.osbot.script.rs2.model.NPC; import org.osbot.script.rs2.model.RS2Object; import org.osbot.script.rs2.ui.Option; /** * * @author LivingRoom */ public class KillCows extends Task { List<NPC> NPCList; Thread CameraThread; public KillCows(Script sA) { super(sA); } @Override public String status() { return status; } String status = "Killing Cows"; @Override public boolean validate() throws InterruptedException { //return Constants.FARM_AREA.contains(sA.client.getMyPlayer().getPosition()); return (!sA.client.getInventory().isFull()) && sA.client.getMyPlayer().getPosition().getY() <= 3313; } public void TurnCameraToGroundItem(final GroundItem npc) { CameraThread = null; CameraThread = new Thread(new Runnable() { @Override public void run() { try { sA.client.moveCameraToPosition(npc.getPosition()); } catch (InterruptedException ex) { Logger.getLogger(KillCows.class.getName()).log(Level.SEVERE, null, ex); } } }); CameraThread.start(); } public void TurnCameraToNPC(final NPC npc) { CameraThread = null; CameraThread = new Thread(new Runnable() { @Override public void run() { try { sA.client.moveCameraToPosition(npc.getPosition()); } catch (InterruptedException ex) { Logger.getLogger(KillCows.class.getName()).log(Level.SEVERE, null, ex); } } }); CameraThread.start(); } public void setRun() throws InterruptedException { if (sA.client.getRunEnergy() > (15 + MethodProvider.random(0, 35)) && !sA.isRunning()) { sA.setRunning(true); } } @Override public boolean execute() throws InterruptedException { NPCList = sA.closestNPCList(Constants.COWS); setRun(); for(NPC npc : NPCList) { if(sA.client.getMyPlayer().isUnderAttack()) { sA.log("HOVER AREA"); TurnCameraToNPC(npc); while(sA.client.getMyPlayer().isUnderAttack()) { if(npc.isVisible() && !sA.client.isMenuOpen()) { for(Option opt : sA.client.getMenu().subList(0, sA.client.getMenu().size())) { if(!opt.action.contains("Attack") && !opt.noun.contains("Cow")) { sA.client.moveMouseTo(npc.getMouseDestination(), false, false, true); } } } sA.sleep(250); if(npc.isUnderAttack()) break; } if(sA.client.isMenuOpen()) { for(Option opt : sA.client.getMenu().subList(0, sA.client.getMenu().size())) { if(opt.action.contains("Attack") && opt.noun.contains("Cow")) { if(!npc.isUnderAttack()) if(npc.getHealth() == 100) npc.interact("Attack"); } } } } if(!npc.isUnderAttack()) { if(!npc.isVisible()) { TurnCameraToNPC(npc); if(npc.getPosition().distance(sA.client.getMyPlayer().getPosition()) >= 12) { sA.walk(new Position(npc.getPosition().getX()+random(-2,2), npc.getPosition().getY()+random(-2,2), 0)); } } if(npc.getHealth() == 100) npc.interact("Attack"); sA.sleep(random(500,700)); while(sA.client.getMyPlayer().isMoving()) { sA.sleep(250); } sA.sleep(random(500,700)); while(npc.getHealth() == 100) { if(!sA.client.getMyPlayer().isUnderAttack()) break; sA.sleep(250); } } } GroundItem cowhide = sA.closestGroundItem(Constants.COWHIDE); while(cowhide != null) { if(!cowhide.isVisible()) { TurnCameraToGroundItem(cowhide); if(cowhide.getPosition().distance(sA.client.getMyPlayer().getPosition()) >= 12) { sA.walk(new Position(cowhide.getPosition().getX()+random(-2,2), cowhide.getPosition().getY()+random(-2,2), 0)); } } cowhide.interact("Take"); sA.sleep(random(500,700)); while(sA.client.getMyPlayer().isMoving()) { sA.sleep(250); } sA.sleep(random(500,700)); } return true; } } I understand the function Execute is rather large. I'll clean it up later and optimize it, but right now it attacks the first cow, then moves onto the next one right away without waiting for the cow to die. Also I am having an issue with the script recognizing whether it is inside an area. This is for the validate function. public boolean validate() throws InterruptedException { return (!sA.client.getInventory().isFull()) && Constants.FARM_AREA.contains(sA.client.getMyPlayer().getPosition()); } and the area FARM_AREA: public static Area FARM_AREA = new Area(3021, 3297, 3313, 3042); the first two integers being the x,y of the SW tile, and the second two integers the NE tile. I thank you for any help received + advice!
-
Thank you for this.
-
That is terrible of me. Thank you very much for being so in-depth in reading my lazy code.
-
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package core; import org.osbot.script.Script; /** * * @author LivingRoom */ public abstract class Node { public Script sA; public Node(Script A) { this.sA = sA; } public String status() { return ""; } public abstract boolean validate() throws InterruptedException; public abstract boolean execute() throws InterruptedException; } Node class. and by goodness, you guys are incredibly prompt at helping! EDIT: changed the validate to return this: return sA.closestObject(BANKOBJECT_ID) != null; but still causes an NullPointerException
-
MainClass: import core.*; import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; import java.util.Collections; import java.util.List; import nodes.*; import org.osbot.script.Script; import org.osbot.script.ScriptManifest; @ScriptManifest(author = "sesamest", info = "Version 0.02", name = "Cow Killer/Hide Grabber", version = 0) public class MainClass extends Script { private String status = ""; private List<Node> nodes = new ArrayList<>(); @Override public void onStart() { nodes.add(new Banking(this)); } @Override public int onLoop() throws InterruptedException { for(Node n : nodes) { if(n.validate()) { status = n.status(); if(n.execute()) { return random(200,400); } } } return random(200, 310); } @Override public void onExit() { log("Thanks for using this wonderful script!"); } @Override public void onPaint(Graphics g) { g.setColor(Color.black); g.drawString(status, 6, 6); g.setColor(Color.white); g.drawString(status, 5, 5); } } Banking Node Class: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package nodes; import core.Constants; import core.Node; import org.osbot.script.Script; import org.osbot.script.ScriptManifest; import org.osbot.script.rs2.model.RS2Object; /** * * @author LivingRoom */ public class Banking extends Node { private static final int[] BANKOBJECT_ID = { 24101 }; public Banking(Script sA) { super(sA); } @Override public String status() { return "Banking"; } private boolean isBoothVisible() { return true; /* RS2Object booth = sA.closestObject(BANKOBJECT_ID); if(booth != null) if(booth.getPosition().distance(sA.myPosition()) <= 5) return true; return false; */ } @Override public boolean validate() throws InterruptedException { return sA.client.getLocalNPCs().contains("Banker"); } public boolean openBank() throws InterruptedException { RS2Object booth = sA.closestObject(BANKOBJECT_ID); if (booth != null) { if(!booth.isVisible()) { sA.client.moveCameraToPosition(booth.getPosition()); } if (booth.interact("Bank")) { while (!sA.client.getBank().isOpen()) sA.sleep(250); sA.client.getBank().depositAll(); } } return false; } @Override public boolean execute() throws InterruptedException { if(sA.client.getInventory().contains(Constants.COWHIDE)){ if(openBank()) { } } return true; } } I believe myself to be relatively capable of programming in Java. It is odd that it keeps throwing a NullPointerException on Line 43 Validate() function. Any advice would be helpful. I believe it is something to do with the Script object being null when parsed to the Banking class.