/// <summary>
/// ExchangeRate is what you set it to be.
/// ExchangeAmount is what you set it to be.
/// <summary>
/// </summary>
/// Copper is the lowest denominator of currency.
/// It requires ExchangeRate Copper to make ExchangeAmount Silver.
/// </summary>
/// <summary>
/// Silver is the second most common form of currency.
/// It requires ExchangeRate Silver to Make ExchangeAmount Gold.
/// </summary>
/// <summary>
/// Gold is the most common form of currency. It takes
/// part in most expensive transactions.
/// It requires ExchangeRate Gold to make ExchangeAmount Platinum
/// this conversion is not in yet.
/// </summary>
function onUseChecked(pUser, iUsed)
{
var socket = pUser.socket;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
if (socket && iUsed && iUsed.isItem)
{
socket.tempObj = iUsed;
currencystone(pUser, iUsed);
}
return false;
}
function onCreateDFN(objMade, objType)
{
if (objType == 0)
{
if (objMade.name == "Currency Stone")
{
objMade.SetTag("exrate", 100);
objMade.SetTag("examount", 1);
}
}
}
function currencystone(pUser, iUsed)
{
var ExchangeRate = iUsed.GetTag("exrate");
var ExchangeAmount = iUsed.GetTag("examount");
var socket = pUser.socket;
var currency = new Gump;
socket.tempObj = iUsed;
currency.AddBackground(230, 200, 536, 270, 5054);
currency.AddTiledGump(260, 220, 470, 21, 3604);
currency.AddText(270, 220, 1153, "The current Exchange Rate is " + ExchangeRate + " for " + ExchangeAmount);
currency.AddTiledGump(510, 290, 117, 21, 3604);
currency.AddTiledGump(510, 320, 117, 21, 3604);
currency.AddTiledGump(290, 300, 141, 21, 3604);
currency.AddText(460, 290, 0, "Recieve");
currency.AddText(470, 320, 0, "Use");
currency.AddText(290, 280, 1153, "Enter the Amount to Trade");
currency.AddText(500, 270, 1153, "Enter Currency to Trade");
currency.AddText(680, 270, 87, "Currency");
currency.AddText(690, 290, 1153, "Gold");
currency.AddText(690, 310, 1153, "Silver");
currency.AddText(690, 330, 1153, "Copper");
currency.AddText(300, 390, 1153, "Is this agreeable?");
currency.AddTiledGump(300, 420, 89, 38, 3004);
currency.AddTiledGump(400, 420, 89, 38, 3004);
currency.AddText(310, 430, 1153, "Yes");
currency.AddText(410, 430, 1153, "No");
currency.AddButton(360, 430, 1209, 248, 1, 0, 1);
currency.AddButton(460, 430, 1209, 248, 1, 0, 0);
currency.AddText(300, 330, 0, "currency is rounded");
currency.AddTextEntryLimited(290, 300, 140, 20, 1153, 0, 13, "0", 6);
currency.AddTextEntry(510, 290, 117, 20, 1153, 0, 14, "");
currency.AddTextEntry(510, 320, 116, 20, 1153, 0, 15, "");
if (pUser.isGM)
{
currency.AddButton(670, 430, 2006, 248, 1, 0, 2);
}
currency.Send(socket);
currency.Free();
}
function gmoptions(pUser, iUsed)
{
var socket = pUser.socket;
var options = new Gump;
options.AddPage(0);
options.AddBackground(330, 250, 440, 130, 9200);
options.AddTiledGump(370, 270, 373, 21, 3604);
options.AddText(380, 270, 1153, "Here you can set the Exchnage Rate and Exchange Amount");
options.AddText(360, 310, 1153, "Exchange rate");
options.AddText(360, 340, 1153, "Exchange Amount");
options.AddTiledGump(480, 310, 140, 21, 3604);
options.AddTiledGump(480, 340, 140, 21, 3604);
options.AddButton(650, 340, 247, 248, 1, 0, 3);
options.AddText(640, 310, 1153, "Hit Okay to Save");
options.AddTextEntry(480, 310, 139, 20, 1153, 0, 5, "");
options.AddTextEntry(480, 340, 139, 20, 1153, 0, 6, "");
options.Send(pUser);
options.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var iUsed = pSock.tempObj;
var pUser = pSock.currentChar;
if (iUsed.GetTag("Options") != true)
{
var amountTyped = gumpData.getEdit(0);
var currencyOne = gumpData.getEdit(1);
var currencyTwo = gumpData.getEdit(2);
var exchangeRate = iUsed.GetTag("exrate");
var exchangeAmount = iUsed.GetTag("examount");
var amountAwarded = Math.round(amountTyped / exchangeRate) * exchangeAmount;
var checkAmount = amountTyped >= exchangeRate;
var numbers = /^[0-9a]+$/;
var numberCheck = amountTyped.match(numbers);
}
else
{
var exchangeRateedit = gumpData.getEdit(0);
var exchangeAmountedit = gumpData.getEdit(1);
}
var gold = 0x0eed;
var silver = 0x0ef0;
var copper = 0xeea;
switch (pButton)
{
case 0:break;
case 1:
if (currencyOne == "gold" || currencyOne == "silver" || currencyOne == "copper" || currencyTwo == "gold" || currencyTwo == "silver" || currencyTwo == "copper" && amountTyped.length <= 2 || amountTyped.length > 40)
{
if (!numberCheck)
{
pUser.SysMessage("Exchange Amount may only consist of Digits (0 - 9).");
currencystone(pUser, iUsed);
break;
}
if (currencyOne == "gold" && currencyTwo == "gold")
{
pUser.SysMessage("Can not exchange " +currencyOne+" for " + currencyTwo);
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "silver" && currencyTwo == "silver")
{
pUser.SysMessage("Can not exchange " +currencyOne+" for " + currencyTwo);
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "copper" && currencyTwo == "copper")
{
pUser.SysMessage("Can not exchange " +currencyOne+" for " + currencyTwo);
currencystone(pUser, iUsed);
break;
}
else if(!checkAmount)
{
pUser.SysMessage("You can not exchange less then the rate");
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "gold" && currencyTwo == "silver")
{
if (pUser.ResourceCount(silver) >= amountTyped)
{
pUser.UseResource(parseInt(amountTyped), silver)
CreateDFNItem(pSock, pUser, "0x0eed", amountAwarded, "ITEM", true);
pUser.SysMessage("you can exchange " + currencyTwo + " for " + currencyOne +" for the amount of " +amountAwarded);
currencystone(pUser, iUsed);
break;
}
else
{
pUser.SysMessage("You do not have enough " + currencyTwo + " to do this exchange");
currencystone(pUser, iUsed);
break;
}
}
else if (currencyOne == "silver" && currencyTwo == "copper")
{
if (pUser.ResourceCount(copper) >= amountTyped)
{
pUser.UseResource(parseInt(amountTyped), copper)
CreateDFNItem(pSock, pUser, "silvercoin", amountAwarded, "ITEM", true);
pUser.SysMessage("you can exchange " + currencyTwo + " for " + currencyOne +" for the amount of " +amountAwarded);
currencystone(pUser, iUsed);
break;
}
else
{
pUser.SysMessage("You do not have enough " + currencyTwo + " to do this exchange");
currencystone(pUser, iUsed);
break;
}
}
else if (currencyOne == "silver" && currencyTwo == "gold")
{
pUser.SysMessage("Sorry we don't support backward conversion yet");
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "copper" && currencyTwo == "gold")
{
pUser.SysMessage("Sorry we don't support backward conversion yet");
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "copper" && currencyTwo == "silver")
{
pUser.SysMessage("Sorry we don't support backward conversion yet");
currencystone(pUser, iUsed);
break;
}
}
else
{
pUser.SysMessage("You either didnt have amount or currency typed in the spaces provided.");
}
break;
case 2:
iUsed.SetTag("Options", true);
gmoptions(pUser, iUsed);
break;
case 3:
iUsed.SetTag("exrate", parseInt(exchangeRateedit));
iUsed.SetTag("examount", parseInt(exchangeAmountedit));
iUsed.SetTag("Options", false);
break;
}
}
{
var socket = pUser.socket;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
if (socket && iUsed && iUsed.isItem)
{
socket.tempObj = iUsed;
currencystone(pUser, iUsed);
}
return false;
}
function onCreateDFN(objMade, objType)
{
if (objType == 0)
{
if (objMade.name == "Currency Stone")
{
objMade.SetTag("exrate", 100);
objMade.SetTag("examount", 1);
}
}
}
function currencystone(pUser, iUsed)
{
var ExchangeRate = iUsed.GetTag("exrate");
var ExchangeAmount = iUsed.GetTag("examount");
var socket = pUser.socket;
var currency = new Gump;
socket.tempObj = iUsed;
currency.AddBackground(230, 200, 536, 270, 5054);
currency.AddTiledGump(260, 220, 470, 21, 3604);
currency.AddText(270, 220, 1153, "The current Exchange Rate is " + ExchangeRate + " for " + ExchangeAmount);
currency.AddTiledGump(510, 290, 117, 21, 3604);
currency.AddTiledGump(510, 320, 117, 21, 3604);
currency.AddTiledGump(290, 300, 141, 21, 3604);
currency.AddText(460, 290, 0, "Recieve");
currency.AddText(470, 320, 0, "Use");
currency.AddText(290, 280, 1153, "Enter the Amount to Trade");
currency.AddText(500, 270, 1153, "Enter Currency to Trade");
currency.AddText(680, 270, 87, "Currency");
currency.AddText(690, 290, 1153, "Gold");
currency.AddText(690, 310, 1153, "Silver");
currency.AddText(690, 330, 1153, "Copper");
currency.AddText(300, 390, 1153, "Is this agreeable?");
currency.AddTiledGump(300, 420, 89, 38, 3004);
currency.AddTiledGump(400, 420, 89, 38, 3004);
currency.AddText(310, 430, 1153, "Yes");
currency.AddText(410, 430, 1153, "No");
currency.AddButton(360, 430, 1209, 248, 1, 0, 1);
currency.AddButton(460, 430, 1209, 248, 1, 0, 0);
currency.AddText(300, 330, 0, "currency is rounded");
currency.AddTextEntryLimited(290, 300, 140, 20, 1153, 0, 13, "0", 6);
currency.AddTextEntry(510, 290, 117, 20, 1153, 0, 14, "");
currency.AddTextEntry(510, 320, 116, 20, 1153, 0, 15, "");
if (pUser.isGM)
{
currency.AddButton(670, 430, 2006, 248, 1, 0, 2);
}
currency.Send(socket);
currency.Free();
}
function gmoptions(pUser, iUsed)
{
var socket = pUser.socket;
var options = new Gump;
options.AddPage(0);
options.AddBackground(330, 250, 440, 130, 9200);
options.AddTiledGump(370, 270, 373, 21, 3604);
options.AddText(380, 270, 1153, "Here you can set the Exchnage Rate and Exchange Amount");
options.AddText(360, 310, 1153, "Exchange rate");
options.AddText(360, 340, 1153, "Exchange Amount");
options.AddTiledGump(480, 310, 140, 21, 3604);
options.AddTiledGump(480, 340, 140, 21, 3604);
options.AddButton(650, 340, 247, 248, 1, 0, 3);
options.AddText(640, 310, 1153, "Hit Okay to Save");
options.AddTextEntry(480, 310, 139, 20, 1153, 0, 5, "");
options.AddTextEntry(480, 340, 139, 20, 1153, 0, 6, "");
options.Send(pUser);
options.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var iUsed = pSock.tempObj;
var pUser = pSock.currentChar;
if (iUsed.GetTag("Options") != true)
{
var amountTyped = gumpData.getEdit(0);
var currencyOne = gumpData.getEdit(1);
var currencyTwo = gumpData.getEdit(2);
var exchangeRate = iUsed.GetTag("exrate");
var exchangeAmount = iUsed.GetTag("examount");
var amountAwarded = Math.round(amountTyped / exchangeRate) * exchangeAmount;
var checkAmount = amountTyped >= exchangeRate;
var numbers = /^[0-9a]+$/;
var numberCheck = amountTyped.match(numbers);
}
else
{
var exchangeRateedit = gumpData.getEdit(0);
var exchangeAmountedit = gumpData.getEdit(1);
}
var gold = 0x0eed;
var silver = 0x0ef0;
var copper = 0xeea;
switch (pButton)
{
case 0:break;
case 1:
if (currencyOne == "gold" || currencyOne == "silver" || currencyOne == "copper" || currencyTwo == "gold" || currencyTwo == "silver" || currencyTwo == "copper" && amountTyped.length <= 2 || amountTyped.length > 40)
{
if (!numberCheck)
{
pUser.SysMessage("Exchange Amount may only consist of Digits (0 - 9).");
currencystone(pUser, iUsed);
break;
}
if (currencyOne == "gold" && currencyTwo == "gold")
{
pUser.SysMessage("Can not exchange " +currencyOne+" for " + currencyTwo);
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "silver" && currencyTwo == "silver")
{
pUser.SysMessage("Can not exchange " +currencyOne+" for " + currencyTwo);
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "copper" && currencyTwo == "copper")
{
pUser.SysMessage("Can not exchange " +currencyOne+" for " + currencyTwo);
currencystone(pUser, iUsed);
break;
}
else if(!checkAmount)
{
pUser.SysMessage("You can not exchange less then the rate");
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "gold" && currencyTwo == "silver")
{
if (pUser.ResourceCount(silver) >= amountTyped)
{
pUser.UseResource(parseInt(amountTyped), silver)
CreateDFNItem(pSock, pUser, "0x0eed", amountAwarded, "ITEM", true);
pUser.SysMessage("you can exchange " + currencyTwo + " for " + currencyOne +" for the amount of " +amountAwarded);
currencystone(pUser, iUsed);
break;
}
else
{
pUser.SysMessage("You do not have enough " + currencyTwo + " to do this exchange");
currencystone(pUser, iUsed);
break;
}
}
else if (currencyOne == "silver" && currencyTwo == "copper")
{
if (pUser.ResourceCount(copper) >= amountTyped)
{
pUser.UseResource(parseInt(amountTyped), copper)
CreateDFNItem(pSock, pUser, "silvercoin", amountAwarded, "ITEM", true);
pUser.SysMessage("you can exchange " + currencyTwo + " for " + currencyOne +" for the amount of " +amountAwarded);
currencystone(pUser, iUsed);
break;
}
else
{
pUser.SysMessage("You do not have enough " + currencyTwo + " to do this exchange");
currencystone(pUser, iUsed);
break;
}
}
else if (currencyOne == "silver" && currencyTwo == "gold")
{
pUser.SysMessage("Sorry we don't support backward conversion yet");
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "copper" && currencyTwo == "gold")
{
pUser.SysMessage("Sorry we don't support backward conversion yet");
currencystone(pUser, iUsed);
break;
}
else if (currencyOne == "copper" && currencyTwo == "silver")
{
pUser.SysMessage("Sorry we don't support backward conversion yet");
currencystone(pUser, iUsed);
break;
}
}
else
{
pUser.SysMessage("You either didnt have amount or currency typed in the spaces provided.");
}
break;
case 2:
iUsed.SetTag("Options", true);
gmoptions(pUser, iUsed);
break;
case 3:
iUsed.SetTag("exrate", parseInt(exchangeRateedit));
iUsed.SetTag("examount", parseInt(exchangeAmountedit));
iUsed.SetTag("Options", false);
break;
}
}
19003=custom/currencyexchange.js
[cstone]
{
get=base_item
name=Currency Stone
id=0xED4
decay=0
movable=2
SCRIPT=19003
}
[silvercoin]
{
get=base_item
name=silver coin
id=0x0ef0
pileable=1
amount=1
decay=1
}
[coppercoin]
{
get=base_item
name=copper coin
id=0xeea
pileable=1
amount=1
decay=1
}
{
get=base_item
name=Currency Stone
id=0xED4
decay=0
movable=2
SCRIPT=19003
}
[silvercoin]
{
get=base_item
name=silver coin
id=0x0ef0
pileable=1
amount=1
decay=1
}
[coppercoin]
{
get=base_item
name=copper coin
id=0xeea
pileable=1
amount=1
decay=1
}