Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 06-06-2009, 06:43 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Why aren't you using the move() function?
__________________
Reply With Quote
  #3  
Old 06-06-2009, 06:49 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by thatdwarf View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 06-06-2009, 06:53 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
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
Reply With Quote
  #5  
Old 06-06-2009, 07:01 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by thatdwarf View Post
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?
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 06-06-2009, 07:05 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
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//////////////////// 
Reply With Quote
  #7  
Old 06-06-2009, 07:14 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by thatdwarf View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #8  
Old 06-06-2009, 07:22 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
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
Reply With Quote
  #9  
Old 06-06-2009, 07:35 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #10  
Old 06-06-2009, 07:45 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
Still no success

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


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:04 AM.


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