Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-06-2009, 06:38 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
Problem with NPC movement

Hello again!

Today I am having two problems:

1) When this movement was moved to the clientside, movement was quicker, but the npc coordinates were offset by a few pixels, and now will not work on a gmap (the NPC merely sits in the warpto() spot)

2) The NPC sometimes will not cease the walk gani

PHP Code:
function followPlayer(){
  
pet.dir player.dir;
 
  if(
pet.level.name != player.level.name){
    if(!
inPrefix(player.level.name) && pet.lvlBlock.index(player.level.name)==-1){
      
warpto(player.level.name,player.x+(vecx(player.dir))%64,player.y+(vecy(player.dir))%64);
      
pet.dir player.dir;
      
storeLocation();
      return;
    }else{
      
pet.state STAY;      //Enum for this is defined elsewhere
      
return;
    }
  }
  
moveTo(player.x+(vecx(player.dir)*-1)%64,player.y+(vecy(player.dir)*-1)%64);
}

function 
moveTo(lx,ly){
  
temp.dx int(pet.temp.lx);
  
temp.dy int(pet.temp.ly);
 
  if(
temp.dx in |0pet.walkSpeed|){
    if(
temp.dy in |0pet.walkSpeed|){
      
setcharani("pet_idle",null);
      return;
    }
  }
  
setcharani("pet_walk",null);  
 
  
temp.nx pet.x;
  
temp.ny pet.y;
 
  if(
temp.dx != 0){
    if(
temp.dx 0){
      
temp.nx -= 1*(pet.walkSpeed);
    }else{
      
temp.nx += 1*(pet.walkSpeed);
    }
  }
  if(
temp.dy != 0){
    if(
temp.dy 0){
      
temp.ny -= 1*(pet.walkSpeed);
    }else{
      
temp.ny += 1*(pet.walkSpeed);
    }
  }
 
  
pet.dir getdir(-temp.dx,-temp.dy);
  
  
  
temp..0002;//.0002 is the error value between a tile and pos
  
temp.e2 this.e*2;
 
  if(!
onwall2(temp.nx+pet.atx,temp.ny+pet.aty,pet.wv,pet.hv)){
    
pet.temp.nx;
    
pet.temp.ny;
  }else if(!
onwall2(temp.nx+pet.atx,pet.y+pet.aty,pet.wv,pet.hv)){
    
pet.temp.nx;
  }else if(!
onwall2(this.x+pet.atx,temp.ny+pet.aty,pet.wv,pet.hv)){
    
pet.temp.ny;
  }
 
//need to handle water

Suggestions?
Reply With Quote
 

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 09:23 PM.


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