Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   getDir() (https://forums.graalonline.com/forums/showthread.php?t=80941)

The_Kez 07-29-2008 11:13 PM

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.

Chompy 07-29-2008 11:17 PM

Err?

In the bigger script you provided you're doing

PHP Code:

  this.dir getDirthis.this.);
  
this.chat "My dir is " this.dir

That's not what you said you were doing though..

(PS, use the same arguments as you use in getangle() ) ^^

The_Kez 07-29-2008 11:20 PM

Quote:

Originally Posted by Chompy (Post 1409604)
Err?

In the bigger script you provided you're doing

PHP Code:

  this.dir getDirthis.this.);
  
this.chat "My dir is " this.dir

That's not what you said you were doing though..

(PS, use the same arguments as you use in getangle() ) ^^

Oops! The larger script is from when I was tinkering with the script to see if I could get different arguments to work.
And thanks I'll try that :]

The_Kez 07-29-2008 11:28 PM

PHP Code:

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 getDir((newx this.x),(newy this.y));
  
this.chat "My dir is " this.dir;


Alright that's what I'm using now. The movement still works fine but the direction still returns zero. I'm thinking maybe this command is only usable on the clientside?

DustyPorViva 07-29-2008 11:36 PM

do:
this.dir = getDir(0,1);

It should return 2. If it doesn't... I dunno. I'm pretty sure it can be used on the serverside.

The_Kez 07-29-2008 11:41 PM

Quote:

Originally Posted by DustyPorViva (Post 1409612)
do:
this.dir = getDir(0,1);

It should return 2. If it doesn't... I dunno. I'm pretty sure it can be used on the serverside.

Yup still returns zero. I guess Ill try testing if it works clientside and if it does I'll fin a way to sync it from the client to the server I guess.

DustyPorViva 07-29-2008 11:44 PM

I'm pretty sure it can be used serverside.

Also, if it does come down to not getting it to work, instead of syncing it you can simply make your own function that calculates the direction and use that.

The_Kez 07-29-2008 11:49 PM

Yeah I guess that'd be better then sending triggers around and such. I'll mess with the arguments some more and if it doesn't work I'll just create something like that :x

xXziroXx 07-30-2008 09:51 PM

It might be one of those functions that refuse to work with capitalized letters, there are a couple of 'em.

napo_p2p 07-30-2008 10:56 PM

Quote:

Originally Posted by xXziroXx (Post 1409966)
It might be one of those functions that refuse to work with capitalized letters, there are a couple of 'em.

I remember having this problem a while back. Ziro is right, getdir only works with all lowercase letters.

Inverness 07-30-2008 11:46 PM

I just call and define all functions and variables in lowercase letters. I only define events and object names with uppercase letters.

The_Kez 08-01-2008 10:55 PM

Oh. I've already created my own working function which is getting the NPC dir:

PHP Code:

//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 getDirecthis.xvel this.yvel );
  
this.chat "My dir is " this.dir;
}

function 
getDirecvx vy ) {
if ( 
vy && absvy ) > absvx ) ) temp.0;
elseif ( 
vx && absvx ) > absvy ) ) temp.1;
elseif ( 
vy && absvy ) > absvx ) ) temp.2;
elseif ( 
vx && absvx ) > absvy ) ) temp.3;
return 
temp.d;


I know know if it makes a difference whether I use .getdir() or my own function. I've tested mine though and it works perfectly well.

cbk1994 08-01-2008 11:02 PM

Use the built in one; it is optimized better. It's usually better to use built-in functions, if they exist.

Chompy 08-01-2008 11:52 PM

Did you actually try getdir() (Not any letters upper cased)

The_Kez 08-02-2008 04:32 AM

Alright I tried using getdir in all lower case and it works just fine now. Thanks =]


All times are GMT +2. The time now is 05:36 PM.

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