PHP Code:
function onPlayerTouchesMe() {
this.chat = "I need an adult, I need an adult!";
}
But no, Cal, that wouldn't work because when you use 'with' the reference to this. changes to the NPC being called by 'with.' To circumvent that(because this. no longer refers to the NPC itself, but in this case the player) you use thiso. to reference the parent object, or the NPC. However he was referencing player which would be wrong in this case, as it should have been this.
Alternatively this can be done:
PHP Code:
for (temp.p: players) {
if (this.x in |temp.p.x, temp.p.x+3| && this.y in |temp.p.y, temp.p.y+3|) {
temp.p.chat = "The NPC touched me!";
}
}
However you may want to consider taking into account the width/height of the NPC for proper collision detection.