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.a = {player.x, player.y, 0};
    
temp.b = {thiso.x, thiso.y, 0};
    
temp.distance = vectordist(temp.a, temp.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.a = {thiso.x, thiso.y, thiso.x+2, thiso.y+2};
    if (
player.x > temp.a[0] && player.x < temp.a[2] && player.y > temp.a[1] && player.y < 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