[RUSE] NPC health bar issue
For those who don't know what I'm going on about, when an npc has a lot off hp, the hp bar displayed in the top right corner showing npc health resets too around 60k, and repeats until you kill the NPC. It should display the full npc hp in 1 bar.
Tried a few things and no results, I'll post the related code below, can anyone else figure it out? I'm sure it has something to do with the packet..
The packet it's self
Code:
case 207:
int flag = inStream.readUnsignedWord();// 1 player, 0 npc
int maxHealth = inStream.readUnsignedWord();
int currentHealth = inStream.readUnsignedWord();
int Max = inStream.readUnsignedWord();
int Current = inStream.readUnsignedWord();
currentEntityHealth = currentHealth;
maximumEntityHealth = maxHealth;
MaxHealth = Max;
CurrentHealth = Current;
RSInterface entityInterface = RSInterface.interfaceCache[41020];
//RSInterface entityInterface = RSInterface.interfaceCache[7799];
if (!getOption("constitution")) {
entityInterface.message = currentHealth/10 + " / " + maxHealth/10;
} else {
entityInterface.message = currentHealth + " / " + maxHealth;
}
opCode = -1;
return true;
The code that sends the packets too the client I believe
Code:
/**
* Sends the combat/entity information required to redraw the interface
* @param flag - player flag, 1 = player, 0 = npc
* @param maxHealth - maximum health of entity
* @param currentHealth - current health of entity
* @return
*/
public PacketSender sendEntityInterface(int flag, int maxHealth, int currentHealth, String entityName) {
PacketBuilder out = new PacketBuilder(207);
out.putShort(flag);
out.putShort(maxHealth);
out.putShort(currentHealth);
player.getSession().queueMessage(out);
sendEntityName(entityName);
player.sendParallellInterfaceVisibility(41020, true);
return this;
}
The method which calculates what data needs to be sent, correct me if I'm wrong..
Code:
public void handleEntityInterface(Character attacker, Character victim, int damage) {
if (attacker.isPlayer()) {
Player p = (Player) attacker;
if (victim.isPlayer()) {//plrs
Player v = (Player) victim;
int maximumHealth = v.getSkillManager().getMaxLevel(Skill.CONSTITUTION);
int currentHealth = v.getSkillManager().getCurrentLevel(Skill.CONSTITUTION);
String entityName = v.getUsername();
p.getPacketSender().sendEntityInterface(victim.isPlayer() ? 1 : 0, maximumHealth, currentHealth, entityName);
} else if (victim.isNpc()) {//npcs
NPC v = (NPC) victim;
int maximumHealth = v.getDefaultConstitution();
int currentHealth = v.getConstitution();
int id = v.getId();
NpcDefinition definition = NpcDefinition.forId(id);
int maxhp = definition.getHitpoints();
String entityName = v.getDefinition().getName();
p.getPacketSender().sendEntityInterface(victim.isPlayer() ? 1 : 0, maxhp, currentHealth, entityName);
}
}
}
The interface it's self.. Don't think it has anything to do with this
Code:
public static void entityInterface(TextDrawingArea wid[]) {
RSInterface tab = addInterface(41020);
addTransparentSpriteWSpriteLoader(41021, 947, 150);
addText(41022, " ", wid, 1, 0xffffff, true, true);
tab.message = " ";
tab.x = 2;
tab.y = 9;
tab.children(2);
tab.child(0, 41021, 0, 20);
tab.child(1, 41022, 63, 22);
}
If you want you can contact me on discord @ Ab#3264
Been trying to fix this on and off for the past 3 days. The code I posted is in original state, I've tried too manually set the NPC HP in the code too display too.