Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPC Movement Again :P (https://forums.graalonline.com/forums/showthread.php?t=134257804)

Sage_Shadowbane 01-29-2010 06:06 AM

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


fowlplay4 01-29-2010 06:14 AM

The wall detection parameter is pretty much useless, and results in glitchy behaivour as you noticed :(

Your best bet is to write your own onwall/water checks.

Sage_Shadowbane 01-29-2010 06:31 AM

Quote:

Originally Posted by fowlplay4 (Post 1552944)
The wall detection parameter is pretty much useless, and results in glitchy behaivour as you noticed :(

Your best bet is to write your own onwall/water checks.

I've actually already tried using both onwall() and onwall2(), neither of them work, they make the NPC seem as if he's surrounded by walls at all time (Pretty much similar to the same situation it's in now.)

Immolate 01-29-2010 02:19 PM

I know it's not as elegant as you probably want it but you might be best off just making nodes for each NPC as you make them. That way you can just avoid the walls knowingly.

Sage_Shadowbane 01-29-2010 10:54 PM

Quote:

Originally Posted by Immolate (Post 1553002)
I know it's not as elegant as you probably want it but you might be best off just making nodes for each NPC as you make them. That way you can just avoid the walls knowingly.

Well honestly at this point it's not even about just avoiding walls, my main priority is really that I don't want the NPC's to be able to stack up on top of each other.. :mad:

Immolate 01-29-2010 11:16 PM

Quote:

Originally Posted by Sage_Shadowbane (Post 1553102)
Well honestly at this point it's not even about just avoiding walls, my main priority is really that I don't want the NPC's to be able to stack up on top of each other.. :mad:

I can see your problem now. Yeah, I had issues with this too, kinda sucks :/ Probably have to badger Stefan and in the mean time, have the baddies stack (since otherwise, well placed nodes will do the trick xD)

adam 03-12-2010 04:10 AM

yeah. this was a problem ... for a LONG time.


All times are GMT +2. The time now is 08:24 PM.

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