boyyo11 Posted December 5, 2014 Share Posted December 5, 2014 So before I got to serious into the script I was at vwest and tried to make a simple fighter that would kill guards, after that id make my script for me to get max cb, but I cant seem to make it work out. The one I made will attempt to try and click one after a min of following it with the mouse, than it will interact with it, than it will fight it, than wont do anything, it seems to not loop at all even tho I know it clearly does. Here is my script as it is, id like to add camera movement as well if that isnt in the interact with method already, Im not sure but seems to be but this script has so many bugs idk what is right or wrong. Thanks a bunch! package com.embah.AIOFighter; import java.awt.Graphics2D; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.Area; @ScriptManifest(author = "Boyyo11", info = "AIO Fighter for 99 combat in the stat of your choice!", name = "AIO FIGHTER", version = 0, logo = "oo embah forever oo") public class AIOFighter extends Script{ private Area fightingLocation = new Area(3169, 3423, 3184, 3432); private Area bankLocation; private boolean isBanking; private Walker walker; private int[] startPoint = new int[2]; private int[] endPoint = {3185, 3436}; private NPC guard; private String status = "Loading"; @Override public void onStart() throws InterruptedException { } @Override public int onLoop() throws InterruptedException { status = "In Loop: "; guard = npcs.closest(3011); if(guard != null){ status = "In Loop: guard != null"; if(!guard.isVisible()){ status = "In Loop: guard is not visible"; // while(camera.toEntity(guard) != true){ // status = "In Loop: moving camera to guard than waiting"; // sleep(random(300, 400)); // } } else if(!guard.isUnderAttack() && fightingLocation.contains(guard) && myPlayer().isAttackable()){ status = "In Loop: Attacking if guard is in location and both opponents arent under attack"; guard.interact("Attack"); sleep(random(100, 200)); } else { status = "In Loop: Sleeping because nothing else worked, prolly no guards"; sleep(random(500, 600)); } } return random(50, 100); } @Override public void onExit() { log("Cya later!"); } @Override public void onPaint(Graphics2D g) { g.drawString(status, 5, 10); } } Link to comment Share on other sites More sharing options...
thelegacy0 Posted December 5, 2014 Share Posted December 5, 2014 Strip it to the very basics and see if that works, then work on adding if visible and attackable and stuff. Like, this is all my fighter has: int fighting() { if(!myPlayer().isUnderAttack()) { NPC npc = getNpcs().closest("Guard"); if(npc.exists()) //add loop for finding attackable ones npc.interact("Attack"); else this.stop(); } return 1000; } Start with just attacking, then work on finding out if they're attackable and stuff. Use enums, don't having everything running in your onLoop(). My fighter has eating, teleporting, and attacking and is 75 lines long, finished Link to comment Share on other sites More sharing options...
Czar Posted December 6, 2014 Share Posted December 6, 2014 (edited) public NPC getTarget(final String npc) { return getNpcs().closest(new Filter<NPC>() { public boolean match(NPC n) { if (!n.getName().equalsIgnoreCase(npc)) { return false; } if (n.getInteracting() != null) { return false; } return true; } }); } You can use a Filter<> to to find the best npc, in this case it's the npc which isn't interacting with anything, and is called whatever you put in the getTarget method, so: NPC guard = getTarget("Guard"); if (guard != null) { // attack } And it will attack every NPC with the name 'guard', also, try to use names instead of IDs when it comes to npcs and objects, since the IDs can change from time to time. You can greatly expand on the filter by adding more stuff like getMap().canReach for extra failsafes etc. As for the camera movement, the while() is unnecessary because you are already checking if its visible. Edited December 6, 2014 by Czar Link to comment Share on other sites More sharing options...
boyyo11 Posted December 6, 2014 Author Share Posted December 6, 2014 (edited) Strip it to the very basics and see if that works, then work on adding if visible and attackable and stuff. Like, this is all my fighter has: int fighting() { if(!myPlayer().isUnderAttack()) { NPC npc = getNpcs().closest("Guard"); if(npc.exists()) //add loop for finding attackable ones npc.interact("Attack"); else this.stop(); } return 1000; } Start with just attacking, then work on finding out if they're attackable and stuff. Use enums, don't having everything running in your onLoop(). My fighter has eating, teleporting, and attacking and is 75 lines long, finished thanks man, as for the loop should I just use getAll, cause as it sits that only returns one npc. public NPC getTarget(final String npc) { return getNpcs().closest(new Filter<NPC>() { public boolean match(NPC n) { if (!n.getName().equalsIgnoreCase(npc)) { return false; } if (n.getInteracting() != null) { return false; } return true; } }); } You can use a Filter<> to to find the best npc, in this case it's the npc which isn't interacting with anything, and is called whatever you put in the getTarget method, so: NPC guard = getTarget("Guard"); if (guard != null) { // attack } And it will attack every NPC with the name 'guard', also, try to use names instead of IDs when it comes to npcs and objects, since the IDs can change from time to time. You can greatly expand on the filter by adding more stuff like getMap().canReach for extra failsafes etc. As for the camera movement, the while() is unnecessary because you are already checking if its visible. kool, prolly use this cause the filter works well used it for rsb0+ along time ago, and as for the camera movement why wouldnt I use while() while im moving camera or does camera move until it hits the location. Cause I know if its not visible itll move but I dont want it to do something else before we move the camera. @Edit- There seems to be alot of lag still when interacting with the guard, which seems to be the biggest problem now:/ Edited December 6, 2014 by boyyo11 Link to comment Share on other sites More sharing options...