R I F T Posted November 25, 2018 Posted November 25, 2018 (edited) I'm trying to write my first script (classic chicken killer) and somewhat following Explvs Scripting 101 concepts. I'm trying to make a filter to then get the closest and attack that chicken. Here's my code: package core; import org.osbot.rs07.api.filter.Filter; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(name = "RIFTChickens", author = "R I F T", version = 1.0, info = "", logo = "") public class RIFTChickens extends Script { private final Area chickenCoop = new Area(3225, 3295, 3236, 3301); private final Area yardArea = new Area(3236, 3293, 3231, 3288); public Filter<Entity> chickenFilter = new Filter<Entity>() { @Override public boolean match(final Entity entity) { return entity.getName() == "Chicken" && (chickenCoop.contains(entity) || yardArea.contains(entity)); } }; @Override public void onStart() { //Code here will execute before the loop is started } @Override public void onExit() { //Code here will execute after the script ends } @Override public int onLoop() { if (!isAttacking()) { Entity targetChicken = getNpcs().closest(chickenFilter); if (targetChicken != null) { targetChicken.interact("Attack"); } } return random(300, 400); //The amount of time in milliseconds before the loop starts over } @Override public void onPaint(Graphics2D g) { //This is where you will put your code for paint(s) } private boolean isAttacking() { return myPlayer().isMoving() || myPlayer().isAnimating() || myPlayer().isUnderAttack(); } } The error that I am getting is... The method closest(String...) in the type EntityAPI<NPC> is not applicable for the arguments (Filter<Entity>) ... which happens on this line ... Entity targetChicken = getNpcs().closest(chickenFilter); I've been playing around with it for about 45 minutes but I can't seem to solve it. Any ideas? EDIT: Solved my problem. Changed this... public Filter<Entity> chickenFilter = new Filter<Entity>() { @Override public boolean match(final Entity entity) { return entity.getName() == "Chicken" && (chickenCoop.contains(entity) || yardArea.contains(entity)); } }; ...to... public Filter<NPC> chickenFilter = new Filter<NPC>() { @Override public boolean match(final NPC entity) { return entity.getName().startsWith("Chicken") && (chickenCoop.contains(entity) || yardArea.contains(entity)); } }; Still have the question as to why Explv could do it the original way, so if anyone knows please let me know (new to Java). Edited November 25, 2018 by R I F T Solved issue
Explv Posted November 25, 2018 Posted November 25, 2018 1 hour ago, R I F T said: entity.getName() == "Chicken" If you want to compare String values, you should use .equals() entity.getName().equals("Chicken") == Compares Object references, not values
R I F T Posted November 25, 2018 Author Posted November 25, 2018 57 minutes ago, Explv said: If you want to compare String values, you should use .equals() entity.getName().equals("Chicken") == Compares Object references, not values Aha... I'd just changed it to use a workaround checking if the entity.getName starts with "Chicken". I'll remove that now. Thanks for that