Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Currency Converter (https://forums.graalonline.com/forums/showthread.php?t=134257317)

Deas_Voice 12-15-2009 06:37 PM

Currency Converter
 
1 Attachment(s)
Hello, this may be my first Code Gallery contribution.
I got inspired by Jerret's (fowlplay4) Translate script that used Google as it's engine.
So, I've made a Google Currency Converter out of Jerret's Script!

Class "class_currency":*
PHP Code:

function onCreated() {
  
// For Server's running on the 64-bit NPC-Server
  
addDNSEntry("www.google.com""72.14.213.95"); 
}
function 
Convert(amountfromto) {
  
// Make from and To UpperCase
  
temp.from.upper();
  
temp.to.upper();
  
  
// Determine URL
  
temp.site "http://www.google.com/finance/converter";
  
temp.url  temp.site "?a=" amount "&from=" temp."&to=" temp.t;

  
// Request URL
  
temp.req requesturl(temp.url);
  
this.catchevent(temp.req"onReceiveData""onConvert");
}
function 
onConvert(obj) {
  
// Perseing Time!
  
temp.parse =  obj.fulldata.substring(obj.fulldata.pos("<!DOCTYPE") + obj.fulldata.pos("<div id=currency_converter_result>") );
  
temp.parse2 temp.parse.substring(0temp.parse.pos("</span>"));
  
temp.parse3 temp.parse2.substring("<div id=currency_converter_result>".length());
  
temp.parse4 temp.parse3.substring(0temp.parse3.pos("<span class=bld>")) @ 
                
temp.parse3.substring(temp.parse3.pos("<span class=bld>") + "<span class=bld>".length());
  
// Echo Parsed Data
  
echo(temp.parse4);


*=The class can be named anything you want,
but I named it for the Example usage.


Example Usage:
PHP Code:

function onCreated() {
  
this.join("class_currency");
  
Convert(1"Eur""UsD");
  
// Would echo "1 EUR = 1.4632 USD"


Currency list at Attachment.

Cheers :)

fowlplay4 12-15-2009 06:40 PM

Nice work.

Soala 12-15-2009 08:09 PM

Neat !

Deas_Voice 12-18-2009 11:04 AM

Quote:

Originally Posted by fowlplay4 (Post 1544531)
Nice work.

Quote:

Originally Posted by alexandralove (Post 1544540)
Neat !


thanks (:

benpoke103 12-18-2009 07:11 PM

Very cool.

Would be interesting to see it run on a timer however, that will convert from a single unit of currency to another in order to get the differentials to store them locally, and have the script run serverside and not depend on google for approx. 6 hours :p

Deas_Voice 12-18-2009 09:33 PM

Quote:

Originally Posted by benpoke103 (Post 1545267)
Very cool.

Thank you.

Quote:

Originally Posted by benpoke103 (Post 1545267)
Would be interesting to see it run on a timer however, that will convert from a single unit of currency to another in order to get the differentials to store them locally, and have the script run serverside and not depend on google for approx. 6 hours :p

Interesting, Why? Don't really see a reason why you should store it locally.

cbk1994 12-18-2009 11:28 PM

Quote:

Originally Posted by benpoke103 (Post 1545267)
Very cool.

Would be interesting to see it run on a timer however, that will convert from a single unit of currency to another in order to get the differentials to store them locally, and have the script run serverside and not depend on google for approx. 6 hours :p

Well, this script is probably never going to be actually used (not very useful for Graal), but if it ever was, I agree that it'd be good to cache.

Deas_Voice 12-19-2009 01:57 AM

Quote:

Originally Posted by cbk1994 (Post 1545336)
this script is probably never going to be actually used

well thanks alot for that :\ :mad:

cbk1994 12-19-2009 02:03 AM

Quote:

Originally Posted by Deas_Voice (Post 1545380)
well thanks alot for that :\ :mad:

What do you think it could be used for on a Graal server? :p

Deas_Voice 12-19-2009 02:07 AM

Quote:

Originally Posted by cbk1994 (Post 1545384)
What do you think it could be used for on a Graal server? :p

well no, i agree that it's not useful to a server, but it's gonna be used.....

Rufus 12-19-2009 02:09 AM

It could be used on Era and Zodiac. It would allow the players to determine how much USD they can sell their items for if they're not in the United States.

cbk1994 12-19-2009 02:13 AM

Quote:

Originally Posted by Rufus (Post 1545389)
It could be used on Era and Zodiac. It would allow the players to determine how much USD they can sell their items for if they're not in the United States.

:\

Deas_Voice 12-19-2009 02:15 AM

Quote:

Originally Posted by Rufus (Post 1545389)
It could be used on Era and Zodiac. It would allow the players to determine how much USD they can sell their items for if they're not in the United States.

haha good one, don't forget GK! ;)

Rufus 12-19-2009 02:16 AM

Quote:

Originally Posted by cbk1994 (Post 1545394)
:\

Lighten up.

cbk1994 12-19-2009 02:18 AM

Quote:

Originally Posted by Rufus (Post 1545399)
Lighten up.

It was more of an admittance of defeat than anything :(.

maximus_asinus 12-19-2009 02:19 AM

Quote:

Originally Posted by Rufus (Post 1545389)
It could be used on Era and Zodiac. It would allow the players to determine how much USD they can sell their items for if they're not in the United States.

I was going to use that exact joke, but I thought it was a tad tasteless. Now that I seen it used, I wish I had used it :(


All times are GMT +2. The time now is 06:18 PM.

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