Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Problem with NPC movement (https://forums.graalonline.com/forums/showthread.php?t=86207)

thatdwarf 06-06-2009 06:38 AM

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?

cbk1994 06-06-2009 06:43 AM

Why aren't you using the move() function?

Tigairius 06-06-2009 06:49 AM

Quote:

Originally Posted by thatdwarf (Post 1497400)
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

Suggestions?

For number 1, use player.gmap.name as well as player.level.name for testing the player's level, when player.gmap.name != NULL, use that, when it is, use player.level.name.

For number 2, might try checking the movement elsewhere in the script or check movement a different way, maybe it's possible the pet's walking speed is not between 0 and pet.walkspeed by some other logic error in the script.

thatdwarf 06-06-2009 06:53 AM

The function completely slipped my mind, great suggestion

however I'm still having a problem with the gmap
The NPC refuses to move while on a gmap


EDIT: The NPC completely disappeared when I changed the moveTo() call in followPlayer() to move() with time: 3 and options 4+16

Tigairius 06-06-2009 07:01 AM

Quote:

Originally Posted by thatdwarf (Post 1497403)
The function completely slipped my mind, great suggestion

however I'm still having a problem with the gmap
The NPC refuses to move while on a gmap


EDIT: The NPC completely disappeared when I changed the moveTo() call in followPlayer() to move() with time: 3 and options 4+16

Can you show us exactly what you're doing with player.gmap.name?

thatdwarf 06-06-2009 07:05 AM

All of this is clientside

PHP Code:

///////////////////Movement//////////////////////
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.gmap.name == NULL) ? player.level.name player.gmap.name,player.x+(vecx(player.dir))%64,player.y+(vecy(player.dir))%64);
      
pet.dir player.dir;
      
storeLocation();
      return(
null);
    }else{
      
pet.state STAY;
      return(
null);
    }
  }
  
moveTo(player.x+(vecx(player.dir)*-1),player.y+(vecy(player.dir)*-1));
}

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("okiepet_idle",null);
      return(
null);
    }
  }
  
setcharani("okiepet_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
}
////////////////////End Movement//////////////////// 


Tigairius 06-06-2009 07:14 AM

Quote:

Originally Posted by thatdwarf (Post 1497407)
All of this is clientside

PHP Code:

///////////////////Movement//////////////////////
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.gmap.name == NULL) ? player.level.name player.gmap.name,player.x+(vecx(player.dir))%64,player.y+(vecy(player.dir))%64);
      
pet.dir player.dir;
      
storeLocation();
      return(
null);
    }else{
      
pet.state STAY;
      return(
null);
    }
  }
  
moveTo(player.x+(vecx(player.dir)*-1),player.y+(vecy(player.dir)*-1));
}

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("okiepet_idle",null);
      return(
null);
    }
  }
  
setcharani("okiepet_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
}
////////////////////End Movement//////////////////// 


Hm, you only replaced part of it with player.gmap.name

You I was mostly talking about the if statement.

PHP Code:

///////////////////Movement//////////////////////

function getObjectLevel(obj) {
  if (
obj.gmap.name != NULL) {
    return 
obj.gmap;
  }else
    return 
obj.level;
}

function 
followPlayer(){
  
pet.dir player.dir;
  
  
temp.petlevel getObjectLevel(pet);
  
temp.playerlevel getObjectLevel(player);

  if (
temp.petlevel.name != temp.petlevel.name){
    if(!
inPrefix(temp.playerlevel.name) && pet.lvlBlock.index(temp.playerlevel.name)==-1){
      
warpto(temp.playerlevel.name,player.x+(vecx(player.dir))%64,player.y+(vecy(player.dir))%64);
      
pet.dir player.dir;
      
storeLocation();
      return(
null);
    }else{
      
pet.state STAY;
      return(
null);
    }
  }
  
moveTo(player.x+(vecx(player.dir)*-1),player.y+(vecy(player.dir)*-1));
}

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("okiepet_idle",null);
      return(
null);
    }
  }
  
setcharani("okiepet_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
}
////////////////////End Movement//////////////////// 

Maybe something like that would work. If not, try
PHP Code:

      warpto(player.level.name,player.x+(vecx(player.dir))%64,player.y+(vecy(player.dir))%64); 

instead.

thatdwarf 06-06-2009 07:22 AM

I tried your suggestion and neither attempts worked (including fixing your error in the first if statement if(temp.petlevel.name != temp.petlevel.name) )

It simply wont warp to the gmap

Tigairius 06-06-2009 07:35 AM

Yes, I apologize, I also meant to remove the modulus from the warpto() in the first example I sent you.

It's possible that it's warping to the gmap, but being displayed at an x/y of 0-64.

thatdwarf 06-06-2009 07:45 AM

Still no success

The pet also would not move correctly with the move() command attempt
I'm not sure what I am doing wrong


All times are GMT +2. The time now is 06:58 AM.

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