Resource icon

OSI Accurate Bounty System 1.02

No permission to download

Jack

Well-Known Member
Sep 23, 2014
163
33
Auckland, New Zealand
Shard Name
Lost Lands
Jack submitted a new resource:

OSI Accurate Bounty System - A drag-drop compatible, OSI accurate bounty system.

This is an OSI accurate bounty system that was disabled with publish 16, June 2002, which coincided with the removal of stat loss for player killers. It is completely drag drop compatible (tested versions: RunUO 2.2, RunUO 2.5, ServUO current). It is compatible with the account gold system that was added to ServUO recently.

When I was created my own shard I was astounded that this system did not exist by default, and no-one had ever released it. As a newbie coder it took me a lot of...
Read more about this resource...
 
  • Like
Reactions: TheDoc

Hank

Well-Known Member
Nov 14, 2013
947
151
Earth
Wow! Thank you so much @Jack for sharing this!
This bounty system is very notorious.(bad pun) I'm sure people will find this resource very useful.
 

Jack

Well-Known Member
Sep 23, 2014
163
33
Auckland, New Zealand
Shard Name
Lost Lands
Cheers! It took me some time and thought to get this to be fully drag drop compatible. Hope it serves the community well.
 

Moody

Well-Known Member
Feb 5, 2015
66
11
29
New Zealand
www.uorevealed.com
Shard Name
UO Revealed
Hey @Jack - thanks for this resource. We've implemented on our development server and will be rolling it out soon!

There are a couple of issues though (but easily fixable)!

1) You're checking for whether or not the new banking system has been activated by checking for the ServUO tag. You shouldn't do this, because some people might be using ServUO but NOT the new banking system. I'd suggest using something like AccountGold.Enabled - which is defined in the CurrentExpansion.cs file. This is the "switch" that needs to be flipped to turn on the new banking system.

2) The second major issue is what happens when someone posts a bounty of more money than what they have - the Withdraw function runs and regardless of whether or not it succeeded, the bounty goes through. Essentially, if someone only has 500k gold and posts a bounty of 1mil, then no gold will be withdrawn from their account and there will be a bounty of 1mil gold placed! To solve this, put the check for whether or not a bounty was input and whether or not the Withdraw was successful at the beginning of the OnResponse from the gump (BEFORE you even add a murder count). This will allow you to reprompt the player with a gump if the input is wrong.

That's about it! Everything else seems to work fine. Thanks so much for putting in so much legwork!
 

Jack

Well-Known Member
Sep 23, 2014
163
33
Auckland, New Zealand
Shard Name
Lost Lands
Hey @Jack - thanks for this resource. We've implemented on our development server and will be rolling it out soon!

There are a couple of issues though (but easily fixable)!

1) You're checking for whether or not the new banking system has been activated by checking for the ServUO tag. You shouldn't do this, because some people might be using ServUO but NOT the new banking system. I'd suggest using something like AccountGold.Enabled - which is defined in the CurrentExpansion.cs file. This is the "switch" that needs to be flipped to turn on the new banking system.

2) The second major issue is what happens when someone posts a bounty of more money than what they have - the Withdraw function runs and regardless of whether or not it succeeded, the bounty goes through. Essentially, if someone only has 500k gold and posts a bounty of 1mil, then no gold will be withdrawn from their account and there will be a bounty of 1mil gold placed! To solve this, put the check for whether or not a bounty was input and whether or not the Withdraw was successful at the beginning of the OnResponse from the gump (BEFORE you even add a murder count). This will allow you to reprompt the player with a gump if the input is wrong.

That's about it! Everything else seems to work fine. Thanks so much for putting in so much legwork!
1) Don't have time to look right now but I have a question - from what I recall there isn't any check for what system is being used at all. It just uses the banker deposit and banker withdraw functions which do the account gold checks themselves don't they? Admittedly making this ServUO compatible was an afterthought and I didn't spend much time looking into it, but my understanding was that the withdraw/deposit functions take care of this. I did however test that both AccountGold and non AccountGold worked to bounty/collect.

2) This is a serious issue and I will fix this tonight. It was introduced when I did some last minute refactoring for ServUO and forgot to cap the bounty at the amount of gold in the bank.
 
Last edited:

Moody

Well-Known Member
Feb 5, 2015
66
11
29
New Zealand
www.uorevealed.com
Shard Name
UO Revealed
The problem still exists, from what I can see.

Code:
killer.Kills++;
killer.ShortTermMurders++;

.......

((PlayerMobile) from).RecentlyReported.Add(killer);
		if (bounty > 0)
		{
#if ServUO
			Banker.Withdraw(from, bounty);
#else
			RemoveGoldFromBank(from, bounty);
#endif
			BountyInformation.AddBounty(pk, bounty, true);

			pk.SendMessage("{0} has placed a bounty of {1} {2} on your head!", from.Name,
				bounty, bounty == 1 ? "gold piece" : "gold pieces");
			pk.Say(500546); // I am now bounty hunted!

			from.SendMessage("You place a bounty of {0}gp on {1}'s head.", bounty, pk.Name);
		}
