I'm not quite sure what you're asking, but I think you mean that you're trying to trigger NPCs when they've been attacked.
Let's create a simple function for it..
PHP Code:
// put this in a class like func_damage so you can reuse it
function attackNPCs(temp.attacker, temp.attackX, temp.attackY, temp.attackRadius) {
for (temp.npc : findAreaNPCs(temp.attackX - temp.attackRadius, temp.attackY - temp.attackRadius, temp.attackRadius * 2, temp.attackRadius * 2)) {
// you could do proper radius checking rather than a square with
// length of 2*radius, but this is easier and generally sufficient for your needs
temp.npc.trigger("attack", temp.attacker); // tell the NPC it's been attacked
}
}
Now in any NPCs, you can do
PHP Code:
function onAttack(temp.attacker) {
this.chat = "I was attacked by " @ temp.attacker.nick @ "!";
}
Then in your weapon, you can just do this:
PHP Code:
function onCreated() {
this.join("func_damage");
}
function onActionServerside(temp.command, temp.x, temp.y)
{
switch(temp.command){
case "attack":
this.attackNPCs(player, temp.x, temp.y, 1);
break;
}
}