View Full Version: Clone

RunUO.FR Support > Probleme de script > Clone


Title: Clone


Kaervek - December 14, 2003 07:47 PM (GMT)
Voilà, j'ai retrouvé ce script de clone en rangeant mes scripts...
Seulement je comprends pas pourquoi, quand je fais .CloneMe,
le server crash...
Quelqu'un sait-il d'où cela pourrait-il provenir?


CODE
using System;
using System.Collections;
using System.Reflection;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Regions;

namespace Server.Scripts.Commands
{
  public class CloneMe
  {
     public static void Initialize()
     {
        Server.Commands.Register( "CloneMe", AccessLevel.Administrator, new CommandEventHandler( CloneMe_OnCommand ) );
                       Server.Commands.Register( "Refresh", AccessLevel.Administrator, new CommandEventHandler( Refresh_OnCommand ) );
               }
     
     [Usage( "CloneMe" )]
     [Description( "Makes an exact duplicate of you at your present location and hides you" )]
                public static void CloneMe_OnCommand( CommandEventArgs e )
     {
                   Dog m = new Dog();  
                   e.Mobile.Hidden = true;
                   m.Dex = e.Mobile.Dex;
                   m.Int = e.Mobile.Int;
                   m.Str = e.Mobile.Str;
                   m.Fame = e.Mobile.Fame;
                   m.Karma = e.Mobile.Karma;
                   m.NameHue = e.Mobile.NameHue;
                   m.SpeechHue = e.Mobile.SpeechHue;
                   m.Criminal = e.Mobile.Criminal;
                   m.Name = e.Mobile.Name;
                   m.Title = e.Mobile.Title;
                   m.Female = e.Mobile.Female;
                   m.Body = e.Mobile.Body;
                   m.Hue = e.Mobile.Hue;
                   m.Hits = e.Mobile.HitsMax;
                   m.Mana = e.Mobile.ManaMax;
                   m.Stam = e.Mobile.StamMax;
                   m.BodyMod = e.Mobile.Body;
                   m.Controled = true;  
                   m.ControlMaster = e.Mobile;
                   m.Map = e.Mobile.Map;
                   m.Location = e.Mobile.Location;
                   m.Direction = e.Mobile.Direction;
                   
                   for (int i=0; i<e.Mobile.Skills.Length; i++)
                    m.Skills[i].Base = e.Mobile.Skills[i].Base;

                 // This code block duplicates all equiped items
                 ArrayList items = new ArrayList( e.Mobile.Items );
                 for (int i=0; i<items.Count; i++)
                 {
                    Item item = (Item)items[i];
                    if((( item != null ) && ( item.Parent == e.Mobile ) && ( item != e.Mobile.Backpack )))
                    {
                       Type type = item.GetType();
                       Item newitem = Loot.Construct( type );
                       CopyProperties( newitem, item );
                       m.AddItem( newitem );
                    }
                 }
                 // This code block duplicates all pack items
                    Container pack = e.Mobile.Backpack;
                    if( pack != null )
                    {
                       ArrayList t_items = new ArrayList( pack.Items );
                       for (int i=0; i<t_items.Count; i++)
                       {
                          Item item = (Item)t_items[i];
                          if(( item != null ) && ( item.IsChildOf( pack )))
                          {
                             Type type = item.GetType();
                             Item newitem = Loot.Construct( type );
                             CopyProperties( newitem, item );
                             m.PlaceInBackpack( newitem );
                          }
                       }
                    }
                 }

private static void CopyProperties ( Item dest, Item src )
  {
     PropertyInfo[] props = src.GetType().GetProperties();

     for ( int i = 0; i < props.Length; i++ )
    {
        try
        {
           if ( props[i].CanRead && props[i].CanWrite )
           {
              props[i].SetValue( dest, props[i].GetValue( src, null ), null );
           }
        }
        catch
        {
        }
     }
  }
   
               [Usage( "Refresh" )]
     [Description( "Sets all targets stats to full." )]
 public static void Refresh_OnCommand( CommandEventArgs e )
     {
                       e.Mobile.Target = new freshTarget();
               }
       public class freshTarget : Target
       {
         public freshTarget() : base( 12, false, TargetFlags.None )
       {
       }
       protected override void OnTarget( Mobile from, object targeted )
       {
          if ( targeted is Mobile )
           {
               Mobile targ = (Mobile)targeted;
           if ( !from.CanSee( targ ) )
           {
          from.SendMessage( "The target is not in your line of sight!" );
           }
           else
           {
               targ.Hits = targ.HitsMax;
               targ.Mana = targ.ManaMax;
               targ.Stam = targ.StamMax;
          }
          }
      }
   }
  }
}

Didi - December 15, 2003 03:05 PM (GMT)
donne le rapport du crash :)

Kaervek - December 15, 2003 05:22 PM (GMT)
CODE
Server Crash Report
===================

