Macil

Initiate
Trying to make potions not consume when used only if the player is a staff member. I know it will need some code along the lines of "
Code:
if ( from.AccessLevel >= AccessLevel.GameMaster )
. But I'm not entirely sure where to add it at in the BasePotion script (presumably it WOULD go in BasePotion, right?
Code:
using System;
using System.Collections.Generic;
using Server.Engines.Craft;

namespace Server.Items
{
    public enum PotionEffect
    {
        Nightsight,
        CureLesser,
        Cure,
        CureGreater,
        Agility,
        AgilityGreater,
        Strength,
        StrengthGreater,
        PoisonLesser,
        Poison,
        PoisonGreater,
        PoisonDeadly,
        Refresh,
        RefreshTotal,
        HealLesser,
        Heal,
        HealGreater,
        ExplosionLesser,
        Explosion,
        ExplosionGreater,
        Conflagration,
        ConflagrationGreater,
        MaskOfDeath,        // Mask of Death is not available in OSI but does exist in cliloc files
        MaskOfDeathGreater,    // included in enumeration for compatability if later enabled by OSI
        ConfusionBlast,
        ConfusionBlastGreater,
        Invisibility,
        Parasitic,
        Darkglow,
        ExplodingTarPotion,
        #region TOL Publish 93
        Barrab,
        Jukari,
        Kurak,
        Barako,
        Urali,
        Sakkhra,
        #endregion
    }

    public abstract class BasePotion : Item, ICraftable, ICommodity
    {
        private PotionEffect m_PotionEffect;

        public PotionEffect PotionEffect
        {
            get
            {
                return this.m_PotionEffect;
            }
            set
            {
                this.m_PotionEffect = value;
                this.InvalidateProperties();
            }
        }

        TextDefinition ICommodity.Description
        {
            get
            {
                return this.LabelNumber;
            }
        }
        bool ICommodity.IsDeedable
        {
            get
            {
                return (Core.ML);
            }
        }

        public override int LabelNumber
        {
            get
            {
                return 1041314 + (int)this.m_PotionEffect;
            }
        }

        public BasePotion(int itemID, PotionEffect effect)
            : base(itemID)
        {
            this.m_PotionEffect = effect;

            this.Stackable = Core.ML;
            this.Weight = 1.0;
        }

        public BasePotion(Serial serial)
            : base(serial)
        {
        }

        public virtual bool RequireFreeHand
        {
            get
            {
                return true;
            }
        }

        public static bool HasFreeHand(Mobile m)
        {
            Item handOne = m.FindItemOnLayer(Layer.OneHanded);
            Item handTwo = m.FindItemOnLayer(Layer.TwoHanded);

            if (handTwo is BaseWeapon)
                handOne = handTwo;
            if (handTwo is BaseWeapon)
            {
                BaseWeapon wep = (BaseWeapon)handTwo;
                
                if (wep.Attributes.BalancedWeapon > 0)
                    return true;
            }

            return (handOne == null || handTwo == null);
        }

        public override void OnDoubleClick(Mobile from)
        {
            if (!this.Movable)
                return;

            if (!from.BeginAction(this.GetType()))
            {
                from.SendLocalizedMessage(500119); // You must wait to perform another action.
                return;
            }

            Timer.DelayCall(TimeSpan.FromMilliseconds(500), () => from.EndAction(this.GetType()));

            if (from.InRange(this.GetWorldLocation(), 1))
            {
                if (!this.RequireFreeHand || HasFreeHand(from))
                {
                    if (this is BaseExplosionPotion && this.Amount > 1)
                    {
                        BasePotion pot = (BasePotion)Activator.CreateInstance(this.GetType());

                        if (pot != null)
                        {
                            this.Amount--;

                            if (from.Backpack != null && !from.Backpack.Deleted)
                            {
                                from.Backpack.DropItem(pot);
                            }
                            else
                            {
                                pot.MoveToWorld(from.Location, from.Map);
                            }
                            pot.Drink(from);
                        }
                    }
                    else
                    {
                        this.Drink(from);
                    }
                }
                else
                {
                    from.SendLocalizedMessage(502172); // You must have a free hand to drink a potion.
                }
            }
            else
            {
                from.SendLocalizedMessage(502138); // That is too far away for you to use
            }
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)1); // version

            writer.Write((int)this.m_PotionEffect);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch ( version )
            {
                case 1:
                case 0:
                    {
                        this.m_PotionEffect = (PotionEffect)reader.ReadInt();
                        break;
                    }
            }

