Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Damn move() (https://forums.graalonline.com/forums/showthread.php?t=71598)

Raeiphon 01-21-2007 12:12 PM

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?

Chandler 01-21-2007 12:32 PM

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()")

Chompy 01-21-2007 05:26 PM

Quote:

Originally Posted by Chandler (Post 1267082)
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); 


konidias 01-21-2007 05:32 PM

Quote:

Originally Posted by Chandler (Post 1267082)
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.

Raeiphon 01-22-2007 04:35 AM

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);


coreys 01-22-2007 06:30 AM

Quote:

Originally Posted by Chompy (Post 1267126)
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.


All times are GMT +2. The time now is 02:46 PM.

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