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 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
  #2  
Old 12-14-2008, 12:19 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
It might be due to the block check - if move() is checking for blocking tiles (4), and it encounters one, it resets back to the position where it was at before using move().
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #3  
Old 12-14-2008, 12:21 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
Thank you so much.
Reply With Quote
  #4  
Old 12-16-2008, 08:36 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
Ok this thread title summarizes my problem, so I will post here too (sorry for the thread steal codein <3)

PHP Code:
function onCreated() {
  
this.image "block.png";
  
setTimer(2);
  
onMovementFinished();
}
function 
onMovementFinished() {
  if(!
onwall(this.imgwidth(this.image), this.imgheight(this.image))) {
    
temp.movex sin(this.angle) * this.speed;
    
temp.movey cos(this.angle) * this.speed;
    
move(movexmovey.18);
  }
}

function 
onTimeout() {
  
destroy();

for the record, this.angle and this.speed are being set in a weapon NPC calling this class
this.angle = getangle(vecx(player.dir), vecy(player.dir));
this.speed = .5;

the move angle goes into an extremely different angle when fired

Suggestions?
Reply With Quote
  #5  
Old 12-16-2008, 09:05 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
PHP Code:
function onCreated() {
  
this.image "block.png";
  
setTimer(2);
  
onMovementFinished();
}
function 
onMovementFinished() {
  if(!
onwall(this.imgwidth(this.image), this.imgheight(this.image))) {
    
temp.movex sin(this.angle) * this.speed;
    
temp.movey cos(this.angle) * this.speed;
    
move(movexmovey.18);
  }
}

function 
onTimeout() {
  
destroy();

PHP Code:
function onCreated() {
  
this.image "block.png";
  
setTimer(2);
  
onMovementFinished();
}
function 
onMovementFinished() {
  if(!
onwall(this.imgwidth(this.image), this.imgheight(this.image))) {
    
temp.movex sin(this.angle) * this.speed;
    
temp.movey cos(this.angle) * this.speed;
    
move(this.movexthis.movey.18);
  }
}

function 
onTimeout() {
  
destroy();

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 12-16-2008, 07:34 PM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
hmm, still not working

here is the control weapon:

PHP Code:
function onActionServerSide(temp.cmdtemp.otemp.dxtemp.dy) {
  if(
cmd == "fire" && temp.== "thatdwarf") {
    
temp.op findplayer(o);
    
temp.obj putnpc2(op.xop.y"");
    
temp.obj.ndx dx;
    
temp.obj.ndy dy;
    
temp.obj.angle getangle(vecx(op.dir), vecy(op.dir));
    
temp.obj.join("lloydprojectile");
  }
}

//#CLIENTSIDE
function onCreated() {
  
this.on false;
}

function 
onWeaponFired() {
  
this.on = !this.on;
  
player.chat this.on;
}

function 
onMouseDown(code) {
  if(
code == "left" && this.on) {
    
triggerServer("gui"this.name"fire"player.accountmousexmousey);
  }

And I also tried the method you suggested in my class Tig, so maybe it's something with the weapon?

The image shoots way off to an extreme corner of the level, then disappears
Reply With Quote
  #7  
Old 12-16-2008, 09:00 PM
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
not sure, but try using different variables instead of angle & speed, like this.pangle and this.pspeed. Otherwise I'd sugest looking at your way to measure angles, etc.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #8  
Old 12-16-2008, 11:14 PM
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
For angle, try
PHP Code:
angle = (pi 2) / * (dir 1); 
getAngle(x, y) works with a coordinate plane. For example, getAngle(-2, 1):



So, to get the right result with getAngle(), you'd have to do something like this:

PHP Code:
angle getAngle(vecx(dir), vecy(dir)); 
which is far too much work when you can use a simpler solution.
__________________
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 08:06 PM.


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