RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Gold to Token Currency Converter

Igon

Wanderer
Gold to Token Currency Converter

I had someone ask for this the other day, so I though i would post my first script.

Description:
This Mobile changes Gold for Tokens. Just drop Gold or BankCheck on him for a confirmation gump. Any unused gold will be returned to player.


In-Game Variables:
Active - True/False
Coin Limit - This is the point at which checks are given instead of coins.
Exchange Rate - Self explanatory, must be an int > 0

If you are GameMaster or above, double click for a gump to edit the above properties, or [props him.

Installation:
Drop in custom folder. This is built with Dupree's token system in mind, but any other system that uses the items, Tokens and TokensBankCheck, will work. If your token system uses different terminology change lines 187 and 195 to the appropriate items.

[add GoldExchanger to place in the world.

There is only 1 bug that I know of:
If your shard restarts while a player is in the middle of a transaction, his gold will be lost. Any thoughts on moving deletion down to the confirmation gump would be great.
 

Attachments

  • GoldExchanger.cs
    8.1 KB · Views: 381

Igon

Wanderer
septor said:
What's the exchange rate? Like, do you get as many Tokens as you drop Gold coins?

The Exchange Rate is exactly that, the rate at which Gold is exchanged for Tokens.
For example:

For an ExchangeRate of 20, if you drop 525 gold on him, you will receive 26 tokens (525/20 = 26.25, so 20*26 = 520) and the remaining 5 gold pieces will be returned to your backpack.
 

Kamron

Knight
If its still around.. you could have used my Cash script, which universally will consume the correct amount of any type of currency with an exchange rate to the base currency (copper or gold depending on the shard).
 

malgrimace

Sorceror
I don't think he meant "what's the exchange rate" as in asking what an exchange rate was - but how many tokens you get for your gold....

IE - 100 gold = 20 tokens.
 

nadious

Sorceror
When you said you made a change, did you have to change it to make it work for RC2, or did you change the mechanics of the script itself?
 

doaker

Wanderer
ok people on my shard likes this vendor guy but they asked me for a guy the traded tokens for gold the guy gives 20 to 1 for the tokens how can i trade them for 20 to 1 for gold when i do it gives 1 gold peaces for 20 tokens basiclly im tring to go 1 to 20 on the flip of the odds on him i tried to change the 20 to 1 odds to 20 to1 but it still comes out short for the gold??
Code:
using System;
using System.Collections;
using System.IO;
using Server;
using Server.Items;
using Server.Misc;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;

namespace Server.Mobiles
{
	public class TokenExchanger : Mobile
	{
		private bool b_Active = true;
		private int i_ExchangeRate = 20; //20 token for 1 gold
		private int i_CoinLimit = 10000; //Limit of gold returned or tokens given before a check is used

		[CommandProperty( AccessLevel.GameMaster )]
		public int ExchangeRate
		{
			get{ return i_ExchangeRate; }
			set{ i_ExchangeRate = value; InvalidateProperties(); }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool Active
		{
			get { return b_Active; }
			set { b_Active = value; }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int CoinLimit
		{
			get{ return i_CoinLimit; }
			set{ i_CoinLimit = value; InvalidateProperties(); }
		}

		[Constructable]
		public TokenExchanger()
		{
			Body = 400;
			Name = "Token Exchanger:";
			Title = "Exchange Rate is " + ExchangeRate + " to 1";
			Hue = Utility.RandomSkinHue();
			Blessed = true;
			Direction = (Direction)3;
			InitStats( 100, 25, 100 );

			AddItem( new LongPants( Utility.RandomNeutralHue() ) );
			AddItem( new FancyShirt( Utility.RandomNeutralHue() ) );
			AddItem( new Boots( Utility.RandomNeutralHue() ) );
			AddItem( new Cloak( Utility.RandomNeutralHue() ) );
			AddItem( new BodySash( Utility.RandomNeutralHue() ) );

			Container pack = new Backpack();
			pack.Movable = false;
			AddItem( pack );
		}

		public override bool OnDragDrop( Mobile m, Item t )
		{
			if ( b_Active )
			{
				if ( t is Tokens )
				{
					int i_Amount = t.Amount;
					int i_Gold = i_Amount / i_ExchangeRate;
					int i_Tokens = i_Gold * i_ExchangeRate;
					m.SendGump( new TokenExchangerGump( m, i_ExchangeRate, i_Tokens, i_Amount, i_CoinLimit ) );
					return true;
				}
				else if (t is TokenCheck )
				{
					int i_Amount = ((TokenCheck)t).Worth;
					int i_Gold = i_Amount / i_ExchangeRate;
					int i_Tokens = i_Gold * i_ExchangeRate;
					m.SendGump( new TokenExchangerGump( m, i_ExchangeRate, i_Tokens, i_Amount, i_CoinLimit ) );
					return true;
				}
				else
				{
					m.SendMessage( "This isn't tokens!" );
					return false;
				}
			}
			else
			{
				m.SendMessage( "The Exchanger is not active now. Please try again later" );
				return false;
			}
		}
		//Admin Gump
		public override void OnDoubleClick( Mobile from )
		{
			if ( from.AccessLevel > AccessLevel.Counselor )
			{
				from.SendGump( new TokenExchangerAdminGump( this, this.Active, this.CoinLimit, this.ExchangeRate ) );
			}
		}
		public TokenExchanger( Serial serial ) : base( serial )
		{
		}


		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 );
			writer.Write( b_Active );
			writer.Write( i_ExchangeRate );
			writer.Write( i_CoinLimit );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			b_Active = reader.ReadBool();
			i_ExchangeRate = reader.ReadInt();
			i_CoinLimit = reader.ReadInt();
		}
	}
}

namespace Server.Gumps
{
	public class TokenExchangerGump : Gump
	{
		private Mobile m_From;
		private int i_Tokens;
		private int i_ExchangeRate;
		private int i_Gold;
		private int i_Amount;
		private int i_CoinLimit;

		public TokenExchangerGump(Mobile from, int ExchangeRate, int tokens, int amount, int coinlimit): base( 100, 100 )
		{
			i_Amount = amount;
			m_From = from;
			i_Tokens = tokens;
			i_ExchangeRate = ExchangeRate;
			i_CoinLimit = coinlimit;
			int gold = i_Tokens / i_ExchangeRate;
			from.SendMessage("You are wanting to exchange {0} token pieces", tokens );
			Closable=false;
			Disposable=true;
			Dragable=true;
			Resizable=false;
			AddPage(0);
			AddBackground(0, 0, 280, 130, 5054);	//Grey Background 129
			AddImageTiled(13, 15, 253, 21, 3604);	//Top Dark Blue Box
			AddLabel(17, 15, 1153, "The current Exchange rate is " + ExchangeRate + " to 1");

			AddLabel(16, 50, 1153, tokens + " token for " + gold +" Gold" );

			AddImageTiled(43, 70, 145, 21, 3604);	//Bottom Dark Blue Box
			AddLabel(53, 69, 1153, "Is this agreeable?");

			AddImageTiled(43, 89, 145, 21, 3004);	//White Yes/No Box
			AddButton(53, 93, 1209, 1210, 1, GumpButtonType.Reply, 0); //Yes Button
			AddLabel(77, 90, 0, "Yes");
			AddButton(132, 93, 1209, 1210, 2, GumpButtonType.Reply, 0); //No Button
			AddLabel(152, 90, 0, "No");
			AddImageTiled(43, 70, 1, 41, 2624);	//Outlining - Verticle - Left
			AddImageTiled(43, 70, 144, 1, 2624);	//Outlining - Horizontal - Top
			AddImageTiled(188, 70, 1, 41, 2624);	//Outlining - Verticle - Right
			AddImageTiled(44, 89, 144, 1, 2624);	//Outlining - Horizontal - Middle
			AddImageTiled(115, 89, 1, 22, 2624);	//Outlining - Verticle - Middle
			AddImageTiled(44, 110, 144, 1, 2624);	//Outlining - Horizontal - Bottom
		}
		public override void OnResponse( NetState state, RelayInfo info )
		{
			Mobile m_From = state.Mobile;
			Container c = m_From.Backpack;
			int i_Gold = i_Tokens / i_ExchangeRate;

			switch ( info.ButtonID )
			{
				case 1: //Yes
				{
					if ( c != null )
					{
						if ( i_Gold > i_CoinLimit || i_Gold > 60000 )
						{
							m_From.AddToBackpack( new BankCheck( i_Gold ) ); //gold Exchanged
							if ( ( i_Amount - i_Gold ) > 0)
							{
								m_From.AddToBackpack( new Tokens( i_Amount - i_Tokens ) ); //return Remainder of tokens
							}
						}
						else
						{
							m_From.AddToBackpack( new Gold( i_Gold ) ); //Tokens Exchanged
							if ( ( i_Amount - i_Tokens ) > 0)
							{
								m_From.AddToBackpack( new Tokens( i_Amount - i_Tokens ) ); //return Remainder of tokens
							}
						}
					}
					break;
				}
				case 2: //No
				{
					if ( c != null )
					{
						if ( i_Amount > i_CoinLimit || i_Amount > 60000)
						{
							m_From.AddToBackpack( new TokenCheck( i_Amount ) ); //return Remainder of tokens
						}
						else
						{
							m_From.AddToBackpack( new Tokens( i_Amount ) ); //Return ALL gold
						}
					}
					break;
				}
			}
		}
	}
	public class TokenExchangerAdminGump : Gump
	{
		private TokenExchanger Exchanger;

		public TokenExchangerAdminGump(TokenExchanger m_exchanger, bool Active, int CoinLimit, int ExchangeRate): base( 100, 100 )
		{
			Exchanger = m_exchanger;

			Closable=true;
			Disposable=true;
			Dragable=true;
			Resizable=false;

			AddPage(0);
			AddBackground(0, 0, 300, 129, 5054);	//Grey Background
			AddLabel(82, 4, 1153, "Token Exchanger Admin");
			AddImageTiled(8, 32, 279, 87, 3604);	//Dark Blue Box

			//Active
			AddLabel(27, 39, 1153, "Active");
			AddImageTiled(20, 69, 59, 20, 3004);	//White Active Box
			AddTextEntry( 25, 69, 53, 20, 0, 90, Active.ToString() );

			//Coin Limit
			AddLabel(114, 39, 1153, "Coin Limit");
			AddImageTiled(118, 69, 59, 20, 3004);	//White Coin Limit Box
			AddTextEntry( 123, 69, 53, 20, 0, 91, CoinLimit.ToString() );

			//Exchange Rate
			AddLabel(232, 39, 1153, "Rate");
			AddImageTiled(216, 69, 59, 20, 3004);	//White Exchange Rate Box
			AddTextEntry( 221, 69, 53, 20, 0, 92, ExchangeRate.ToString() );

			AddButton(260, 100, 1209, 1210, 93, GumpButtonType.Reply, 0); //Apply Button
			AddLabel(222, 95, 1153, "Apply");
		}

		public override void OnResponse( NetState state, RelayInfo info )
		{
			Mobile m_From = state.Mobile;
			if ( Exchanger.Deleted )
			return;

			switch ( info.ButtonID )
			{
				case 93: //Apply
				{
					try
					{
						TextRelay t_active = info.GetTextEntry( 90 );
						Exchanger.Active = Convert.ToBoolean (t_active.Text);

						TextRelay t_coinlimit = info.GetTextEntry( 91 );
						Exchanger.CoinLimit = Convert.ToInt32(t_coinlimit.Text);

						TextRelay t_exchangerate = info.GetTextEntry( 92 );
						Exchanger.ExchangeRate = Convert.ToInt32(t_exchangerate.Text);
						Exchanger.Title = "Exchange Rate is " + Exchanger.ExchangeRate + " to 1";
						break;
					}
					catch{break;}
				}
			}
		}
	}
}
can some one help me figure out how to change this. Now i change from the gold to tokens and from tokens to gold from the original script ty.
 
notice the paerts in red
checge the * to / and the / to *
should do it

Code:
				if ( t is Tokens )
				{
					int i_Amount = t.Amount;
					[COLOR="Red"]int i_Gold = i_Amount / i_ExchangeRate;
					int i_Tokens = i_Gold * i_ExchangeRate;[/COLOR]
					m.SendGump( new TokenExchangerGump( m, i_ExchangeRate, i_Tokens, i_Amount, i_CoinLimit ) );
					return true;
				}
				else if (t is TokenCheck )
				{
					int i_Amount = ((TokenCheck)t).Worth;
					[COLOR="red"]int i_Gold = i_Amount / i_ExchangeRate;
					int i_Tokens = i_Gold * i_ExchangeRate;[/COLOR]
					m.SendGump( new TokenExchangerGump( m, i_ExchangeRate, i_Tokens, i_Amount, i_CoinLimit ) );
					return true;
				}
 

doaker

Wanderer
ok i tried returning it to that it now says 100 tokens for 0 gold in the GoldExchanger script its say if you give him 100 gold he gives you 5 tokens im tring to make a tokenExchanger when you give him like 5 tokens he gives you 100 gold coins but it still says 100 tokens to 5 gold. i tried that but now im getting losts looking how to swich the 2 so it be different from each other. i hope this helps someone toto know what im tring to do ??:confused:
 

doaker

Wanderer
the GoldExchanger says 20 to 1 odds. when you give him 100 gold he gives you 5 tokens i took where its says gold turned to tokens and tokens to gold so it makes TokenExchanger which he also 20 to 1 odds 100 tokens 5 gold how can i change the script where its like 1 to 20 odds where 5 tokens will give you 100 gold:confused: i tried to change ( to 1 )and(to 20 and the odds up but still it gives more tokens for gold or it has no amount)
 
in the avove quote i did before - change tokens to gold and gold with tokens and then added to pack, etc add gold instead of tokens
 

doaker

Wanderer
when i do that it comes up as 100 to 0 odd dont even get any gold back for the tokens. like you have in red is the way he has it for the GoldExchanger. it is puzzling me like crazzy.
 
Top