View Single Post
  #10  
Old 06-05-2012, 05:04 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.pplayers) {
  if (
this.x in |temp.p.xtemp.p.x+3| && this.y in |temp.p.ytemp.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.
Reply With Quote