Hello I wanted to make a script where if your hair grows after so many hours like back on a old sphere shard like if you had bald hair it grow into short hair then longer then really long & same with beard, I found a Hair Brush script off runuo by Liacs I tried to add a timer & change some things around to test & if i got it growing hair I was gonna customize it the way I wanted the hair to grow, I probably did it all wrong & there's probably a easier way of doing it I just dont know how to,
I got it to compile but once I log in the shard crashes if anyone knows a easier way to do this can you point me in right direction or tell me if this script will even work the way I have it set up & what I did wrong for it to crash shard on player login?
here is the crash log
Code:
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
  at Server.Misc.HairGrowthTimer.HairGrowth(Mobile m) in c:\Users\Desktop\backups\ServUO-TEST\Scripts\Custom Systems\HairGrowth.cs:line 49
  at Server.Misc.HairGrowthTimer.HairGrowth() in c:\Users\Desktop\backups\ServUO-TEST\Scripts\Custom Systems\HairGrowth.cs:line 35
  at Server.Misc.HairGrowthTimer.OnTick() in c:\Users\Desktop\backups\ServUO-TEST\Scripts\Custom Systems\HairGrowth.cs:line 28
  at Server.Timer.Slice() in c:\Users\Desktop\test\ServUO-master\Server\Timer.cs:line 386
  at Server.Core.Main(String[] args) in c:\Users\Desktop\test\ServUO-master\Server\Main.cs:line 621
& here is the code I was tinkering with
Code:
using System;
using Server;
using System.Collections;
using Server.Targeting;
using Server.Mobiles;
using Server.Items;
using Server.Network;


namespace Server.Misc
{

    public class HairGrowthTimer : Timer
    {
        public static void Initialize()
        {
            new HairGrowthTimer().Start();
        }

        public HairGrowthTimer()
            : base(TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(60))
        {
            Priority = TimerPriority.OneSecond;
        }

        protected override void OnTick()
        {
            HairGrowth();
        }

        public static void HairGrowth()
        {
            foreach (NetState state in NetState.Instances)
            {
                HairGrowth(state.Mobile);
            }
        }

