I am working on a stone that players can contribute gold to a common goal. The idea is that they would double click the stone to get the gump, which displays the goal and the current amount contributed. There's a button they can click to get a target, and they would target either a pile of gold or a bank check. The problem I'm having is figuring out how to get the amount of the gold or value of the bank check to add to the contribution amount. Both scripts are attached for reference. This is the method where I need some help:


Code:
public class GoalStoneTarget : Target
    {
        private GoalStone GSparent;

        public GoalStoneTarget(GoalStone parentGS) : base(-1, true, TargetFlags.None)
        {
            GSparent = parentGS;
           
        }

        protected override void OnTarget(Mobile from, object o)
        {
            if (GSparent == null || from == null || o == null)
            {
                Console.WriteLine("GoalStone: That's odd. Better call a GM");
                return;
            }
           

           if (o is Gold || o is BankCheck) //Need Help Here
            {
                GSparent.Contribution +=                
            }


            else
                from.SendMessage("You can't contribute that!");
            }

        }
    }
 

Attachments

  • GoalGump.cs
    2.9 KB · Views: 1
  • GoalStone.cs
    1 KB · Views: 2
It'd need to be something like:

Code:
protected override void OnTarget(Mobile from, object o)
        {
            if (GSparent == null || from == null || o == null)
            {
                Console.WriteLine("GoalStone: That's odd. Better call a GM");
                return;
            }
         
            if (o is Item)
            {
                Item item = o as Item;
                if (o is Gold)
                {
                    GSparent.Contribution += item.Amount;
                    item.Delete();
                }
                else if (o is BankCheck)
                {
                    GSparent.Contribution += ((BankCheck)item).Worth;
                    item.Delete();
                }
                else
                {
                    from.SendMessage("You can't contribute that!");
                }
            }
            else
            {
                from.SendMessage("You can't contribute that!");
            }

        }
 
this is untested but you can try this so it doesnt take it over the Goal and take all gold too.
Code:
protected override void OnTarget(Mobile from, object o)
{
	if (GSparent == null || from == null || o == null)
	{
		Console.WriteLine("GoalStone: That's odd. Better call a GM");
		return;
	}
	double ContributionRemaining = GSparent.Goal - GSparent.Contribution;
	double takeGold;
	if (o is Gold)
	{
		takeGold = Math.Min(ContributionRemaining, (o as Gold).Amount);
		GSparent.Contribution += takeGold;
		(o as Gold).Consume((int)takeGold);
	}
	else if (o is BankCheck)
	{
		BankCheck bc = o as BankCheck;
		takeGold = Math.Min(ContributionRemaining, bc.Worth);
		GSparent.Contribution += takeGold;
		bc.Worth -= (int)takeGold;
		if (bc.Worth <= 0)
			bc.Delete();
	}
	else
	{
		from.SendMessage("You can't contribute that!");
	}
}
 
These are great - only thing is by changing the method it causes a problem with getting the target from the button:

Code:
public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile m_from = state.Mobile;
          

            if (m_from != null && GSparent != null)
            {
                if (info.ButtonID == 1)
                {
                    m_from.SendMessage("Target the gold or check you wish to contribute");
                    m_from.Target = new GoalStoneTarget(GSparent);
                }
                if (info.ButtonID == 2)
                {
                    m_from.SendMessage("This goal has already been reached.");

                }
            }
        }

Since "GoalStoneTarget" isn't a thing anymore. Not sure how to reconcile that.
[doublepost=1488073970][/doublepost]Oh I'm dumb....I just realized my mistake. I still need the public class GoalStoneTarget : Target.....you just omitted that because it was obvious lol sorry

Thanks guys - this is great. I was able to complete the system and I will be contributing it to the community. You've both been credited in the scripts for your help. Cheers
 
Last edited:
Back