Full Version : how they make this?
xmlspawner >>Scripting Support >>how they make this?
<< Prev | Next >>
ArteGordon- 02-09-2006
if you want it to show at every access level, then just take out the access level test.

CODE
if (m_Title1 != null) { list.Add(1060660, "Title\t{0}",m_Title1); // ~1_val~:~2_val~ }

ambak- 02-09-2006
it still not showing on staff chars.
ArteGordon- 02-09-2006
that may just be because the property list is not getting updated.
Add this

QUOTE
private string m_Title1; [CommandProperty( AccessLevel.GameMaster )] public string Title1 { get{ return m_Title1; }
set{ m_Title1= value; InvalidateProperties(); }
}

ambak- 02-09-2006
ok it works but i think i found the problem.everytime the server restarts the titles got dissapear.
Zyle- 02-10-2006
Like Arte said:

QUOTE
Note that if you added those custom properties, then you would also need to Serialize and Deserialize them.

If you don't do so, then the property isn't saved through a reboot. If you don't know how to do that, don't try to experiment unless it's on a test shard as changing the serialization for PlayerMobile can cause you to wipe your entire playerbase if you mess it up. I think you do this by adding a new case to the serialization and deserialization which contains the information you want saved. Just don't mess around with it on a live shard!
ArteGordon- 02-10-2006
Another way to get around having to modify the Serialization/Deserialization of your playermobile class, which, as Zyle mentioned, carries dangers of messing up your saves and possibly wiping your players if you dont know what you are doing, is to store the information on an attachment such as XmlData which will take care of all of that for you.
The disadvantage is that the code is a little more involved, but the advantage is that you dont have to mess around with your playermobile serialization so it is completely safe.
Instead of using this

CODE
private string m_Title1; [CommandProperty( AccessLevel.GameMaster )] public string Title1 { get{ return m_Title1; }
set{ m_Title1= value; }
}

use this

CODE
private string m_Title1; [CommandProperty(AccessLevel.GameMaster)] public string Title1 { get {
if (m_Title1 == null)
{
// find the value on the XmlData attachment
XmlData a = (XmlData)XmlAttach.FindAttachment(this, typeof(XmlData), "Title1");
if (a != null)
{
m_Title1 = a.Data;
}
}
return m_Title1;
}
set {
m_Title1 = value;
// find the value on the XmlData attachment
XmlData a = (XmlData)XmlAttach.FindAttachment(this, typeof(XmlData), "Title1");
if (a == null)
{
// if none exist, then add one
a = new XmlData("Title1", m_Title1);
XmlAttach.AttachTo(this, a);
}
// store the new title in the Data property
if (a != null)
{
a.Data = m_Title1;
}
InvalidateProperties(); }
}

if you dont already have it, you will also have to add this to the beginning of your playermobile.cs

CODE
using Server.Engines.XmlSpawner2;

Zyle- 02-10-2006
That's so awesome, I really can't get over how much can be done using this system. Just brilliant!
ambak- 02-10-2006
arte can you help me for Serialize and Deserialize
ArteGordon- 02-10-2006
if you use the code that I posted, then you dont have to worry about serializing or deserializing anything.
ambak- 02-10-2006
yes i used the code that you gave me but everytime the server restarts the titles disapperaring.
oh wait i didnt see your last code.ill try it
ambak- 02-10-2006
oh yeah this is vey good !i love xmlspawner but can i add more title properties to this code?

CODE
private string m_Title1; [CommandProperty(AccessLevel.GameMaster)] public string Title1 { get {
if (m_Title1 == null)
{
// find the value on the XmlData attachment
XmlData a = (XmlData)XmlAttach.FindAttachment(this, typeof(XmlData), "Title1");
if (a != null)
{
m_Title1 = a.Data;
}
}
return m_Title1;
}
set {
m_Title1 = value;
// find the value on the XmlData attachment
XmlData a = (XmlData)XmlAttach.FindAttachment(this, typeof(XmlData), "Title1");
if (a == null)
{
// if none exist, then add one
a = new XmlData("Title1", m_Title1);
XmlAttach.AttachTo(this, a);
}
// store the new title in the Data property
if (a != null)
{
a.Data = m_Title1;
}
InvalidateProperties(); }
}

ArteGordon- 02-10-2006
what else do you want to add?
ambak- 02-10-2006
i want 3 custom title like title1 title2 title3
for example if i set three of them to a pleyer it will show like this
ArteGordon (player name)
God of XMLSpawner (title1)
Script Master (title2)
Friendly (title3)
ArteGordon- 02-10-2006
you can add more custom properties by just copying the previous code and changing the names

CODE
private string m_Title2; [CommandProperty(AccessLevel.GameMaster)] public string Title2 { get
{
if (m_Title2 == null)
{
// find the value on the XmlData attachment
XmlData a = (XmlData)XmlAttach.FindAttachment(this, typeof(XmlData), "Title2");
if (a != null)
{
m_Title2 = a.Data;
}
}
return m_Title2;
}
set
{
m_Title2 = value;
// find the value on the XmlData attachment
XmlData a = (XmlData)XmlAttach.FindAttachment(this, typeof(XmlData), "Title2");
if (a == null)
{
// if none exist, then add one
a = new XmlData("Title2", m_Title2);
XmlAttach.AttachTo(this, a);
}
// store the new title in the Data property
if (a != null)
{
a.Data = m_Title2;
}
InvalidateProperties();
}
}

and then in your GetProperties, add the multiple title strings on separate lines by putting a carriage return between them like this

CODE
list.Add(1060660, "Title\t{0}\n{1}", m_Title1, m_Title2); // ~1_val~:~2_val~

ambak- 02-10-2006
ok thanks this is very good.
list.Add(1060660, "Title\t{0}\n{1}", m_Title1, m_Title2); // ~1_val~:~2_val~
will this list the titles like this "Title1 Title2"
OR
Title1
Title2