View Single Post
  #1  
Old 01-29-2010, 06:06 AM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
NPC Movement Again :P

Alright so.. I've started on a new serverside NPC, but this time I'm using move(). This is only a basic form, as I was experimenting with move() and have never used it before. I've ran into a problem.. while trying to add the option to make the move() command detect walls, it seems to have broken it. The move() function is still being called, except for some odd reason, the NPC is acting as if it's constantly surrounded by walls. It tries to move but than ends up just going right back to the position it was spawned at. Could anyone help me please? Here's the code:

HTML Code:
function onPlayerchats() {
  if ( player.chat == "/destroy" ) destroy();
}

function onCreated() {

  showcharacter();
  setcharani("walk", nil);
  setshape(1, 32, 48);
  this.npcSpeed = random(1, 4);
  //- New script command: move(dx,dy,time,options);
  //dx - delta x
  //dy - delta y
  //time - time in seconds
  //options - cachingmode (0,1 or 2) + blockcheck (4 or 0) +
  //informmewhendone (8 or 0) + applydirection (16 or 0)
  
  onTimeout();
}

function onTimeout() {

  this.to_check = findnearestplayer(this.x, this.y);
  this.plyr = this.to_check;
  this.dist_x = this.plyr.x - this.x;
  this.dist_y = this.plyr.y - this.y;
  this.len = (this.dist_x * this.dist_x + this.dist_y * this.dist_y) ^ 0.5;
  this.add_x = (this.dist_x / this.len / this.npcSpeed);
  this.add_y = (this.dist_y / this.len / this.npcSpeed); 
  if ( this.x in |this.plyr.x - 3, this.plyr.x + 3| &&
       this.y in |this.plyr.y - 3, this.plyr.y + 3| ) {
  
    this.npcMode = "Attacking";
    if ( ani != "idle" )  setcharani("idle", nil);
  } else { this.npcMode = "Seeking"; }
  if ( this.npcMode == "Seeking" ) {
  
    chat = timevar2;
    move(this.add_x, this.add_y, 1, 4+16);
    if ( ani != "walk" ) setcharani("walk", nil);
  }
  //chat = this.npcMode;
  setTimer(.1);
}

function onActionProjectile()
{
  chat = "Ouch!";
  setcharani("hurt", nil);
}
Reply With Quote