Hurting an NPC
Once you set this.hp the object can be attacked by player It's automatically calculating the damage based on the players weapon, the NPC hp and the NPC armor/body level as defined in items.json. An example of a barrel which can be shot:
Example
function onUpdated() {
this.onRespawn();
}
function onMouseDown() {
this.say("HP: " + this.hp + "/" + this.maxhp, 3);
}
function onDeath(pl) {
this.chat = "killed by " + pl;
this.ani = "explode";
this.scheduleevent(1, "respawn");
}
function onRespawn() {
this.image = "barrel.png";
this.chat = "";
this.hp = this.maxhp = 50; //setting the HP to 50
}