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 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
  #2  
Old 07-29-2008, 11:17 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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() )
__________________
Reply With Quote
  #3  
Old 07-29-2008, 11:20 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
Quote:
Originally Posted by Chompy View Post
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 :]
Reply With Quote
  #4  
Old 07-29-2008, 11:28 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
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?
Reply With Quote
  #5  
Old 07-29-2008, 11:36 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #6  
Old 07-29-2008, 11:41 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
Quote:
Originally Posted by DustyPorViva View Post
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.
Reply With Quote
  #7  
Old 07-29-2008, 11:44 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #8  
Old 07-29-2008, 11:49 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
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
Reply With Quote
  #9  
Old 07-30-2008, 09:51 PM
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 one of those functions that refuse to work with capitalized letters, there are a couple of 'em.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #10  
Old 07-30-2008, 10:56 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by xXziroXx View Post
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.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #11  
Old 07-30-2008, 11:46 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I just call and define all functions and variables in lowercase letters. I only define events and object names with uppercase letters.
__________________
Reply With Quote
  #12  
Old 08-01-2008, 10:55 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
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.
Reply With Quote
  #13  
Old 08-01-2008, 11:02 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
Use the built in one; it is optimized better. It's usually better to use built-in functions, if they exist.
__________________
Reply With Quote
  #14  
Old 08-01-2008, 11:52 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Did you actually try getdir() (Not any letters upper cased)
__________________
Reply With Quote
  #15  
Old 08-02-2008, 04:32 AM
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
Alright I tried using getdir in all lower case and it works just fine now. Thanks =]
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 06:51 PM.


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