        public static void HairGrowth(Mobile m)
        {
            if (m != null)

                if (m.HairItemID == 0x2044) // Mohawk
                {
                    // m.SendMessage("You take your hair together.");
                    m.HairItemID = 0x204A; //Krisna
                    return;
                }
                if (m.HairItemID == 0x204A) // Krisna
                {
                    // m.SendMessage("You open your hair.");
                    m.HairItemID = 0x2044; // Mohawk
                    return;
                }

                //short
                if (m.HairItemID == 0x2045) // Pageboy
                {
                    if (!m.Female)
                    {
                        // m.SendMessage("You curl your hair.");
                        m.HairItemID = 0x2047; // Afro
                        return;
                    }
                    else
                    {
                        // m.SendMessage("You brush your hair.");
                        m.HairItemID = 0x203B; // Short
                        return;
                    }
                }

                if (m.HairItemID == 0x203B && m.Female) // Short
                {
                    // m.SendMessage("You curl your hair.");
                    m.HairItemID = 0x2047; // Afro
                    return;
                }
                if (m.HairItemID == 0x2047) // Afro
                {
                    // m.SendMessage("You straighten your hair.");
                    m.HairItemID = 0x2FBF; //MidLong
                    return;
                }
                if (m.HairItemID == 0x2FBF) // MidLong
                {
                    // m.SendMessage("You put a feather in your hair.");
                    m.HairItemID = 0x2FC0; // Feather
                    return;
                }
                if (m.HairItemID == 0x2FC0) // Feather
                {
                    // m.SendMessage("You brush your hair and take the feather out.");
                    m.HairItemID = 0x2FC2; // Mullet
                    return;
                }
                if (m.HairItemID == 0x2FC2) // Mullet
                {
                    // m.SendMessage("You make a knot.");
                    m.HairItemID = 0x2FCE; // ElfKnot
                    return;
                }
                if (m.HairItemID == 0x2FCE) // ElfKnot
                {
                    // m.SendMessage("You make a bun.");
                    m.HairItemID = 0x2FD0; // BigBun
                    return;
                }
                if (m.HairItemID == 0x2FD0) // BigBun
                {
                    // m.SendMessage("You brush your hair.");
                    m.HairItemID = 0x2045; // Pageboy
                    return;
                }

                //long
                if (m.HairItemID == 0x2046) // Buns
                {
                    // m.SendMessage("You open your hair.");
                    m.HairItemID = 0x203C; // Long
                    return;
                }
                if (m.HairItemID == 0x203C) // Long
                {
                    // m.SendMessage("You brush your hair.");
                    m.HairItemID = 0x2FCD; // LongElf
                    return;
                }
                if (m.HairItemID == 0x2FCD) // LongElf
                {
                    // m.SendMessage("You take your hair together in a ponytail.");
                    m.HairItemID = 0x203D; // Ponytail
                    return;
                }
                if (m.HairItemID == 0x203D) // Ponytail
                {
                    // m.SendMessage("You braid your hair.");
                    m.HairItemID = 0x2FCF; // BraidElf
                    return;
                }
                if (m.HairItemID == 0x2FCF) // BraidElf
                {
                    if (!m.Female)
                    {
                        // m.SendMessage("You make two pigtails.");
                        m.HairItemID = 0x2049; // Two Pigtails
                        return;
                    }
                    else
                    {
                        // m.SendMessage("You put a flower in your hair.");
                        m.HairItemID = 0x2FCC; // Flower
                        return;
                    }
                }
                if (m.HairItemID == 0x2FCC) // Flower
                {
                    // m.SendMessage("You make two pigtails.");
                    m.HairItemID = 0x2049; // Two Pigtails
                    return;
                }
                if (m.HairItemID == 0x2049) // Two Pigtails
                {
                    if (!m.Female)
                    {
                        // m.SendMessage("You open your hair.");
                        m.HairItemID = 0x203C; // Long
                        return;
                    }
                    else
                    {
                        // m.SendMessage("You roll your pigtails up in buns.");
                        m.HairItemID = 0x2046; // Buns
                        return;
                    }
                }



                //short / receeding

                if (m.HairItemID == 0x2048) // receeding
                {
                    // m.SendMessage("You brush your hair.");
                    m.HairItemID = 0x2FC1; // ShortElven
                    return;
                }

                if (m.HairItemID == 0x2FC1) // ShortElven
                {
                    // m.SendMessage("You brush your hair.");
                    m.HairItemID = 0x2FD1; // Spiked
                    return;
                }
                if (m.HairItemID == 0x2FD1) // Spiked
                {
                    if (!m.Female)
                    {
                        // m.SendMessage("You brush your hair.");
                        m.HairItemID = 0x203B; // Short
                        return;
                    }
                    else
                    {
                        // m.SendMessage("You brush your hair.");
                        m.HairItemID = 0x2048; // receeding
                        return;
                    }
                }
                if (!m.Female && m.HairItemID == 0x203B) // Short
                {
                    // m.SendMessage("You brush your hair.");
                    m.HairItemID = 0x2048; // receeding
                    return;
                }

                else
                {
                    m.SendMessage("Your hair can't grow.");
                    return;
                }
            }
        }
    }

I tried it with & without the if (m != null) i probably did that wrong & put it in wrong spot too , Thank's
 
new HairGrowthTimer().Start();
should be along the lines of:


HairGrowthTimer timer = new HairGrowthTimer();
timer.Start();


You may also want to do this in Configure() as opposed to Initialize(). I sometimes have trouble with event handlers when trying to declare them in the initialization.

++ Not that I'm saying you shouldn't take the time to look at Felladrin's work.
 
Last edited:
Thank you both when I have time later I will do as you both suggested and play around with the script some more
 
