fre024 Posted September 5, 2014 Share Posted September 5, 2014 (edited) NPC beast = npcs.closest("beast name"); does this lag for someone else? It uses alot of cpu power or it is this method interact.beast("Attack"); full code public boolean killbeast() throws InterruptedException { NPC beast = npcs.closest("beast"); // Player p = myPlayer(); Mylog("2"); loot(); Mylog("3"); if (combat.isFighting()) { Mylog("4"); Mylog("Already attacking beast"); spec(10); if (random(100) == 1) { combat.getFighting().interact("Attack"); } if (fillLootingBag()) { lootingBagEmpty = false; } return true; } Mylog("5"); if (!beast.isVisible()) { camera.toEntity(beast, true); } Mylog("6"); if (beast.isVisible()){ return public boolean killbeast() throws InterruptedException { NPC beast = npcs.closest("beast"); // Player p = myPlayer(); Mylog("2"); loot(); Mylog("3"); if (combat.isFighting()) { Mylog("4"); Mylog("Already attacking beast"); spec(10); if (random(100) == 1) { combat.getFighting().interact("Attack"); } if (fillLootingBag()) { lootingBagEmpty = false; } return true; } Mylog("5"); if (!beast.isVisible()) { camera.toEntity(beast, true); } Mylog("6"); if (beast.isVisible()){ return beast.interact("Attack"); } return false; } Edited September 5, 2014 by fre024 Link to comment Share on other sites More sharing options...
darkxor Posted September 5, 2014 Share Posted September 5, 2014 (edited) I know objects.closest() uses many CPU - because there can be 1000s objects loaded. Check NPC amount npcs.getAll() - if they're a little - then i think it should'nt consume much. And you can just call getAll() and then iterate yourself and compare CPU usage. Edited September 5, 2014 by darkxor Link to comment Share on other sites More sharing options...
Botre Posted September 5, 2014 Share Posted September 5, 2014 Depends on the amount of NPCs it has to iterate through. Link to comment Share on other sites More sharing options...
Pandemic Posted September 5, 2014 Share Posted September 5, 2014 It does use quite a bit of processing power, make sure you're not doing that every loop, because you'll notice a big hit in performance. Only use it when you have to Link to comment Share on other sites More sharing options...
FrostBug Posted September 5, 2014 Share Posted September 5, 2014 Shouldn't noticable really. Can we see the code where the issue occurs? I have a feeling that you may be calling the method more often than required.. Eg. with no sleep inbetween. This would make it noticable. Link to comment Share on other sites More sharing options...
fre024 Posted September 5, 2014 Author Share Posted September 5, 2014 (edited) public boolean killbeast() throws InterruptedException { NPC beast = npcs.closest("beast"); // Player p = myPlayer(); Mylog("2"); loot(); Mylog("3"); if (combat.isFighting()) { Mylog("4"); Mylog("Already attacking beast"); spec(10); if (random(100) == 1) { combat.getFighting().interact("Attack"); } if (fillLootingBag()) { lootingBagEmpty = false; } return true; } Mylog("5"); if (!beast.isVisible()) { camera.toEntity(beast, true); } Mylog("6"); if (beast.isVisible()){ return beast.interact("Attack"); } return false; } Edited September 5, 2014 by fre024 Link to comment Share on other sites More sharing options...
adc Posted September 5, 2014 Share Posted September 5, 2014 (edited) First and foremost, help us help you by formatting your code in a readable fashion: public boolean killbeast() throws InterruptedException { NPC beast = npcs.closest("beast"); // Player p = myPlayer(); Mylog("2"); loot(); Mylog("3"); if (combat.isFighting()) { Mylog("4"); Mylog("Already attacking beast"); spec(10); if (random(100) == 1) { combat.getFighting().interact("Attack"); } if (fillLootingBag()) { lootingBagEmpty = false; } return true; } Mylog("5"); if (!beast.isVisible()) { camera.toEntity(beast, true); } Mylog("6"); if (beast.isVisible()){ return beast.interact("Attack"); } return false; } You don't appear to have any sleeps, so that's not exactly helping your cpu usage. You should find your target NPC in a seperate method from the one you use for interaction, as your target shouldn't be changing between interaction loops (assuming the first was successful), i.e. NPC beast; if(!beast.isAValidTarget) { beast = npcs.getClosest("beast"); } killBeast(beast); Edited September 5, 2014 by adc Link to comment Share on other sites More sharing options...
fre024 Posted September 5, 2014 Author Share Posted September 5, 2014 Thx for the reply. I 'll keep in mind to formatting the code. I find the target in a seperate method now, still the same lag The script runs fine, just want to reduce cpu usage. Link to comment Share on other sites More sharing options...