Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Some small functions I made (https://forums.graalonline.com/forums/showthread.php?t=73740)

Chompy 04-29-2007 04:13 PM

Some small functions I made
 
Well, I finnaly decided to release some simple functions I've been using lately helping me script stuff.. so here they are :o
PS: This is also my first release in the Code-Gallery :)

class
PHP Code:

public function reverseDir(dir)
{
  if (
dir in |03|)
    return (
dir+2)%4;
}
public function 
reversedeg(deg)
  return (
deg+180)%360;

public function 
reverserad(rad)
{
  
reverse reversedeg(radtodeg(rad));
  return 
degtorad(reverse);
}
public function 
percentage(ofvalue)
  return ((
value of) / 100);

public function 
radianequaldir(dir)
  return (
pi/2)+(pi/2*dir); 

They are currently serverside, but works as well on clientside

reverseDir():

Well, I made this function for knockback effects, because it gets the direction
behind the player, for example input 2 would be 0, 1 would be 3 etc..

example of use:

PHP Code:

function onCreated()
  
join("ch_functions"); // this is what I named the class
//#CLIENTSIDE
function onCreated()
{
  
reversedir(player.dir);
  
setani("hurt""");
  
power 0.8;   // knock-back tiles
  
for(power0-= power/3;) {
    
= {vecx(a)*2vecy(a)*2};
    
player.+= d[0]*i;
    
player.+= d[1]*i;
    
sleep(power / (35 + (power 10)));
  }


I know, poor example but I just wanted to clear how it could be used

reversedeg():

Well, this functions does almost the same as reversedir but reverses degrees,
for example: 360 would be 180, 180 would be 0 and 247 would be 67

Well, I haven't actually used this alot, but it could be used by projectiles or even spells (wall hit, reflect spells)

reverserad():
Yep, it reverses radians, actually it starts reversedeg() and then uses degtorad() to get output, can be used as reversedeg() can be used..

percentage(of, value)

Well, easy math thingy, gets a percentage amount of a value, for example

PHP Code:

function onCreated()
{
  
join("ch_functions");
  
  echo(
"P1: " percentage(47100));
  echo(
"P2: " percentage(67847));


would output
NPC Code:

P1: 47
P2: 567.49


Easy function, I've used this for alot (Spells taking a percentage as mana, damage bonuses etc...)

radianequaldir()

Basicly all it does it gets the radian value of the current direction of the player
I simple used this for a movement system, to get the start radian of the direction

Formula used:
The formula I've used to get the reverse is in this format:

(VALUE+HALF)%FULL
where VALUE is the float being reversed, FULL is the max value, for example 360,
while HALF is the half value of FULL, for example 180


Notes:

All examples are serverside (knockback isn't); the functions will work clientside if you edit the class containing the functions (moving the functions to the clientside)

Thanks Dusty for telling an easier formula :D

I'll release some "small"-functions later when I make them :O
And I also hope some other scripters will release some of their "nifty"-functions :)

ff7chocoboknight 04-29-2007 04:39 PM

Holy ****!! I smell long equations.... oh wait nvm u made it simple

DustyPorViva 04-29-2007 06:05 PM

No need for the absolute value in reversedir, modulus will make sure it doesn't go under 0. Same for reversedeg.

Also, why do dir%4?
I usually just do (dir+2)%4

Chompy 04-29-2007 06:12 PM

Quote:

Originally Posted by DustyPorViva (Post 1304181)
No need for the absolute value in reversedir, modulus will make sure it doesn't go under 0. Same for reversedeg.

Also, why do dir%4?
I usually just do (dir+2)%4

:O didn't think of that
Thanks, will edit my post :)

Chandler 04-29-2007 06:16 PM

You're aware that abs turns a negative value to a posative, right?

Chompy 04-29-2007 06:20 PM

Quote:

Originally Posted by Chandler (Post 1304186)
You're aware that abs turns a negative value to a posative, right?

Yes, but as Dusty said, I wasn't aware that modulus will make it so it won't go under 0

ff7chocoboknight 04-29-2007 06:21 PM

Quote:

Originally Posted by Chandler (Post 1304186)
You're aware that abs turns a negative value to a posative, right?

perhaps he is aware (or maybe he isn't?)


All times are GMT +2. The time now is 09:51 AM.

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