You're processing the murder count BEFORE you're checking whether or not they have the right amount of money in their account. Moreover - you're not even checking if they have the right amount of money. "Banker.Withdraw" will TRY to remove the set amount - but if it can't, then it will fail, but the bounty will still be placed. (If you input more than what's in your bank account, your RemoveGoldFromBank function will eat through ALL the gold in the bank before continuing on and placing the original bounty).

This can all be easily fixed (assuming you're using the Banker.Withdraw function).

Code:
if (bounty > 0)
{
	if (Banker.Withdraw(from, bounty))
   {
			BountyInformation.AddBounty(pk, bounty, true);

			pk.SendMessage("{0} has placed a bounty of {1} {2} on your head!", from.Name,
				bounty, bounty == 1 ? "gold piece" : "gold pieces");
			pk.Say(500546); // I am now bounty hunted!

			from.SendMessage("You place a bounty of {0}gp on {1}'s head.", bounty, pk.Name);
   } else {
		   from.SendMessage("You do not have that much gold in your bank!");
		   from.SendGump(new ReportMurdererBountyGump(from, _killers, _idx));
		   return;
   }
}
You also need to place this code BEFORE you increment the murder counts. That way the user will keep getting prompted until they put in a valid amount.
 

Moody

Well-Known Member
Feb 5, 2015
66
11
29
New Zealand
www.uorevealed.com
Shard Name
UO Revealed
As for your custom gold eating function. I'd make it search through the bankbox NOT eating gold, but just checking if there is enough gold in there before searching through the bankbox again and eating the gold. I'd also switch it from a void function to a bool function so you can return whether or not the gold has been consumed and you can put it in an if statement the same way I did in the above code.
 

Jack

Well-Known Member
Sep 23, 2014
163
33
Auckland, New Zealand
Shard Name
Lost Lands
Hmm, did you download the latest version?

The code you pasted seems to be missing this:

Code:
     var bounty = Math.Min( Utility.ToInt32(c.Text), GetBountyMax( from ) );
								
     if (bounty > 0)
     {
The bounty is now calculated as a minimum of what the person entered vs what the actual amount of gold in the bank is.

Because of this, when we actually go to withdraw, we know that the bank has that much gold in it. If the person entered 1,000,000 gold and they only have 30 gold in their bank, then the var "bounty" will hold 30 in it. Correct me if I'm wrong but I cannot see any situation in which Banker.Withdraw(from, bounty); or RemoveGoldFromBank(from, bounty); would withdraw anything but either what the person entered, or the total amount of gold in the bank.

Kills are added regardless of whether the person entered a bounty or not, and a bounty is only applied if the person has gold in their bank.
 

Moody

Well-Known Member
Feb 5, 2015
66
11
29
New Zealand
www.uorevealed.com
Shard Name
UO Revealed
Ok, so that checks out functionally. But what occurs when a typo happens? Someone enters 1000 when they only have 100 will result in no bounty being created. As a player, I'd be confused if that happened. Obviously I want to create a bounty, but because I entered too much money in there, a bounty is not being created.

Call it being a stickler for best-practice. But Banker.Withdraw already checks if you have enough money within it. You're creating all these redundant functionalities that are already present in other parts of the codebase. I would sanitise the amount input and then just stick it in the Banker.Withdraw which returns a bool.

If, for whatever reason, you want to change the way that gold is calculated in an account on the server - if you're using your script, you're going to have to not only change the code inside Banker but also find the snippet of code inside the bounty system and change that. Also, if this is a coding habit and you're creating more and more systems all with their own checks for whether or not you have money, then you're going around plugging holes rather than just changing it from one location.

There's more than one right answer for coding. It's just... some correct answers are better than other correct answers ;)
 

Jack

Well-Known Member
Sep 23, 2014
163
33
Auckland, New Zealand
Shard Name
Lost Lands
Ok, so that checks out functionally. But what occurs when a typo happens? Someone enters 1000 when they only have 100 will result in no bounty being created. As a player, I'd be confused if that happened. Obviously I want to create a bounty, but because I entered too much money in there, a bounty is not being created.
Well this isn't actually true, it would create a 100gp bounty in that situation.

You are right that these should use the banker balance/withdraw/deposit functions, that code itself was written a long time ago when I was new to coding and for whatever reason at the time I didn't think such a function existed in Banker.cs. On review even RunUO 2.2 contains a bool function for deposit/withdraw.
 

Tasanar

Moderator
ServUO Developer
Oct 16, 2014
4,546
123
32
trueuo.com
Shard Name
Heritage
Donate
Donate money to this user
So I just installed this on a pre aos shard.

Newest SVN

Two issues

1. the bounty guards disappear like normal guards would after a few seconds of being spawned. (can fix that myself)

2. had a player kill another player, player was not prompted to enter a bounty.
 
Last edited:

Jack

Well-Known Member
Sep 23, 2014
163
33
Auckland, New Zealand
Shard Name
Lost Lands
I wonder if something changed with guards, I'll test this out with the newest version of ServUO when I get some free time.