Thread: Player on Npc
View Single Post
  #2  
Old 03-02-2011, 10:14 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
I assume there is a reason you would like to use a timeout in your code for this.
This should determine when the player is within the circle with a radius of 1 tile:
PHP Code:
//#CLIENTSIDE
function onCreated() {
    
onTimeout();
}

function 
onTimeout() {
    
temp.= {player.xplayer.y0};
    
temp.= {thiso.xthiso.y0};
    
temp.distance vectordist(temp.atemp.b);
    if (
temp.distance 1) {
        echo(
"touching npc");
    } else {
        echo(
"not touching npc");
    }
    
setTimer(0.1);

If you wanted to test if the player is within a 2x2 square this should work:
PHP Code:
//#CLIENTSIDE
function onCreated() {
    
onTimeout();
}

function 
onTimeout() {
    
temp.= {thiso.xthiso.ythiso.x+2thiso.y+2};
    if (
player.temp.a[0] && player.temp.a[2] && player.temp.a[1] && player.temp.a[3]) {
        echo(
"touching npc");
    } else {
        echo(
"not touching npc");
    }
    
setTimer(0.1);

If you do not want to use a timeout:
PHP Code:
//#CLIENTSIDE
function onCreated() {
    
setshape(1,32,32);
}

function 
onPlayerTouchsMe() {
    echo(
"touching npc without a timeout");

I haven't tested these examples but I hope they help you.
__________________
Reply With Quote