Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-29-2007, 04:13 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
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

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
__________________

Last edited by Chompy; 04-29-2007 at 06:15 PM..
Reply With Quote
  #2  
Old 04-29-2007, 04:39 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to all
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Holy ****!! I smell long equations.... oh wait nvm u made it simple
__________________
Reply With Quote
  #3  
Old 04-29-2007, 06:05 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
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
Reply With Quote
  #4  
Old 04-29-2007, 06:12 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
Quote:
Originally Posted by DustyPorViva View Post
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
__________________
Reply With Quote
  #5  
Old 04-29-2007, 06:16 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
You're aware that abs turns a negative value to a posative, right?
Reply With Quote
  #6  
Old 04-29-2007, 06:20 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
Quote:
Originally Posted by Chandler View Post
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
__________________

Last edited by Chompy; 04-29-2007 at 08:03 PM..
Reply With Quote
  #7  
Old 04-29-2007, 06:21 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to all
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Quote:
Originally Posted by Chandler View Post
You're aware that abs turns a negative value to a posative, right?
perhaps he is aware (or maybe he isn't?)
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:29 PM.


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