Found this on RunUO: http://www.runuo.com/community/threads/runuo-2-0-age-system.100024/
Don't know if you code by reference...but take a look at that script, rip it apart, and take what you need.

If you still need help, post again.
I'm not able to take a look at that script at the moment, but I will when I get home.

I realized after looking at it again that the hair growth was a planned update that seems to have never happened.
@thor86 - I know the Sphere Server script you mean though. I remember it being on a PVP shard I played called Ulmaria back in 2001 or 2002. I feel like I've seen this script on RunUO but can't find it. Will keep looking and offer any help that I can.
 
Thanks while testing I changed the script around & to grow after 10secs & logged in and changed my hair to 0x203B Short & it does the hair grow cycle I had tossed together for testing then I logged out & tried to make a new char & I get this crash
Code:
Server Crash Report
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
  at Server.Misc.HairGrowthTimer.HairGrowth(Mobile m) in c:\Users\Desktop\backups\ServUO-TEST\Scripts\Custom Systems\HairGrowth - Copy.cs:line 50
  at Server.Misc.HairGrowthTimer.HairGrowth() in c:\Users\Desktop\backups\ServUO-TEST\Scripts\Custom Systems\HairGrowth - Copy.cs:line 37
  at Server.Misc.HairGrowthTimer.OnTick() in c:\Users\Desktop\backups\ServUO-TEST\Scripts\Custom Systems\HairGrowth - Copy.cs:line 30
  at Server.Timer.Slice() in c:\Users\Desktop\test\ServUO-master\Server\Timer.cs:line 386
  at Server.Core.Main(String[] args) in c:\Users\Desktop\test\ServUO-master\Server\Main.cs:line 621

Here is the newest code im using

Code:
using System;
using Server;
using System.Collections;
using Server.Targeting;
using Server.Mobiles;
using Server.Items;
using Server.Network;


namespace Server.Misc
{

    public class HairGrowthTimer : Timer
    {
        public static void Initialize() //Configure()
        {
            //  new HairGrowthTimer().Start();
            HairGrowthTimer timer = new HairGrowthTimer();
            timer.Start();
        }

        public HairGrowthTimer()
            : base(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10))
        {
            Priority = TimerPriority.OneSecond;
        }

        protected override void OnTick()
        {
            HairGrowth();
        }

        public static void HairGrowth()
        {
            foreach (NetState state in NetState.Instances)
            {
                HairGrowth(state.Mobile);
            }
        }

        public static void HairGrowth(Mobile m)
        {
            if (m is PlayerMobile)

                if (m.HairItemID == 0x203B) // Short
                    {
                        m.HairItemID = 0x2FD1; // Spiked
                        return;
                    }
                    if (m.HairItemID == 0x2FC1) // ShortElven
                    {
                        m.HairItemID = 0x2FD1; // Spiked
                        return;
                    }
                    if (m.HairItemID == 0x2FD1) // Spiked
                    {
                        m.HairItemID = 0x2FC2; // Mullet
                        return;
                    }
                    if (m.HairItemID == 0x2FC2) // Mullet
                    {
                        m.HairItemID = 0x2FBF; // MidLong
                        return;
                    }
                    if (m.HairItemID == 0x2FBF)// MidLong
                    {
                        m.HairItemID = 0x203C; // Long
                        return;
                    }
                    if (m.HairItemID == 0x2048) // receeding
                    {
                        m.SendMessage("You notice your hair falling out.");  // just a test message so far
                        return;
                    }
                    {
                        m.SendMessage("Your hair can't grow."); // just a test message so far
                        return;
                    }
            }
        }
    }
if anyone can give some pointers to help out thanks

I tried Configure() instead of Initialize() & the hair growth works the same but get the same crash on making new char
 
Last edited:
I fixed the crash I guess all it needed was a != null check should of tried it first seeing it was a .NullReferenceException error
I am going to add more hair to it & beards & test some more then I will post it up on releases if anyone wants it
 
Back