Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-02-2011, 09:15 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #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
  #3  
Old 03-02-2011, 10:41 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
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
Reply With Quote
  #4  
Old 03-03-2011, 04:37 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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;      
      }
    }

__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #5  
Old 03-05-2011, 03:00 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
bump... still need help...
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #6  
Old 03-05-2011, 03:41 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
use disabledefmovement and attackplayertoobj. There was a ladder help script a few weeks ago, use the forum search function.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #7  
Old 03-05-2011, 03:44 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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);

__________________
Quote:
Reply With Quote
  #8  
Old 03-05-2011, 04:50 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Quote:
Originally Posted by MrOmega View Post
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!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming

Last edited by kingcj; 03-05-2011 at 05:07 AM.. Reason: some more
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:08 AM.


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