PDA

View Full Version : Additions to ZScript.txt of the Utility Routines



Joe123
11-19-2007, 06:32 PM
Would it be possible for someone to add what the utility routines from std.zh are, and what they do to ZScript.txt?
Because obviously they're very useful, and it's not always apparent (it took me a long time to discover them) what they are (espcially if you're just learning ZScript) due to where they are, and the fact that they're not explained in that location (it's not obvious what they do or how to use them to start with)

Please?

EDIT: Come to think of it, I'm going to go add them to the Wiki. Maybe I'll even give them their own page.

EDIT2: Ok, I added it to the end of the ZScript Language Reference page in the end, which probably wasn't the best place for it, so if anyone knows/can think of a better place then please move it for me, because I can't. I think it should all be correct, but it may not be.
(http://www.shardstorm.com/ZCwiki/ZScript_Language_Reference#Utility_Routines)

Gleeok
11-19-2007, 10:33 PM
It sounds confusing for people new to scripting. :eek: haha.. Good that it's there though.

Also I've got a question about the distance routine. How would one use it say...to shoot fireballs at Link?

distance(Link->X,Link->Y,this->X,this->Y);

this->Vx = distance;
this->Vy = distance;


That's definately not right. hmm...

DarkDragon
11-19-2007, 10:41 PM
Distance doesn't matter; you just need to orientation of the vector point from the FFC to Link. The only tricky part is that you probably want to normalize this vector, otherwise the fireball will move faster if it's farther away from link.


int dx = Link->X - this->X;
int dy = Link->Y - this->Y;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
this->Vx = dx/norm;
this->Vy = dy/norm;
}

Gleeok
11-19-2007, 11:55 PM
Ooh! Sweet. Your awesome DarkDragon. :)

But hypothetically, lets suppose someone wanted to increase the projectiles speed.

this->Vx = dx/norm+speed; .....this->Vx = speed + dx/norm ?

How would you add to that, if your not sure if the Vx is a positive or negative number.
..or I should say what the Vx is set to rather.

It's been many, many years since I was in math class.



Edit: Aah, well I realized I could alway's add 4 if else statements to check where Link is greater or less than this->X and Y, but it seems a bit clunky when compared to your design.

DarkDragon
11-20-2007, 12:15 AM
To change the speed, you multiply Vx and Vy. For instance, assuming you have an enclosing loop that increments t:

1) if you want it to accelerate linearly:


this->Vx = dx/norm*t;
this->Vy = dy/norm*t;


2) slow down with time


this->Vx = dx/norm/Sqrt(t);
this->Vy = dy/norm/Sqrt(t);


Just play around with different functions.