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 12-14-2008, 12:07 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Problem with move

For some reason, when the NPC reaches directly behind the player, the position of the NPC resets to the start position. This shouldn't happen. Can anybody help me?

PHP Code:
function onCreated() {

  
setshape(13232);

  
this.speed 12;
  
  
//format: idle animation, walking animation
  
this.ganis = {"idle""walk"};
  
  
showcharacter();
  
setCharAni("idle"null);
  
  
setTimer(0.1);
}

function 
onPlayerChats() {
  switch (
player.chat) {
    case 
":destroy":
      
destroy();
      break;
    
    case 
":follow":
      
this.following true;
      
setTimer(0.1);
      break;
    
    case 
":stop following":
      
this.following false;
      
setTimer(0.1);
      break;
  }
}

function 
onTimeout() {
  
this.nick this.attr[5] @ "'s Pet";
  
  if (
this.following == true) {
    
    
//get the coordinates that are directly behind the owner
    
for (plplayers) {
      if (
pl.account == this.attr[5]) {
        
temp.newxy = {
                      
pl.0.5 - (vecx(pl.dir) * 3),
                      
pl.- (vecy(pl.dir) * 3)
                      };
                    
        
//pl.chat = vecx(player.dir) SPC vecy(player.dir) SPC player.dir;
        
break;
      }
    }
    
    
//work out delta_x and delta_y for move
    
temp.dxy = {
                
temp.newxy[0] - this.x,
                
temp.newxy[1] - this.y
               
};
    
    
    
this.dir getdir(temp.dxy[0], temp.dxy[1]);
    
     
//set the animations
    
if (this.== temp.newxy[0] && temp.== this.newxy[1]) {
       if (
this.ani != this.ganis[0]) {
        
setCharAni( @ this.ganis[0], null);
       } 
     }
  
    else {
      if (
this.ani != this.ganis[1]) {
        
setCharAni( @ this.ganis[1], null);
      }
    }
    
    
//work out the distance and time to cover that distance
    
temp.dist getDistance(temp.dxy[0], temp.dxy[1]);
    
temp.time temp.dist/this.speed;
    
    
move(this.dxy[0], temp.dxy[1], temp.time4);
    
    
    if (
temp.time 0.1temp.time 0.1;
    
    
setTimer(temp.time);
  }
}

function 
getDistance(temp.xtemp.y) {
  
temp.dist = (temp.temp.2) ^ 0.5;
  return 
temp.dist;

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 07:28 PM.


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