Jump to content

npcs.closest lag


fre024

Recommended Posts

NPC beast = npcs.closest("beast name");

does this lag for someone else?

It uses alot of cpu power sad.png

 

 

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 by fre024
Link to comment
Share on other sites


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 by fre024
Link to comment
Share on other sites

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 by adc
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...