Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Player on Npc (https://forums.graalonline.com/forums/showthread.php?t=134262284)

kingcj 03-02-2011 09:15 AM

Player on Npc
 
I've tried a variety of different ways, but they all seem inconsistent so I'll just show and ask. I'm trying to detect the player on an npc, which really seems easy enough but for some reason acts very strange with this code.

PHP Code:

if (player.this.&& player.this.x+&& player.this.&& player.this.y+2

Now I am doing this check in a timeout and clientside, and yes I did set a timer. What I see it doing is checking for the player inside these positions.
What it actually does is, sometimes it checks for the player.
My Timer is set at .1 so that's not the problem. Also i've played with the plus and minus from the this.x and this.y, but it just seems that it doesn't always catch the player on top of the npc which would be these coordinates.
Any suggestions would be awesome.

0PiX0 03-02-2011 10:14 AM

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.

Twinny 03-02-2011 10:41 AM

Slight side note but you can specify ranges rather than using multiple && e.g.

PHP Code:

  if (player.x in |this.xthis.x+5| && player.y in |this.y-5this.y|)
    
this.chat "FOUND YOU!"

I'd nest the y test but going off your example. Can still look neat(ish) without having to declare temp vars :)

kingcj 03-03-2011 04:37 AM

Ok so this is what I'm trying to accomplish with the player coordinate checks.
Its a ladder and I'm using a custom movement system. I need to place an enable and disable custom movement but I haven't yet.
This script seems to work fine if I come top down, but if I start at the bottom it doesn't work at all.
Any help is appreciated.

PHP Code:

//#CLIENTSIDE
function onTimeout() {
  if (
player.y in |y-.5,y+3|)
    
Movement.ReplaceAni("climbidle","idle");
    
Movement.ReplaceAni("climb","walk");
    
this.ladder false;
}

function 
onPlayerTouchsme() {
  if (
player.y in |y-.5,y+3|) { 
    
this.ladder false;}
  else {
  
player.dir 0
  
this.ladder true;
  
setTimer(0.1);   
  
Movement.ReplaceAni("idle","climbidle");
  
Movement.ReplaceAni("walk","climb");    
  }
}

function 
onKeyPressed(code,key) {
  if (
this.ladder) {
    
player.dir 0;
      if (
keydown(2)) { 
          
player.y+=0.3;
          
freezeplayer(.7);
      } else if (
keydown(0)) { 
          
player.y-=0.15;
          
freezeplayer(.4);
      } else if (
keydown(1)) {
          
player.dir 0;
          return;
      } else if (
keydown(3)) {
          
player.dir 0;
          return;      
      }
    }



kingcj 03-05-2011 03:00 AM

bump... still need help...

MrOmega 03-05-2011 03:41 AM

use disabledefmovement and attackplayertoobj. There was a ladder help script a few weeks ago, use the forum search function.

fowlplay4 03-05-2011 03:44 AM

Try something like this:

- Check if the player touched the ladder
- If touched, "attach" the player to ladder
- Disable the player's normal movement
- While "attached" make sure the player is still on the ladder and check for keystrokes, move the player if necessary.

PHP Code:

//#CLIENTSIDE
function onPlayerTouchsMe() {
  if (!
this.ladder) {
    
this.ladder true;
    
player.this.x;
    
setTimer(0.05);   
  } 
}

function 
onTimeout() {
  if (
player.y in |y-1.5y+3|) {
    if (
keydown(0)) player.-= 0.15;
    if (
keydown(2)) player.+= 0.3;
  } else {
    
this.ladder false;
    
Movement.ReplaceAni("idle","climbidle"); 
    
Movement.ReplaceAni("walk","climb");      
  }
  if (
this.laddersetTimer(0.05);



kingcj 03-05-2011 04:50 AM

Quote:

Originally Posted by MrOmega (Post 1634614)
use disabledefmovement and attackplayertoobj. There was a ladder help script a few weeks ago, use the forum search function.

Custom movement system..... disabledefmovement won't work and I don't believe attackplayertoobj is a real command. I've tried attachplayertoobj from that script, but I'm not use to using it.
Thanks MrOmega

Just seems when I use the player coordinates it doesn't function correctly. I tried this, and it's the same thing I was trying to accomplish just better, but it still doesn't seem to work. I guess I need to attachplayertoobj after all?
Thanks anyway fp4!


All times are GMT +2. The time now is 05:18 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.