Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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:36 PM.


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