View Single Post
  #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