zerodowned

Moderator
I'm using Lokai's race/class system but modified to use PlayerMobile instead of NewMobile

If I implement the new skills into player mobile it crashes when I save the shard.
Any thoughts on why this would be happening?

This part in the serializer is causing a crash
Code:
for (int x=0; x<5; x++)
            {
                writer.Write( (int) m_Skills[x].Name );
                writer.Write( (int) m_Skills[x].Value );
            }

which is serializing this
Code:
private NewSkillNameValue[] m_Skills;
        /// <summary>
        /// These are the NewSkillNameValue's for the NewMobile class.
        /// They include ClassSkill_1 through ClassSkill_5.
        /// </summary>
        public NewSkillNameValue[] NewSkills { get { return m_Skills; } set { m_Skills = value; } }
        public NewSkillNameValue ClassSkill_1 { get { return m_Skills[0]; } set { m_Skills[0] = value; } }
        public NewSkillNameValue ClassSkill_2 { get { return m_Skills[1]; } set { m_Skills[1] = value; } }
        public NewSkillNameValue ClassSkill_3 { get { return m_Skills[2]; } set { m_Skills[2] = value; } }
        public NewSkillNameValue ClassSkill_4 { get { return m_Skills[3]; } set { m_Skills[3] = value; } }
        public NewSkillNameValue ClassSkill_5 { get { return m_Skills[4]; } set { m_Skills[4] = value; } }

crash msg
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Mobiles.PlayerMobile.Serialize(GenericWriter writer) in ...\ServUO-master\Scripts\Mobiles\PlayerMobile.cs:line 4355
 

Attachments

  • Custom_Race-Class_System.zip
    46.1 KB · Views: 2
I realize this system is out of date and @Lokai has recommended not using it, but I'm trying to get it working for someone else.
Thanks
 
I am kind of reluctant to help with this since I know for whom this is but..

You probably do not initialize them with default values for the case of the pre existing playermobiles. So you could try to solve this with the deserialize method or with a null check in the serialize to set it to default values.

After you initialized the m_Skills array you could also m_Skills.Length instead of x<5 in case they want more or less skills (just be sure to add a null check there in case the size changes)
 
:-/
yeah sorry man, i don't fully know what happened but thank you for helping

that's close to what i've tried but not quite. will give it another try
 
this worked to implement with existing mobiles
good idea on using skills.length. I love multiple profession games

thank you again for your help

Code:
if ( m_Skills == null )
                m_Skills = new NewSkillNameValue[5];
              
            for (int x=0; x<5; x++)
            {
                writer.Write( (int) m_Skills[x].Name );
                writer.Write( (int) m_Skills[x].Value );
            }
 
For serializing and deserializing, i suggest you to write the length of the skill array, and reading it, so you can add/remove skills at any time without having to create a new case.

Code:
write.Write(newSkills.Length());
for (int i = 0; i < newSkills.Length(); ++i)
{
	write.Write(newSkills);
}

Same thing for the deserialize.
 
this worked to implement with existing mobiles
good idea on using skills.length. I love multiple profession games

thank you again for your help

Code:
if ( m_Skills == null )
                m_Skills = new NewSkillNameValue[5];
             
            for (int x=0; x<5; x++)
            {
                writer.Write( (int) m_Skills[x].Name );
                writer.Write( (int) m_Skills[x].Value );
            }

I think part of the problem is that m_Skills has the same name as the private variable of the same name in the Mobile class, which even though it is private might implement some kind of hiding or something. Not sure if that's possible.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back