Go Back   RunUO - Ultima Online Emulation > RunUO > Custom Script Releases
Welcome, Nockar.
You last visited: 11-22-2009 at 07:57 PM
Private Messages: Unread 0, Total 0.

Custom Script Releases This forum is where you can release your custom scripts for other users to use.

Please note: By releasing your scripts here you are submitting them to the public and as such agree to publish them under the GPL licensing terms. The RunUO Team has made its software GPL for you to use and enjoy you should do the same for anything based off of RunUO.

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 02-02-2007, 07:14 PM   #1 (permalink)
the_hopkins
Lurker
 
Join Date: Aug 2003
Posts: 17
Default [RunUO 2.0 RC1] Randomized Vendor Prices and Amounts

I never liked the fact that every vendor charges the exact same for a given item, pays the same for said item, and has the same quantity of that item for sale. I wanted some variation in all of the above to simulate a real economy a bit better. After a bit of mashing up code, I came up with the following changes. The result is that buy and sell prices, as well as the amounts, are randomized when the vendor is initially spawned. Each vendor therefore has his or her own pricing scale, meaning that you might want to shop around before purchasing or selling large quantities of items. It adds a bit more roleplay to the game.

The system uses the default sb* files without changes. Originally I was editting every one of them heavily, but was pointed towards modifying the loading functions instead (thanks Lord_Greywolf and Sotho Tal Ker). The functions use the base amounts listed in the sb* files and randomize them as follows:

Purchasing from vendor(set in GetRandBuyPriceFor())
Min. Price - 80% of listed price
Max. Price 130% of listed price

Selling to a vendor(set in GetRandSellPriceFor())
Min. Price - 70% of listed price
Max. Price - 120% of listed price

Amount of item vendor carries(set in GetRandAmountFor())
Min. Amount - 40% of listed amount
Max. Amount - 160% of listed amount

You can change the min and max values to whatever you prefer. The functions are weighted so that the majority of the time the values are roughly what's listed in the sb* files, with occasional values much higher or lower. Optionally, you can force the vendor to randomize these numbers every time they restock, rather than only when they're spawned, to better simulate the changing prices in a real economy.

Three files are modified: genericbuy.cs, genericsell.cs, and optionally, basevendor.cs. These are all located in the .\scripts\mobiles\vendors\ folder.

GenericBuy.cs

Change:
Code:
		public GenericBuyInfo( string name, Type type, int price, int amount, int itemID, int hue, object[] args )
		{
			amount = 20;
		
			m_Type = type;
			m_Price = price;
			m_MaxAmount = m_Amount = amount;
			m_ItemID = itemID;
			m_Hue = hue;
			m_Args = args;
		
			if ( name == null )
				m_Name = (1020000 + (itemID & 0x3FFF)).ToString();
			else
				m_Name = name;
		}
to
Code:
		public GenericBuyInfo( string name, Type type, int price, int amount, int itemID, int hue, object[] args )
		{
			//amount = 20;
		
			m_Type = type;
			m_Price = GetRandBuyPriceFor( price );
			m_MaxAmount = m_Amount = GetRandBuyAmountFor( amount );
			m_ItemID = itemID;
			m_Hue = hue;
			m_Args = args;
		
			if ( name == null )
				m_Name = (1020000 + (itemID & 0x3FFF)).ToString();
			else
				m_Name = name;
		}
