Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-08-2008, 03:16 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Useful functions

Some general useful functions in GS2 (Some of them are for compatibility with JS/PHP/etc others are just good)
PHP Code:
function rand() {
  return new 
MRandomLCG().randFloat();
}
function 
tan(x) {
  return 
sin(x)/cos(x);
}
function 
atan2(y,x) {
  return 
x<>0?x>0?atan(y/x):atan(y/x)-radian(180):y>0?radian(90):radian(-90);
}
function 
atan(number) {
  return 
arctan(number);
}
function 
floor(number) {
  return 
int(number);
}
function 
ceil(number) {
  return 
int(number) < number number number;
}
function 
radian(degree) {
    return (
degree 0.0174532925);

function 
degree(radian) {
    return (
radian 57.2957795);

function 
square(n) {
    return (
n);

function 
norm(angle) {
    return (
angle 6.283185 floor((angle pi) / 6.283185));

function 
tile(pixel) {
    return (
pixel 16);

function 
pixel(tile) {
    return (
tile 16);

Enjoy
__________________


Last edited by Robin; 05-08-2008 at 04:53 AM.. Reason: Updated to reflect awesomeness.
Reply With Quote
  #2  
Old 05-08-2008, 03:19 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Oi! Very nice
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 05-08-2008, 03:24 AM
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
Not bad!

Some of these have been released by other people before (meaning, they made the same thing, not that you stole the script). By the way, you have

PHP Code:
function random)
{
  
//blah

Yet x is not used at all. Was this left over from before?
__________________
Reply With Quote
  #4  
Old 05-08-2008, 03:36 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Ah yeah, I used to have rand.seed=x but it doesn't really change anything so I took it out for effciency's sake. Edited the post.
__________________

Reply With Quote
  #5  
Old 05-08-2008, 03:48 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Robin View Post
... for effciency's sake.
Cascade the 'if's in atan2... for efficiency's sake.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #6  
Old 05-08-2008, 04:24 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
PHP Code:

function atan2(y,x) {
  if (
0) {
    return 
atan(y/x);
  } elseif (
0) {
    return 
atan(y/x) - radian(180);
  } elseif (
== 0) {
    if (
0) {
      return 
radian(90);
    } elseif (
0) {
      return 
radian(-90);
    } elseif (
y==0) {
      return 
0;
    }
  }

Better? :P
__________________

Reply With Quote
  #7  
Old 05-08-2008, 04:29 AM
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
PHP Code:
function floor(number) {
  return 
int(number);

What does this do?

Simply for compatibility with your almighty ECMAScript Standards?
__________________
Reply With Quote
  #8  
Old 05-08-2008, 04:31 AM
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
PHP Code:
function ceil(number) {
  return 
int(number) < number number number;

Shouldn't that be:
PHP Code:
return int(number) < number number number
Reply With Quote
  #9  
Old 05-08-2008, 04:44 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Quote:
Originally Posted by DustyPorViva View Post
PHP Code:
function ceil(number) {
  return 
int(number) < number number number;

Shouldn't that be:
PHP Code:
return int(number) < number number number
You are correct sir! I saw it just now.

Just for that, you get this special version of atan2 as your prize!
PHP Code:
function atan2(y,x) {
  return 
x<>0?x>0?atan(y/x):atan(y/x)-radian(180):y>0?radian(90):radian(-90);

That's right. They're nested.
__________________

Reply With Quote
  #10  
Old 05-08-2008, 10:53 AM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
There's degtorad and radtodeg built in.

Also, why have this? Besides the fact you lose 2 letters -.-
PHP Code:
function atan(number) {
  return 
arctan(number);

It's like the same as me doing a "getnumberone()" function for returning 1...
PHP Code:
function getnumberone() {
  return 
1;

__________________
Reply With Quote
  #11  
Old 05-08-2008, 10:16 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
Quote:
Originally Posted by Dan View Post
There's degtorad and radtodeg built in.

Also, why have this? Besides the fact you lose 2 letters -.-
PHP Code:
function atan(number) {
  return 
arctan(number);

It's like the same as me doing a "getnumberone()" function for returning 1...
PHP Code:
function getnumberone() {
  return 
1;

I agree, that's rather silly.
__________________
Reply With Quote
  #12  
Old 05-08-2008, 10:22 PM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
ECMAScript compatibility, if you don't like it, don't use my code. Simple.
__________________

Reply With Quote
  #13  
Old 05-08-2008, 10:25 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
Quote:
Originally Posted by Robin View Post
ECMAScript compatibility, if you don't like it, don't use my code. Simple.
No need to get angry. We simply find it strange you would make a new function when you could just type two or three extra characters.
__________________
Reply With Quote
  #14  
Old 05-08-2008, 10:26 PM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Quote:
Originally Posted by cbkbud View Post
No need to get angry. We simply find it strange you would make a new function when you could just type two or three extra characters.
Because I find myself always putting atan in instead of arctan, and wondering why things dont work properly since for some reason my console doesn't like to work and I can't see the error there.
__________________

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 04:57 AM.


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