hey this is my tutorial about make npc's automatic attack you (explained)
don't know if it's posted before if it is a mod please delete this
we will start :
first off you need to choose an npc wich you want to automatic attack you.
i choosed and zamorak battle mage (id =912)
ok so now go into npchandler.java and search for:
under the last } there add:
Code:
{//battle mage zamorak
for (Player p : server.playerHandler.players)
{
client person = (client)p;
if(p != null && person != null)
{
if(p != null && person != null)
{
if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) <= 5 && person.heightLevel == npcs[i].heightLevel)
if (npcs[i].npcType == 912)
{
npcs[i].StartKilling = person.playerId;
npcs[i].RandomWalk = false;
npcs[i].IsUnderAttack = true;
} else if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) >= 5 || person.heightLevel != npcs[i].heightLevel)
if (npcs[i].npcType == 912)
{
npcs[i].RandomWalk = true;
}
}
}
}
}
change the 912 to your npc id.
what does this do? this makes it so that if your in range of the npc it will attack you.
next search for:
Code:
npcs[i].updateRequired = true;
u should see something like:
Code:
} else if (npcs[i].RandomWalk == false && npcs[i].IsUnderAttack == true) {
if(npcs[i].npcType == 1645 || npcs[i].npcType == 1241 || npcs[i].npcType == 1246 || npcs[i].npcType == 1159 || npcs[i].npcType == 54)
AttackPlayerMage(i);
else
AttackPlayer(i);
add all those ids add:
Code:
npcs[i].npcType == 912 ||
after the || 's
again change the 912 to your npc id
next search for:
Code:
if(npcs[i].StartKilling > 0) {
u shuld see something like:
Code:
if(npcs[i].npcType == 1645 || npcs[i].npcType == 1246 || npcs[i].npcType == 54)
AttackPlayerMage(i);
else
AttackPlayer(i);
}
}
else {
FollowPlayer(i);
}
again add:
Code:
npcs[i].npcType == 1246
after the || 's
next search for:
Code:
if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) >= 5)
u should see this:
Code:
if (npcs[i].npcType != 1158 || npcs[i].npcType == 2745 || npcs[i].npcType == 2745)
{
npcs[i].RandomWalk = true;
}
}
}
}
again add:
Code:
npcs[i].npcType == 2745 ||
after the two || 's and change the 912 to your npc id
next search for:
Code:
if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) <= 20 && p.heightLevel == npcs[i].heightLevel)
u should see:
Code:
if (npcs[i].npcType == 1158 || npcs[i].npcType == 2745 )
{
npcs[i].StartKilling = person.playerId;
npcs[i].RandomWalk = false;
npcs[i].IsUnderAttack = true;
again add:
Code:
npcs[i].npcType == 912 ||
and change the 912 to your npc ID
now the intresting part comes:
we now gonna add how the (in my case zamorak battle mages attack you)
search for:
Code:
if (server.playerHandler.players[Player].IsDead == true) {
u should see:
Code:
if (server.playerHandler.players[Player].IsDead == true) {
ResetAttackPlayer(NPCID);
} else {
npcs[NPCID].animNumber = 711; // mage attack
if(npcs[NPCID].npcType == 1645) {
p.stillgfx(369, p.absY, p.absX);
hitDiff = 6 + misc.random(43);
}
after the last } add:
Code:
if(npcs[NPCID].npcType == 912) { //battle mage zamorak
p.stillgfx(369, p.absY, p.absX);
hitDiff = 2 + misc.random(20);
}
il explain the code: the 369 is the gfx (this case ice barrage) change that to wich you want [Only registered and activated users can see links. ]
for the gfx id's credits going to ant for this list.
the:
is how high he hits change the 20 higher or lower if u want them to hit higher/lower
as last search for:
Code:
public boolean AttackNPCMage(int NPCID) {
now u should see:
Code:
int EnemyX = server.npcHandler.npcs[npcs[NPCID].attacknpc].absX;
int EnemyY = server.npcHandler.npcs[npcs[NPCID].attacknpc].absY;
int EnemyHP = server.npcHandler.npcs[npcs[NPCID].attacknpc].HP;
int hitDiff = 0;
int Npchitdiff = 0;
int wepdelay = 0;
//hitDiff = misc.random(npcs[NPCID].MaxHit);
if (npcs[NPCID].actionTimer == 0) {
if (server.npcHandler.npcs[npcs[NPCID].attacknpc].IsDead == true) {
ResetAttackNPC(NPCID);
//npcs[NPCID].textUpdate = "Oh yeah I win bitch!";
//npcs[NPCID].textUpdateRequired = true;
npcs[NPCID].animNumber = 2103;
npcs[NPCID].animUpdateRequired = true;
npcs[NPCID].updateRequired = true;
under that u see:
Code:
} else {
npcs[NPCID].animNumber = 711; // mage attack
if(npcs[NPCID].npcType == 1645) {
gfxAll(369, EnemyY, EnemyX);
hitDiff = 6 + misc.random(43);
}
now under the last bracket of this code add:
Code:
if(npcs[NPCID].npcType == 912) {
gfxAll(369, EnemyY, EnemyX);
hitDiff = 2 + misc.random(20);
}
i explained the code earlier change the id to your npc id!
this whas my tut i hope i helped yah rep apreciated!
don't flame me if this is already posted it will be deleted then
credits:
npchandler.java: i think me
gfx list: ant
thanks for reading
arvidje136