Just above the following:
Code:
		public virtual void OnRestock() //may be public void OnRestock()
		{
			if ( m_Amount <= 0 )
			{
add this:
Code:
		public static int GetRandBuyPriceFor( int itemPrice )
		{
			int lowPrice = (int)( .8 * itemPrice );
			int highPrice = (int)( 1.3 * itemPrice );
			int price = 0;
			for ( int i = 1; i <= 3; i++ )
			{
				price += Utility.RandomMinMax( lowPrice, highPrice );
			}
			price /= 3;
			if ( price < 1 )
				price = 1;
			return price;
		}
		
		public static int GetRandBuyAmountFor( int itemAmount )
		{
			int lowAmount = (int)( .4 * itemAmount );
			int highAmount = (int)( 1.6 * itemAmount );
			int amount = 0;
			for ( int i = 1; i <= 3; i++ )
			{
				amount += Utility.RandomMinMax( lowAmount, highAmount );
			}
			amount /= 3;
			if ( amount < 1 )
				amount = 1;
			return amount;
		}
GenericSell.cs

Change:
Code:
		public void Add( Type type, int price )
		{
			m_Table[type] = price;
			m_Types = null;
		}
to
Code:
		public void Add( Type type, int price )
		{
			m_Table[type] = GetRandSellPriceFor( price );
			m_Types = null;
		}

		public static int GetRandSellPriceFor( int itemPrice )
		{
			int lowPrice = (int)( .7 * itemPrice );
			int highPrice = (int)( 1.2 * itemPrice );
			int price = 0;
			for ( int i = 1; i <= 3; i++ )
			{
				price += Utility.RandomMinMax( lowPrice, highPrice );
			}
			price /= 3;
			if ( price < 1 )
				price = 1;
			return price;
		}
Basevendor.cs (Optional, only if you want everything randomized upon every restock)

Just below:
Code:
		public virtual void Restock()
		{
			m_LastRestock = DateTime.Now;
add this:
Code:
			LoadSBInfo();
I've attached copies of GenericBuy.cs and GenericSell.cs for those who have unmodified RunUO distros. If you've modified these files, either follow the above instructions or use WinMerge. I haven't included Basevendor.cs because the change is optional, it's one line, and many other packages also modify basevendor, so it's likely you'd need to manually make the change anyway.
Attached Files
File Type: cs GenericBuy.cs (8.2 KB, 152 views)
File Type: cs GenericSell.cs (3.0 KB, 139 views)

Last edited by the_hopkins; 02-06-2007 at 06:06 PM. Reason: Bugfix
the_hopkins is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-03-2007, 01:15 AM   #2 (permalink)
Lord_Greywolf
Master of the Internet
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 11,236
Send a message via Yahoo to Lord_Greywolf
Default

I am very glad you got this working!!!!

Will be giving it a look see - and probaly be using it
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-03-2007, 09:04 AM   #3 (permalink)
the_hopkins
Lurker
 
Join Date: Aug 2003
Posts: 17
Default

I just fixed a rather dumb mistake that could allow prices or amounts to be 0 if the original price or amount was 1. Updated code is shown in green in the listing above, the attached files have been updated as well.
the_hopkins is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-03-2007, 01:02 PM   #4 (permalink)
Broadside
Forum Expert
 
Broadside's Avatar
 
Join Date: Jul 2004
Location: Minnesota
Age: 33
Posts: 1,488
Send a message via ICQ to Broadside Send a message via MSN to Broadside Send a message via Yahoo to Broadside
Default

Hrmm cool idea this will make it seem more realistic. Nice work.
__________________
Broadside ~AkA~ Bad Karma
Broadside is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-06-2007, 03:44 PM   #5 (permalink)
Lord_Greywolf
Master of the Internet
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 11,236
Send a message via Yahoo to Lord_Greywolf
Default

found the little bug in it - but not your bug - the origional bug put in by the runuo staff - you just carried it on

in genericbuy

Code:
		public GenericBuyInfo( string name, Type type, int price, int amount, int itemID, int hue, object[] args )
		{
			amount = 20;

			m_Type = type;
remove the line in red - or the quanities you put in in the lists will be voided and will base it off of 20
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-06-2007, 06:05 PM   #6 (permalink)
the_hopkins
Lurker
 
Join Date: Aug 2003
Posts: 17
Default

Yah, I've got it commented out in the above scripts, but I did forget to highlight it as something you need to change in your own file. That was the first thing I did when I installed RunUO, and I kinda forgot the file didn't come that way. Thanks for pointing that out.
the_hopkins is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-06-2007, 06:48 PM   #7 (permalink)
Greystar
Forum Expert
 
Greystar's Avatar
 
Join Date: Mar 2004
Location: NorthCentral IL, USA
Age: 36
Posts: 3,974
Default

Interesting now if you could also make it Region/Map Specific it could be even more "real" by making so that things in Tokuno that are "normal" priced in say Vesper would be ALOT more expensive because of importing. On something like that... also maybe combining it with the Colored ore cost changes that someone provided ages ago on the Forums...
__________________
Quote:
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
Killable Guards (GS Version)
Just a Simple Staff Tool
You can leave me messages.
Ernest Gary Gygax - Quote "I would like the world to remember me as the guy who really enjoyed playing games and sharing his knowledge and his fun pastimes with everybody else."
Greystar is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-07-2007, 12:05 AM   #8 (permalink)
the_hopkins
Lurker
 
Join Date: Aug 2003
Posts: 17
Default

Greystar:

I was thinking about making prices region specific for my shard, too. That shouldn't really be a problem; the SB* files should be able to be set up to be region specific (I haven't gotten a chance to look into it yet), and my changes will then modify those prices as they normally would. You should just be able to add <using Server.Regions> to the includes in your SB* files, then call whatever property contains the current region and act on that. Switch statements work within SB* files, as do if statements, so you could either (in pseudo-code):

Code:
if ( CurrentRegion = Vesper )
{
     Add GenericBuyInfo with Price = 100
     Continue for each item you want to vary in price by region
}
else if ( CurrentRegion = Tokuno )
{
     Add GenericBuyInfo with Price = 300
     Continue for each item
}
or:

Code:
Switch ( CurrentRegion )
case Vesper:
     Add GenericBuyInfo with Price = 100
     Continue for each item
     break
case Tokuno:
     Add GenericBuyInfo with Price = 300
     Continue for each item
     break
I could add the region checking code into my changes, but as I've no idea what you want to be more expensive in one region than in another, the net result would be that every item is more expensive in this region than in that one, which isn't how I'd personally like for it to work. I'd like magery, scribe, and alchemy item related prices to be lower in Moonglow than in, for example, Minoc, because it's the center of magical studies in Brittania and there's a surplus of those items there. Conversely, I'd like anything created using Blacksmithy to be less expensive in Minoc than elsewhere, for the same reasons. And the easiest, most reliable way to do that is in the SB* files.

As for the colored ore price changes, that's high on my list, although I probably wouldn't bundle it in with these changes, because there are several different colored resource packages out there. I'm using Daat99's OWLTR, and Karmageddon (I think) has one, and there's at least one other. I imagine a colored resource pricing mod would need to be tailored specifically for each one. I know when I was rooting around in the code, I spotted a function to alter the price based on the item's quality and I thought it would be an easy matter to just hook into that function and modify price based on color as well (guess it might have been a good idea to write down where the function was, huh? ).
the_hopkins is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-07-2007, 09:44 AM   #9 (permalink)
Broadside
Forum Expert
 
Broadside's Avatar
 
Join Date: Jul 2004
Location: Minnesota
Age: 33
Posts: 1,488
Send a message via ICQ to Broadside Send a message via MSN to Broadside Send a message via Yahoo to Broadside
Default

Perhaps making fel prices different as well?? As soon as i am finished with my ml fun i will get this working on my shard.
__________________
Broadside ~AkA~ Bad Karma
Broadside is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 02-07-2007, 04:59 PM   #10 (permalink)
Greystar
Forum Expert
 
Greystar's Avatar
 
Join Date: Mar 2004
Location: NorthCentral IL, USA
Age: 36
Posts: 3,974
Default

Quote:
Originally Posted by Broadside View Post
Perhaps making fel prices different as well?? As soon as i am finished with my ml fun i will get this working on my shard.
Same concept as the region thing I mentioned...

yeah the best place for it would probably be in the actual sell/buy code, but I'm not too sure and I don't really script anymore and dont even run a shard, but I thought it might be a good idea. Just throwing out suggestions... I've used both Daat99's code and Karmageddons I stopped using Daat99s when it started getting too complicated for what I wanted and went for something easier to edit, both is good code though.
__________________
Quote:
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
Killable Guards (GS Version)
Just a Simple Staff Tool
You can leave me messages.
Ernest Gary Gygax - Quote "I would like the world to remember me as the guy who really enjoyed playing games and sharing his knowledge and his fun pastimes with everybody else."
Greystar is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 11-02-2008, 06:24 PM   #11 (permalink)
Soulflyas
Lurker
 
Join Date: Oct 2008
Age: 21
Posts: 2
Default

Great Script thank you !
Soulflyas is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 12-18-2008, 12:48 PM   #12 (permalink)
Onirim
Lurker
 
Onirim's Avatar
 
Join Date: Dec 2003
Posts: 13
Send a message via ICQ to Onirim
Default

Someone have a version of this excellent script compatible with RunUO RC2 ?
I've a lot of errors when i use it :x

Errors:
+ Mobiles/Vendors/GenericBuy.cs:
CS0535: Line 9: 'Server.Mobiles.GenericBuyInfo' does not implement interface
member 'Server.IBuyItemInfo.GetEntity()'
+ Mobiles/Vendors/BeverageBuy.cs:
CS0115: Line 29: 'Server.Mobiles.BeverageBuyInfo.GetEntity()': no suitable m
ethod found to override
+ Mobiles/Vendors/PresetMapBuy.cs:
CS0115: Line 18: 'Server.Mobiles.PresetMapBuyInfo.GetEntity()': no suitable
method found to override

:/
__________________
Onirim,
Administrator of UO Classic [fr] (uoclassic.free.fr)
Onirim is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Old 12-23-2008, 04:58 PM   #13 (permalink)
Miller.
Forum Novice
 
Join Date: Feb 2008
Location: UOResurgence.com
Age: 28
Posts: 211
Default

If you just put the edits into your original RC2 files as described above (instead of replacing them with the posted .cs files) then the script edits still work fine. The errors are because the GenericBuy and GenericSell files that are modified as posted are from prior to RC2.

Also, post RC2 that line regarding amount is already deleted from the GenericBuy.cs file. (Note that those posts were coming from February 2007, before the change)
__________________
Miller. is offline Report Post   Reply With Quote Multi-Quote This Message Quick reply to this message
Reply

Bookmarks

Tags
None

Quick Reply
Message:
Remove Text Formatting
Bold
Italic
Underline

Insert Image
Wrap [QUOTE] tags around selected text
 
Check Spelling
Decrease Size
Increase Size
Switch Editor Mode
Options


Currently Active Users Viewing This Thread: 1 (1 members and 0 guests)
Nockar

Posting Rules
You may post new threads
You may post replies
You may post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5