Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-29-2010, 05: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
  #2  
Old 01-29-2010, 05:14 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
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.
__________________
Quote:
Reply With Quote
  #3  
Old 01-29-2010, 05:31 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
Quote:
Originally Posted by fowlplay4 View Post
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.)
Reply With Quote
  #4  
Old 01-29-2010, 01:19 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
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.
Reply With Quote
  #5  
Old 01-29-2010, 09:54 PM
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
Quote:
Originally Posted by Immolate View Post
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..
Reply With Quote
  #6  
Old 01-29-2010, 10:16 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by Sage_Shadowbane View Post
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..
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)
Reply With Quote
  #7  
Old 03-12-2010, 03:10 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
yeah. this was a problem ... for a LONG time.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:48 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.