use a timeout and use checks
PHP Code:
function onCreated()
{
this.width = <WIDTH>; //In Tiles
this.height = <HEIGHT>; //In Tiles
onTimeout();
}
function onTimeout()
{
if ( player.x + 1.5 in | this.x, this.width| &&
player.y + 2.0 in | this.y, this.height| &&
!this.touch)
{
this.touch = true;
//Touch Actions
}
if ( !( player.x + 1.5 in | this.x, this.width|) &&
!( player.y + 2.0 in | this.y, this.height|) &&
this.touch)
{
this.touch = false;
//Stop Touch Actions
}
setTimer( 0.1);
}
replace <WIDTH> and <HEIGHT> with the NPCs width and height in tiles, not pixels. ( 1 pixel would equal ( 1 / 16), btw)