Open up your NPC.java and add these:
Code:
public int poisonTimer, poisonDelay;
public boolean poisonDmg;
Now find this line:
Code:
protected void appendHitUpdate(stream str) {
Replace that void with this:
Code:
protected void appendHitUpdate(stream str) {
try {
HP -= hitDiff;
if (HP <= 0) {
IsDead = true;
}
str.writeByteC(hitDiff); // What the npc got 'hit' for
if (hitDiff > 0 && !poisonDmg) {
str.writeByteS(1); // 0: red hitting - 1: blue hitting
} else if (hitDiff > 0 && poisonDmg) {
str.writeByteS(2); // 0: red hitting - 1: blue hitting
} else {
str.writeByteS(0); // 0: red hitting - 1: blue hitting
}
str.writeByteS(HP); // Their current hp, for HP bar
str.writeByteC(MaxHP); // Their max hp, for HP bar
poisonDmg = false;
} catch(Exception e) {
e.printStackTrace();
}
}
Now open your npcHandler.java and add this void:
Code:
public void poisonNpc(int index)
{
npcs[index].poisonDmg = true;
npcs[index].poisonDelay = misc.random(60);
npcs[index].hitDiff = misc.random(5);
npcs[index].hitDiff = npcs[index].hitDiff;
npcs[index].updateRequired = true;
npcs[index].hitUpdateRequired = true;
}
Then add this in process:
Code:
if (npcs[i].poisonTimer > 0) {
npcs[i].poisonTimer--;
}
if (npcs[i].poisonTimer == 0) {
npcs[i].poisonDmg = false;
npcs[i].poisonDelay = -1;
}
if (npcs[i].poisonDelay > 0) {
npcs[i].poisonDelay--;
}
if (npcs[i].poisonTimer > 0 && npcs[i].poisonDelay == 0){
poisonNpc(i);
}
Now when you want to poison an npc you use it like this:
Code:
if (server.npcHandler.npcs[index].poisonTimer <= 0)
{
server.npcHandler.npcs[index].poisonTimer = 120; //120 = (60 * 2) [60 = 30 seconds]
server.npcHandler.npcs[index].poisonDmg = true;
server.npcHandler.poisonNpc(index);
}
- Mr. Brightside