Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-11-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
NPC Movement Help.

So yeah, I'm creating my first attempt at NPC Movement, obviously the code itself isn't going to be too great since I'm not that great but learning, so don't make fun of me. XP But yeah, i'm having problem regarding my onwall check, oddly I added an onwall check, and now the NPC isn't moving at all. Could anyone tell me why? Also, I know I could use move(), but i'm going to try with just adjusting the x/y first so any advice regarding a way to do it better than my current would be appreciated.

Here's the code:

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

function 
onCreated() 
{
  
setshape(13248);
  
initializeCharacter();
}

function 
initializeCharacter()
{
  
setcharAni("idle"nil);
  
  
this.charDirection 2;
  
this.decisionRan int(random(02));
  if ( 
this.decisionRan == this.decisionAction "Walk";
  if ( 
this.decisionRan == this.decisionAction "Idle";
  if ( 
this.decisionRan == this.decisionAction "Animate";
  
this.decisionTimer 0;
  
this.decisionMax int(random(25));
  
  
onTimeout();
}

function 
onTimeout()
{
  
introduceDecisions();
  
introduceLife();
  
setTimer(0.01);
}

function 
introduceDecisions()
{
  if ( 
this.decisionTimer ) {
  
    
this.decisionTimer += .05;
  }
  if ( 
this.decisionTimer >= this.decisionMax ) {
  
    
this.decisionRan int(random(03));
    if ( 
this.decisionRan == this.decisionAction "Walk";
    if ( 
this.decisionRan == this.decisionAction "Idle";
    if ( 
this.decisionRan == this.decisionAction "Animate";
    
this.decisionTimer 0;
    
this.charAni false;
    
this.decisionMax int(random(14));
  }
}

function 
introduceLife()
{
  if ( 
this.decisionAction == "Walk" characterMove();
  if ( 
this.decisionAction == "Idle" characterIdle();
  if ( 
this.decisionAction == "Animate" characterAnimate();
  
dir this.charDirection;
}

function 
characterMove()
{
  if ( 
this.dirTimer this.dirTimer += .05;
  if ( 
this.dirTimer >= ) {
  
    
this.xRan int(random(03));
    
this.yRan int(random(03));
    
this.dirTimer 0;
  }
  if ( 
this.xRan == ) {
    
this.xMove .45;
  }
  if ( 
this.xRan == ) {
    
this.xMove = -.45;
  }
  if ( 
this.xRan == this.xMove 0;
  if ( 
this.yRan == ) {
    
this.yMove .45;
  }
  if ( 
this.yRan == ) {
    
this.yMove = -.45;
  }
  if ( 
this.yRan == this.yMove 0
  if ( 
this.xRan == this.charDirection 3;
  else
  if ( 
this.xRan == this.charDirection 1;
  else
  if ( 
this.yRan == this.charDirection 2;
  else 
  if ( 
this.yRan == this.charDirection 0
  
this.charMoving true;
  if ( 
this.charMoving ) {
  
    
this.charPos = {this.1.5 vecx(this.charDirection), 
                    
this.vecy(this.charDirection)};
    
chat this.charPos;
    if ( !
onwall(this.charPos[0], this.charPos[1]) ) {  
    
      
this.xMove;
      
this.yMove;
      if ( !
this.charAni ) {
    
        
setcharAni("walk"nil);
        
this.charAni true;
      }
    }
  }
}

function 
characterIdle()
{

  
this.charMoving false;
  
setcharAni("idle"nil);
}

function 
characterAnimate() {

  
this.charMoving false;
  if ( !
this.charAni ) {
  
    
setcharAni("lift"nil);
    
this.charAni true;
  }

Reply With Quote
 


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 02:15 AM.


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