            if (version == 0)
                this.Stackable = Core.ML;
        }

        public abstract void Drink(Mobile from);

        public static void PlayDrinkEffect(Mobile m)
        {
            m.RevealingAction();
            m.PlaySound(0x2D6);
            m.AddToBackpack(new Bottle());

            if (m.Body.IsHuman && !m.Mounted)
            {
                if (Core.SA)
                {
                    m.Animate(AnimationType.Eat, 0);
                }
                else
                {
                    m.Animate(34, 5, 1, true, false, 0);
                }
            }
        }

        public static int EnhancePotions(Mobile m)
        {
            int EP = AosAttributes.GetValue(m, AosAttribute.EnhancePotions);
            int skillBonus = m.Skills.Alchemy.Fixed / 330 * 10;

            if (Core.ML && EP > 50 && m.IsPlayer())
                EP = 50;

            return (EP + skillBonus);
        }

        public static TimeSpan Scale(Mobile m, TimeSpan v)
        {
            if (!Core.AOS)
                return v;

            double scalar = 1.0 + (0.01 * EnhancePotions(m));

            return TimeSpan.FromSeconds(v.TotalSeconds * scalar);
        }

        public static double Scale(Mobile m, double v)
        {
            if (!Core.AOS)
                return v;

            double scalar = 1.0 + (0.01 * EnhancePotions(m));

            return v * scalar;
        }

        public static int Scale(Mobile m, int v)
        {
            if (!Core.AOS)
                return v;

            return AOS.Scale(v, 100 + EnhancePotions(m));
        }

        public override bool WillStack(Mobile from, Item dropped)
        {
            return dropped is BasePotion && ((BasePotion)dropped).m_PotionEffect == this.m_PotionEffect && base.WillStack(from, dropped);
        }

        #region ICraftable Members

        public int OnCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, ITool tool, CraftItem craftItem, int resHue)
        {
            if (craftSystem is DefAlchemy)
            {
                Container pack = from.Backpack;

                if (pack != null)
                {
                    if ((int)this.PotionEffect >= (int)PotionEffect.Invisibility)
                        return 1;

                    List<PotionKeg> kegs = pack.FindItemsByType<PotionKeg>();

                    for (int i = 0; i < kegs.Count; ++i)
                    {
                        PotionKeg keg = kegs[i];

                        if (keg == null)
                            continue;

                        if (keg.Held <= 0 || keg.Held >= 100)
                            continue;

                        if (keg.Type != this.PotionEffect)
                            continue;

                        ++keg.Held;

                        this.Consume();
                        from.AddToBackpack(new Bottle());

                        return -1; // signal placed in keg
                    }
                }
            }

            return 1;
        }
        #endregion
    }
}
 
Rather than changing the code to do what your wanting I personally would just use a staff command to make more of the item. Such as
[Set Amount 60000
then target the potion.

But if you want to change the code:
Consume(): is the method call that uses the potions.

I'd put
if ( from.AccessLevel < AccessLevel.GameMaster )
just before it to keep them from being consumed by staff.

for potions it can be found in the following files: (may have missed one but I think that's all of them)

BaseAgilityPotion.cs
BaseConflagurationPotion.cs
BaseCurePotion.cs
BaseExplodingTarPotion.cs
BaseHealPotion.cs
BasePoison.cs
BaseRefreshingPotion.cs
BaseStrengthPotion.cs
EodonPotions.cs
InvisibilityPotion.cs
Nightsight.cs
PetBondingPotion.cs
PotionOfGloriousFortune.cs
 
Ok so.. The part where it asks if its a baseexplosionpotion and then does the...
this.Amount--;

Make it do an if statement to check the accesslevel and if its a player then do the this.Amount-- otherwise nothing.

What Visam said above for the rest.
 
Rather than changing the code to do what your wanting I personally would just use a staff command to make more of the item. Such as
[Set Amount 60000
then target the potion.

But if you want to change the code:
Consume(): is the method call that uses the potions.

I'd put
if ( from.AccessLevel < AccessLevel.GameMaster )
just before it to keep them from being consumed by staff.

for potions it can be found in the following files: (may have missed one but I think that's all of them)

BaseAgilityPotion.cs
BaseConflagurationPotion.cs
BaseCurePotion.cs
BaseExplodingTarPotion.cs
BaseHealPotion.cs
BasePoison.cs
BaseRefreshingPotion.cs
BaseStrengthPotion.cs
EodonPotions.cs
InvisibilityPotion.cs
Nightsight.cs
PetBondingPotion.cs
PotionOfGloriousFortune.cs


Well, that's what I've been doing for years and years except when I have to quickly toggle between player/staff, while I'm a player I'm immediately fatigued and that can sometimes thwart whatever I'm testing at the moment in case my character needs to move. I just want to hold one of each potion I could be needing for a test of sorts and just drink it in an unlimited capacity when I need it and never have it weigh me down... Now that I think of it, I suppose I could always have a weight reduction pack of sorts, too... Hrmm.... Now I'm wondering if a zero weight potion bag would be better, seeing as I still would have to toggle to staff otherwise the potion will consume if I accidentally drank it while in player mode...


OR!!! What if I had a special staff backpack that negates all item consumption for ANY items that are currently in the pack (negating having to switch to staff/player mode at all)? Is that something that is doable? Regardless of access levels. Just the item has to be in the pack for it to call on the non-consume parameter or whatever? Now this whole thing has me thinkin'.
Post automatically merged:


This script works brilliantly. I'll just carry 60,000 piles of everything I need on hand for my tests and I replaced my actual player backpack with the bag of reduction so no matter what if I'm Admin/Player - EVERYTHING in my pack has 0 weight always. Thanks for the help anyways guys. heheh
 
Last edited:

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back