Thread: getDir()
View Single Post
  #1  
Old 07-29-2008, 11:13 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
getDir()

I have a custom baddy script which I've written (It's still in progress so it just uses chat commands to test it's functionality so far) and I'm having some trouble with a certain command.

PHP Code:
function onCreated() {
  
this.isBaddy true;
  
this.maxHealth 100;
  
this.atkdmg 1;
  
setImg("Block.png");
  
this.chat "Rawr I'm a baddy!";
  
onTimeout();
}

function 
onPlayerChats() {
  
temp.movex player..5 vecx(player.dir) * 2;
  
temp.movey player..5 vecy(player.dir) * 2;
  if ( 
player.chat == "destroybaddy" destroy();
  elseif ( 
player.chat == "remove target" this.target NULL;
  elseif ( 
player.chat.tokenize()[0] == "target" ) {
    
this.target player.chat.tokenize()[1];
    
this.chat "Targeting: "this.target;
  }
  
}

function 
onTimeout() {
  
this.attack = ( this.attack # 40;
  
if ( this.target != NULL ) {
    
temp.findPlayer(this.target);
    
temp.movex temp.a..5 vecx(temp.a.dir) * 2;
    
temp.movey temp.a..5 vecy(temp.a.dir) * 2;
    if ( !(
this.x in |temp.movex-.5,temp.movex+.5|)  || !(this.y in |temp.movey-.5,temp.movey+.5|) ) {
      
this.last temp.test;
      
this.newmove = !this.newmove;
      
MoveTotemp.movex,temp.movey );
    }
    else if ( 
this.attack == 10 Attack();
  }
  if ( 
playerscount setTimer(0);
  else 
setTimer(.05);
}

//Move one space closer to newx,newy
function MoveTonewx,newy ) {
  
temp.angle getangle((newx this.x),(newy this.y));
  
this.xvel cos(temp.angle);
  
this.yvel sin(temp.angle);
  
this.+= this.xvel;
  
this.-= this.yvel;
  
this.dir getDirthis.this.);
  
this.chat "My dir is " this.dir;
}

//Testing removal of HP
function Attack() findPlayerthis.target ).clientr.myhealthstat -= this.atkdmg
Everything runs just fine except for this:

PHP Code:
  this.dir getDirnewx this.newy this.);
  
this.chat "My dir is " this.dir
This is always returning zero. I need to find the direction which the baddy is facing depending on where it moves so I can apply the proper direction for the setcharani animations for the baddy.
Anyone know what I may be doing wrong?

Also, this is my first custom baddy script. Any other CONSTRUCTIVE criticism or suggesstions for any other part of this script is obviously welcome.
Reply With Quote