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 12-15-2009, 06:37 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Currency Converter

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
Attached Files
File Type: txt Currencys.txt (1.5 KB, 259 views)
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
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:20 AM.


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