Originally Posted by
Nighel
Hello,
First problem: So i was working on DKS on my server but then i noticed DKS are not aggresive (Yes i added them to the aggresive check) but they still wont attack ppl who are close
Second plroblem: NPC and Player combat when you attack an npc or player with range or mage it walks to the person (Yes i tryed the fixed that where released but didnt work)
Some help would be nice
here is my attack npc metod
in npchandler.java
Code:
/**
* Attacking npc
**/
if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && !switchesAttackers(i)) {
npcs[i].killerId = getCloseRandomPlayer(i);
} else if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && switchesAttackers(i)) {
npcs[i].killerId = getCloseRandomPlayer(i);
}
if (System.currentTimeMillis() - npcs[i].lastDamageTaken > 5000)
npcs[i].underAttackBy = 0;
if((npcs[i].killerId > 0 || npcs[i].underAttack) && !npcs[i].walkingHome && retaliates(npcs[i].npcType)) {
if(!npcs[i].isDead) {
int p = npcs[i].killerId;
if(PlayerHandler.players[p] != null) {
Client c = (Client) PlayerHandler.players[p];
if(FightCave.isCaveNpcs(i))
followInCave(i, c.playerId,true);
else
followPlayer(i, c.playerId);
if (npcs[i] == null) return;
if(npcs[i].attackTimer == 0) {
if(c != null) {
attackPlayer(c, i);
} else {
npcs[i].killerId = 0;
npcs[i].underAttack = false;
npcs[i].facePlayer(0);
}
}
} else {
npcs[i].killerId = 0;
npcs[i].underAttack = false;
npcs[i].facePlayer(0);
}
}
}
and add this in npchandler.java
Code:
public int getClosePlayer(int i) {
for (int j = 0; j < PlayerHandler.players.length; j++) {
if (PlayerHandler.players[j] != null) {
if (j == npcs[i].spawnedBy)
return j;
if (goodDistance(PlayerHandler.players[j].absX, PlayerHandler.players[j].absY, npcs[i].absX, npcs[i].absY, 2 + distanceRequired(i) + followDistance(i))) {
if ((PlayerHandler.players[j].underAttackBy <= 0 && PlayerHandler.players[j].underAttackBy2 <= 0) || PlayerHandler.players[j].inMulti())
if (PlayerHandler.players[j].heightLevel == npcs[i].heightLevel)
return j;
}
}
}
return 0;
}
public int getCloseRandomPlayer(int i) {
ArrayList<Integer> players = new ArrayList<Integer>();
for (int j = 0; j < PlayerHandler.players.length; j++) {
if (PlayerHandler.players[j] != null) {
if (goodDistance(PlayerHandler.players[j].absX, PlayerHandler.players[j].absY, npcs[i].absX, npcs[i].absY, 2 + distanceRequired(i) + followDistance(i))) {
if ((PlayerHandler.players[j].underAttackBy <= 0 && PlayerHandler.players[j].underAttackBy2 <= 0) || PlayerHandler.players[j].inMulti())
if (PlayerHandler.players[j].heightLevel == npcs[i].heightLevel)
players.add(j);
}
}
}
if (players.size() > 0)
return players.get(Misc.random(players.size() -1));
else
return 0;
}
Hope this will help you find out whate the problem is