We have Xanthos shrink system on the server & its working great. We also have Repairing NPC's that repair weapons and/or armor for a price. The PetLeash is currently set for 50 charges in ShrinkConfig which is fine. What we are wanting to do is have a recharge system for them (make the players pay for extended use). I'm trying to combine both systems & so far its working with 1 minor detail. The Repairer I made recognizes the PetLeash, but says it doesnt need recharged & I think I know why. The Leash reads from the ShrinkConfig which is set for 50 uses, but has no "max" charges, so the repairer has nothing to compare to. I'm including the section of my repairer that has the pet leash recharge coding along with the scripts for the repairer, petleash & shrinkconfig. I'm hoping I wont have to alter coding in the petleash or config very much (if at all) since it ties in with other things we have.
Code:
            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted is IShrinkTool && from.Backpack != null)
                {
                    IShrinkTool st = targeted as IShrinkTool;
                    Container pack = from.Backpack;
                    int toConsume = 0;

                    if (st.ShrinkCharges < st.ShrinkCharges)
                    {
                        toConsume = (st.ShrinkCharges - st.ShrinkCharges) * 20; // 2 gp per hitpoint - change 2 to whatever you want as a multiplier
                    }
                    else
                    {
                        m_Trainer.SayTo(from, "That does not need to be recharged.");
                    }

                    if (toConsume == 0)
                        return;

                    if (pack.ConsumeTotal(typeof(Gold), toConsume))
                    {
                        m_Trainer.SayTo(from, "Here is your pet leash.");
                        from.SendMessage(String.Format("You pay {0} gold.", toConsume));
                        Effects.PlaySound(from.Location, from.Map, 0x55);
                        st.ShrinkCharges -= 1;
                        st.ShrinkCharges = st.ShrinkCharges;
                    }
                    else
                    {
                        m_Trainer.SayTo(from, "It would cost you {0} gold to have that repaired.", toConsume);
                        from.SendMessage("You do not have enough gold.");
                    }
                }
                else
                    m_Trainer.SayTo(from, "I cannot recharge that.");
            }
 

Attachments

  • PetLeash.cs
    1.9 KB · Views: 16
  • ShrinkConfig.cs
    3.5 KB · Views: 11
  • RepairingAnimalTrainer.cs
    5 KB · Views: 12
Well it tells you that it does not need recharging because
Code:
if (st.ShrinkCharges < st.ShrinkCharges)
{
	toConsume = (st.ShrinkCharges - st.ShrinkCharges) * 20; // 2 gp per hitpoint - change 2 to whatever you want as a multiplier
}
litterally translates to
Code:
if (10 < 10)
{
	toConsume = (10 - 10) * 20;
}

for your maxcharge, you could use the value from the config. And therefor it would translate to
Code:
if (st.ShrinkCharges < ShrinkConfig.ShrinkCharges
{
	toConsume = (ShrinkConfig.ShrinkCharges - st.ShrinkCharges) * 20; // 2 gp per hitpoint - change 2 to whatever you want as a multiplier
}
 
Ok, that compiled, but still not working quite right. Took 900 gold but only reduced the remaining charges by 1. No recharge to 49 like it should have,
[doublepost=1481040116][/doublepost]Minor, insignificant update... it now works like I was hoping. Just had to add ShrinkConfig in a couple other places & it took a 4 charge PetLeash & recharged it to 49 charges for only 920 gold (may have to up the cost amount). Thx for the help Pyro!
 
Back