Operating System: Microsoft Windows NT 5.1.2600.0
.NET Framework: 1.1.4322.573
Time: 14/12/2003 20:39:19
Mobiles: 12485
Items: 97616
Clients:
- Count: 1
+ xxx.xxx.xxx.xxx: (account = Kaervek) (mobile = 0x1 'Kaervek le Seigneur de Guerre')

Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
  at Server.Mobile.PlaceInBackpack(Item item)
  at Server.Scripts.Commands.CloneMe.CloneMe_OnCommand(CommandEventArgs e)
  at Server.Commands.Handle(Mobile from, String text)
  at Server.Mobile.DoSpeech(String text, Int32[] keywords, MessageType type, Int32 hue)
  at Server.Network.PacketHandlers.UnicodeSpeech(NetState state, PacketReader pvSrc)
  at Server.Network.MessagePump.HandleReceive(NetState ns)
  at Server.Network.MessagePump.Slice()
  at Server.Core.Main(String[] args)

Voilou ;)
Ps: xxx.xxx.xxx.xxx c'est mon ip :)

Didi - December 17, 2003 05:38 PM (GMT)
Apres testes avec kaervek pour ceux que sa inetresse, lew probleme vient du faite quil portait un item non dupable

la correction :P

CODE
using System;
using System.Collections;
using System.Reflection;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Regions;

namespace Server.Scripts.Commands
{
 public class CloneMe
 {
    public static void Initialize()
    {
       Server.Commands.Register( "CloneMe", AccessLevel.Administrator, new CommandEventHandler( CloneMe_OnCommand ) );
                      Server.Commands.Register( "Refresh", AccessLevel.Administrator, new CommandEventHandler( Refresh_OnCommand ) );
              }
   
    [Usage( "CloneMe" )]
    [Description( "Makes an exact duplicate of you at your present location and hides you" )]
               public static void CloneMe_OnCommand( CommandEventArgs e )
    {
                  Dog m = new Dog();  
                  e.Mobile.Hidden = true;
                  m.Dex = e.Mobile.Dex;
                  m.Int = e.Mobile.Int;
                  m.Str = e.Mobile.Str;
                  m.Fame = e.Mobile.Fame;
                  m.Karma = e.Mobile.Karma;
                  m.NameHue = e.Mobile.NameHue;
                  m.SpeechHue = e.Mobile.SpeechHue;
                  m.Criminal = e.Mobile.Criminal;
                  m.Name = e.Mobile.Name;
                  m.Title = e.Mobile.Title;
                  m.Female = e.Mobile.Female;
                  m.Body = e.Mobile.Body;
                  m.Hue = e.Mobile.Hue;
                  m.Hits = e.Mobile.HitsMax;
                  m.Mana = e.Mobile.ManaMax;
                  m.Stam = e.Mobile.StamMax;
                  m.BodyMod = e.Mobile.Body;
                  m.Controled = true;  
                  m.ControlMaster = e.Mobile;
                  m.Map = e.Mobile.Map;
                  m.Location = e.Mobile.Location;
                  m.Direction = e.Mobile.Direction;
                 
                  for (int i=0; i<e.Mobile.Skills.Length; i++)
                   m.Skills[i].Base = e.Mobile.Skills[i].Base;

                // This code block duplicates all equiped items
                ArrayList items = new ArrayList( e.Mobile.Items );
                for (int i=0; i<items.Count; i++)
                {
                   Item item = (Item)items[i];
                   if((( item != null ) && ( item.Parent == e.Mobile ) && ( item != e.Mobile.Backpack )))
                   {
                      Type type = item.GetType();
                      Item newitem = Loot.Construct( type );
                      CopyProperties( newitem, item );
                      m.AddItem( newitem );
                   }
                }
                // This code block duplicates all pack items
                   Container pack = e.Mobile.Backpack;
                   if( pack != null )
                   {
                      ArrayList t_items = new ArrayList( pack.Items );
                      for (int i=0; i<t_items.Count; i++)
                      {
  try
  {
                          Item item = (Item)t_items[i];
                          if(( item != null ) && ( item.IsChildOf( pack )))
                          {
                              Type type = item.GetType();
                              Item newitem = Loot.Construct( type );
                              CopyProperties( newitem, item );
                              m.PlaceInBackpack( newitem );
                          }
  }
  catch
  {
  }
                      }
                   }
                }

private static void CopyProperties ( Item dest, Item src )
 {
    PropertyInfo[] props = src.GetType().GetProperties();

    for ( int i = 0; i < props.Length; i++ )
   {
       try
       {
          if ( props[i].CanRead && props[i].CanWrite )
          {
             props[i].SetValue( dest, props[i].GetValue( src, null ), null );
          }
       }
       catch
       {
       }
    }
 }
 
              [Usage( "Refresh" )]
    [Description( "Sets all targets stats to full." )]
public static void Refresh_OnCommand( CommandEventArgs e )
    {
                      e.Mobile.Target = new freshTarget();
              }
      public class freshTarget : Target
      {
        public freshTarget() : base( 12, false, TargetFlags.None )
      {
      }
      protected override void OnTarget( Mobile from, object targeted )
      {
         if ( targeted is Mobile )
          {
              Mobile targ = (Mobile)targeted;
          if ( !from.CanSee( targ ) )
          {
         from.SendMessage( "The target is not in your line of sight!" );
          }
          else
          {
              targ.Hits = targ.HitsMax;
              targ.Mana = targ.ManaMax;
              targ.Stam = targ.StamMax;
         }
         }
     }
  }
 }
}

Youl - March 14, 2004 12:50 PM (GMT)
C'est possible de créer la commande inverse ? De prendre l'apparence d'un Pj ou d'un NPC ?




* Hosted for free by InvisionFree