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 01-21-2007, 12:12 PM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
Damn move()

NPC Code:

this.movex = playerx - x; // x needed to travel to player
this.movey = playery - y; // y needed to travel to player
if (player.dir=1){ this.desx = 1.7; this.desy = 1; }
if (player.dir=0) { this.desx = -1.7; this.desy = 1; }
if (player.dir=2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir=3) { this.desx = -1.7; this.desy = -1.7; }
setCharAni("walk","");
move(this.movex+this.desx,this.movey+this.desy,1,1 );
setCharAni("idle","");



Inefficient, I know, but it gets the job done.

Basically, it's supposed to move the npc so it looks like it's standing next to me. Problem is, i'm an aesthetics freak, and the fact that it just glides along concerns me. How would I go about making the npc use the walk gani through the move sequence?
__________________

I hope for nothing. I fear nothing. I am free.
Reply With Quote
  #2  
Old 01-21-2007, 12:32 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
HTML Code:
function onCreated()
{
  this.showCharacter();
  
  this.curPlayer = findPlayer("cHANDLER");
  this.onTimeout();
}
function onTimeout()
{
  temp.movex = this.curPlayer.x - x; // x needed to travel to player
  temp.movey = this.curPlayer.y - y; // y needed to travel to player
  dir = getdir(temp.movex, temp.movey);
  
  if (player.dir == 1) { this.desx = 1.7;   this.desy = 1;    }
  if (player.dir == 0) { this.desx = -1.7;  this.desy = 1;    }
  if (player.dir == 2) { this.desx = 1.7;   this.desy = -1.7; }
  if (player.dir == 3) { this.desx = -1.7;  this.desy = -1.7; }
 
  this.ani = "walk";
  move((temp.movex + this.desx), (temp.movey + this.desy), 1, 1);
}
function onMovementFinished()
{
  this.ani = "idle";
  this.onTimeout();
}
Mainly, you should focus on the "onMovementFinished()" function.
That's how I was testing it, however it wasn't finishing the movement. (Wasn't calling "onMovementFinished()")
Reply With Quote
  #3  
Old 01-21-2007, 05:26 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Chandler View Post
HTML Code:
function onCreated()
{
  this.showCharacter();
  
  this.curPlayer = findPlayer("cHANDLER");
  this.onTimeout();
}
function onTimeout()
{
  temp.movex = this.curPlayer.x - x; // x needed to travel to player
  temp.movey = this.curPlayer.y - y; // y needed to travel to player
  dir = getdir(temp.movex, temp.movey);
  
  if (player.dir == 1) { this.desx = 1.7;   this.desy = 1;    }
  if (player.dir == 0) { this.desx = -1.7;  this.desy = 1;    }
  if (player.dir == 2) { this.desx = 1.7;   this.desy = -1.7; }
  if (player.dir == 3) { this.desx = -1.7;  this.desy = -1.7; }
 
  this.ani = "walk";
  move((temp.movex + this.desx), (temp.movey + this.desy), 1, 1);
}
function onMovementFinished()
{
  this.ani = "idle";
  this.onTimeout();
}
Mainly, you should focus on the "onMovementFinished()" function.
That's how I was testing it, however it wasn't finishing the movement. (Wasn't calling "onMovementFinished()")
You need to add 8 to the move options to trigger that.

And, for better, and smooth movement (time wise),
use this:

PHP Code:
dist = ( dx dy 2) ^ 0.5;
movedxdydist tilespersecondflags); 
__________________
Reply With Quote
  #4  
Old 01-21-2007, 05:32 PM
konidias konidias is offline
Old Bee
konidias's Avatar
Join Date: Jul 2001
Location: Orlando, FL
Posts: 7,222
konidias will become famous soon enough
Send a message via AIM to konidias
Quote:
Originally Posted by Chandler View Post
HTML Code:
function onCreated()
{
  this.showCharacter();
  
  this.curPlayer = findPlayer("cHANDLER");
  this.onTimeout();
}
function onTimeout()
{
  temp.movex = this.curPlayer.x - x; // x needed to travel to player
  temp.movey = this.curPlayer.y - y; // y needed to travel to player
  dir = getdir(temp.movex, temp.movey);
  
  if (player.dir == 1) { this.desx = 1.7;   this.desy = 1;    }
  if (player.dir == 0) { this.desx = -1.7;  this.desy = 1;    }
  if (player.dir == 2) { this.desx = 1.7;   this.desy = -1.7; }
  if (player.dir == 3) { this.desx = -1.7;  this.desy = -1.7; }
 
  this.ani = "walk";
  move((temp.movex + this.desx), (temp.movey + this.desy), 1, 8+16);
}
function onMovementFinished()
{
  this.ani = "idle";
  this.onTimeout();
}
Like that. The 8 in bold means "inform when done" which lets you use "onMovementFinished". The 16 is for making sure the npc faces the direction it's moving. Otherwise it's just gonna be facing down or whatever while it walks.
__________________

Put this image in your sig if you support Bomy Island! (g2k1 revision)
play bomberman while you wait!


Reply With Quote
  #5  
Old 01-22-2007, 04:35 AM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
It's still stuck on the walk gani even when it's supposed to be idling.

onMovementFinished doesn't appear to be called, even with 8+16

EDIT: Fixed. This works.

NPC Code:

function onCreated()
{
this.showCharacter();

this.curPlayer = findPlayer("Raeiphon");
this.onTimeout();
}
function onTimeout()
{
temp.movex = this.curPlayer.x - x; // x needed to travel to player
temp.movey = this.curPlayer.y - y; // y needed to travel to player
dir = getdir(temp.movex, temp.movey);

if (player.dir == 1) { this.desx = 1.7; this.desy = 1; }
if (player.dir == 0) { this.desx = -1.7; this.desy = 1; }
if (player.dir == 2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir == 3) { this.desx = -1.7; this.desy = -1.7; }
if (this.curPlayer.x+this.desx!=x) {
this.ani = "walk";
move((temp.movex + this.desx), (temp.movey + this.desy), 1, 8+16);
} else {
this.ani = "idle";
setTimer(.05);
}
}
function onPlayerChats() {
if (player.chat="dismiss") {
destroy();
}
}
function onMovementFinished()
{
this.ani = "idle";
setTimer(.05);

__________________

I hope for nothing. I fear nothing. I am free.

Last edited by Raeiphon; 01-22-2007 at 04:46 AM..
Reply With Quote
  #6  
Old 01-22-2007, 06:30 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Chompy View Post
And, for better, and smooth movement (time wise),
use this:

PHP Code:
dist = ( dx dy 2) ^ 0.5;
movedxdydist tilespersecondflags); 
Yay basic geometry! One of the few equations from Geometry I actually remember.

But yeah, I never really liked move(). Not for any particular reason really...o.o.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
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 08:46 PM.


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