|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Newbie
Join Date: Dec 2004
Age: 26
Posts: 18
|
Code:
private ColorTeam m_ColorTeam; ...//later in the seralize function writer.Write( m_ColorTeam ); ...//later in the deserialize function m_ColorTeam = (ColorTeam)reader.ReadGuild(); System.Exception: Load failed (items=False, mobiles=True, guilds=False, regions=False, type=Server.Mobiles.PlayerMobile, serial=0x00000001) ---> System.InvalidCastException: Specified Cast is not valid. at Server.Mobiles.PlayerMobile.Deserialize(GenericRea der reader) I would love to just make a custom ReadColorTeam function but I have nothing to base it on. I don't know what happens in a 'Read_____' function. |
|
|
|
|
|
#2 (permalink) |
|
P3'c Orion Aviator
Join Date: Sep 2004
Age: 30
Posts: 1,272
|
Read is the load, and write is the save :"P
Look at this serialize example... Code:
public class CharFlagStone : Item
{
private bool SomeVariable;
//Constructor and stuff here
//do some stuff
public CharFlagStone( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( (bool)SomeVariable );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
SomeVariable = reader.ReadBool();
}
}
Pass variable through the writer/saver Pass it to the Reader/loader This way uses the serialization of its parent class. |
|
|
|
|
|
#5 (permalink) |
|
Forum Novice
Join Date: Sep 2002
Posts: 238
|
Take a look at this code from keyring I made. This has an expamle of what you are trying to do.
Code:
using System.Collections;
using Server.Network;
using Server.Targeting;
using Server.Prompts;
namespace Server.Items
{
public class KeyInfo
{
private string m_Description;
private uint m_KeyVal;
private Item m_Link;
private int m_MaxRange;
private KeyType m_Type;
public string Description{ get{ return m_Description; } }
public int MaxRange{ get{ return m_MaxRange; } }
public uint KeyValue{ get{ return m_KeyVal; } }
public Item Link{ get{ return m_Link; } }
public KeyType type{ get{ return m_Type; } }
public KeyInfo( Key key )
{
m_KeyVal = key.KeyValue;
m_Description = key.Description;
m_MaxRange = key.MaxRange;
m_Link = key.Link;
m_Type = (KeyType)key.ItemID;
}
public KeyInfo( GenericReader reader )
{
int version = reader.ReadInt();
m_KeyVal = reader.ReadUInt();
m_Description = reader.ReadString();
m_MaxRange = reader.ReadInt();
m_Link = reader.ReadItem();
m_Type = (KeyType)reader.ReadInt();
}
public void Serialize( GenericWriter writer )
{
writer.Write( (int) 0 ); // version
writer.Write( (uint) m_KeyVal );
writer.Write( (string) m_Description );
writer.Write( (int) m_MaxRange );
writer.Write( (Item) m_Link );
writer.Write( (int) m_Type );
}
}
public class KeyRing : Item
{
private ArrayList m_Keys;
public ArrayList Keys{ get{ return m_Keys; } }
[Constructable]
public KeyRing() : base( 0x1011 )
{
m_Keys = new ArrayList();
}
public KeyRing( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
writer.Write( (int) m_Keys.Count );
foreach( KeyInfo key in m_Keys )
key.Serialize( writer );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
m_Keys = new ArrayList();
int KeyCount = reader.ReadInt();
for ( int i = 0; i < KeyCount; i++ )
m_Keys.Add( new KeyInfo( reader ) );
}
public override bool OnDragDrop( Mobile from, Item item )
{
base.OnDragDrop( from, item );
if ( item is Key && ((Key)item).KeyValue != 0 )
{
if ( m_Keys.Count < 20 )
{
from.SendLocalizedMessage( 501691 ); // You put the key on the keyring.
m_Keys.Add( new KeyInfo( (Key)item ) );
item.Delete();
if( m_Keys.Count > 0 && m_Keys.Count < 3 )
ItemID = 0x1769;
else if ( m_Keys.Count > 2 && m_Keys.Count < 5 )
ItemID = 0x176A;
else if ( m_Keys.Count > 4 )
ItemID = 0x176B;
}
else
{
from.SendLocalizedMessage( 1008138 ); // This keyring is full.
}
}
else
{
from.SendLocalizedMessage( 501689 ); // Only non-blank keys can be put on a keyring.
}
return false;
}
public override void OnDoubleClick( Mobile from )
{
from.SendLocalizedMessage( 501680 ); // What do you want to unlock?
from.Target = new UnlockTarget( this );
}
private class UnlockTarget : Target
{
private KeyRing m_KeyRing;
public UnlockTarget( KeyRing keyring ) : base( 10, false, TargetFlags.None )
{
m_KeyRing = keyring;
CheckLOS = false;
}
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted == m_KeyRing )
{
from.SendLocalizedMessage( 501685 ); // You open the keyring.
m_KeyRing.ItemID = 0x1011;
foreach( KeyInfo k in m_KeyRing.Keys )
{
Key key = new Key( k.type, k.KeyValue, k.Link );
key.Description = k.Description;
from.AddToBackpack( key );
}
m_KeyRing.Keys.Clear();
}
else if ( targeted is ILockable )
{
ILockable o = (ILockable)targeted;
bool KeyMatched = false;
foreach( KeyInfo key in m_KeyRing.Keys )
{
if ( key.KeyValue == o.KeyValue )
{
KeyMatched = true;
break;
}
}
if ( KeyMatched )
{
if ( o is BaseDoor && !((BaseDoor)o).UseLocks() )
{
from.SendLocalizedMessage( 1008140 ); // You do not have a key for that.
}
else
{
o.Locked = !o.Locked;
if ( o is LockableContainer )
{
LockableContainer cont = (LockableContainer)o;
if ( cont.LockLevel == -255 )
cont.LockLevel = cont.RequiredSkill - 10;
}
if ( targeted is Item )
{
Item item = (Item)targeted;
if ( o.Locked )
item.SendLocalizedMessageTo( from, 1048000 ); // You lock it
else
item.SendLocalizedMessageTo( from, 1048001 ); // You unlock it.
}
}
}
else
{
from.SendLocalizedMessage( 1008140 ); // You do not have a key for that.
}
}
else
{
from.SendLocalizedMessage( 501666 ); // You can't unlock that!
}
}
}
}
|
|
|
|
|
|
#6 (permalink) |
|
Newbie
Join Date: Dec 2004
Age: 26
Posts: 18
|
here is the Item BlueTeamBook that uses it s a property:
Code:
public class BlueTeamBook : Item
{
private ColorTeam m_ColorTeam;
public ColorTeam ColorTeam
{
get
{
return m_ColorTeam;
}
}
[Constructable]
public BlueTeamBook() : base( 0xFBE )
{
m_ColorTeam = new ColorTeam( "Blue", "BLU" );
Hue = 94;
Name = "Blue Team Sign Up Book";
Movable = false;
}
public BlueTeamBook( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 ); // version
writer.Write( m_ColorTeam );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 1:
{
m_ColorTeam = (ColorTeam)reader.ReadGuild();
break;
}
}
}
public override void OnDoubleClick( Mobile temp )
{
PlayerMobile from = (PlayerMobile)temp;
if ( !from.InRange( GetWorldLocation(), 2 ) )
{
from.SendLocalizedMessage( 500446 ); // That is too far away.
}
else if ( from.ColorTeam == null )
{
ColorTeamsGump.EnsureClosed( from );
from.SendGump( new ColorTeamsGump( from, m_ColorTeam ) );
}
else if ( from.ColorTeam == m_ColorTeam )
{
from.SendMessage("You are already on the Red Team");
}
else
{
from.SendMessage("You are on another color team. You cannot join this one.");
}
}
}
}
|
|
|
|
|
|
#9 (permalink) |
|
Swashbuckling Ninja Pimp
Join Date: Jun 2004
Age: 31
Posts: 44
|
Code:
m_ColorTeam=m_ColorTeam.Deserialize( reader ); Code:
public ColorTeam( /*add any other paramaters here that come with the regular constructor call,*/ Generic reader )
{
}
Code:
m_ColorTeam = new ColorTeam( */any other parameters here,*/ reader ); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|