View Full Version: BOule de cristal

RunUO.FR Support > Le vivier > BOule de cristal


Title: BOule de cristal
Description: Qui donne la position d'un joueur


Kaervek - September 13, 2003 01:11 PM (GMT)
Voilà, j'ai le scripte d'une boule de crystal...
CODE
using System;
using Server;
using Server.Network;

namespace Server.Items
{
  public class MagicCrystalBall : Item
  {
     [Constructable]
     public MagicCrystalBall() : base( 0xE2E )
     {
        this.Name = "Boule de crystal";
        this.Weight = 10;
        this.Stackable = false;
        this.LootType = LootType.Blessed;
        this.Light = LightType.Circle150;
     }

     public override void OnDoubleClick( Mobile from )
     {
        this.PublicOverheadMessage( MessageType.Regular, 0x3B2, 1007000 + Utility.Random( 28 ));
     }

     public MagicCrystalBall( Serial serial ) : base( serial )
     {
     }

     public override void Serialize( GenericWriter writer )
     {
        base.Serialize( writer );
        writer.Write( (int) 0 ); // version
     }

     public override void Deserialize( GenericReader reader )
     {
        base.Deserialize( reader );
        int version = reader.ReadInt();
     }
  }
}


Mais j'aimerais améliorer cet idem de maniere a ce qu'en fait, un double clic dessus fasses'ouvrir un tableau avec la liste des personne connectees.
Ensuite, un clic sur un des noms, fera dire à la boule de crystal la localistation de la personne.

Notes: J'aimerais limiter les utilisations en mettant un timer de 5 minutes entre chaque utilisation.
Et il faudrait 100 en spiritspeak et magery pour pouvoir l'utiliser B)

Ps: Attention, contrairement à tracking, ici aucune fleche n'indiquerait la direction du joueur. Juste un message affichant les coordonnées du joueur.

Kaervek - September 17, 2003 03:23 PM (GMT)
Voici ce que j'ai pour l'instant MAIS il me faut faire un lien et je en sais pas comment.... :( (voir ligne 20 ma remarque)
Sinon la portée de l'objet serait très importante et son utilisaiton limitée à 1fois par heure.

CODE
using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Network;

namespace Server.Items
{
  public class MagicCrystalBall2 : Item
  {
     [Constructable]
     public MagicCrystalBall2() : base( 0xE2E )
     {
        this.Name = "Boule de crystal";
        this.Weight = 10;
        this.Stackable = false;
        this.LootType = LootType.Blessed;
        this.Light = LightType.Circle300;
     }
     public override void OnDoubleClick( Use.Tracking ); //Il me faudrait faire le lien avec tout ce qui suit....
   
  public class Tracking
{
 public static void Initialize()
 {
  SkillInfo.Table[(int)SkillName.Tracking].Callback = new SkillUseCallback( OnUse );
 }

 public static TimeSpan OnUse( Mobile m )
 {
  m.SendLocalizedMessage( 1011350 ); // What do you wish to track?

  m.CloseGump( typeof( TrackWhatGump ) );
  m.CloseGump( typeof( TrackWhoGump ) );
  m.SendGump( new TrackWhatGump( m ) );

  return TimeSpan.FromSeconds( 10.0 ); // 10 second delay before beign able to re-use a skill
 }
}

public class TrackWhatGump : Gump
{
 private Mobile m_From;
 private bool m_Success;

 public TrackWhatGump( Mobile from ) : base( 20, 30 )
 {
  m_From = from;
  m_Success = from.CheckSkill( SkillName.Tracking, 0.0, 21.1 );

  AddPage( 0 );

  AddBackground( 0, 0, 440, 135, 5054 );

  AddBackground( 10, 10, 420, 75, 2620 );
  AddBackground( 10, 85, 420, 25, 3000 );

  AddItem( 20, 20, 9682 );
  AddButton( 20, 110, 4005, 4007, 1, GumpButtonType.Reply, 0 );
  AddHtmlLocalized( 20, 90, 100, 20, 1018087, false, false ); // Animals

  AddItem( 120, 20, 9607 );
  AddButton( 120, 110, 4005, 4007, 2, GumpButtonType.Reply, 0 );
  AddHtmlLocalized( 120, 90, 100, 20, 1018088, false, false ); // Monsters

  AddItem( 220, 20, 8454 );
  AddButton( 220, 110, 4005, 4007, 3, GumpButtonType.Reply, 0 );
  AddHtmlLocalized( 220, 90, 100, 20, 1018089, false, false ); // Human NPCs

  AddItem( 320, 20, 8455 );
  AddButton( 320, 110, 4005, 4007, 4, GumpButtonType.Reply, 0 );
  AddHtmlLocalized( 320, 90, 100, 20, 1018090, false, false ); // Players
 }

 public override void OnResponse( NetState state, RelayInfo info )
 {
  if ( info.ButtonID >= 1 && info.ButtonID <= 4 )
   TrackWhoGump.DisplayTo( m_Success, m_From, info.ButtonID - 1 );
 }
}

public delegate bool TrackTypeDelegate( Mobile m );

public class TrackWhoGump : Gump
{
 private Mobile m_From;
 private int m_Range;

 private static TrackTypeDelegate[] m_Delegates = new TrackTypeDelegate[]
  {
   new TrackTypeDelegate( IsAnimal ),
   new TrackTypeDelegate( IsMonster ),
   new TrackTypeDelegate( IsHumanNPC ),
   new TrackTypeDelegate( IsPlayer )
  };

 private class InternalSorter : IComparer
 {
  private Mobile m_From;

  public InternalSorter( Mobile from )
  {
   m_From = from;
  }

  public int Compare( object x, object y )
  {
   if ( x == null && y == null )
    return 0;
   else if ( x == null )
    return -1;
   else if ( y == null )
    return 1;

   Mobile a = x as Mobile;
   Mobile b = y as Mobile;

   if ( a == null || b == null )
    throw new ArgumentException();

   return m_From.GetDistanceToSqrt( a ).CompareTo( m_From.GetDistanceToSqrt( b ) );
  }
 }

 public static void DisplayTo( bool success, Mobile from, int type )
 {
  if ( !success )
  {
   from.SendLocalizedMessage( 1018092 ); // You see no evidence of those in the area.
   return;
  }

  Map map = from.Map;

  if ( map == null )
   return;

  TrackTypeDelegate check = m_Delegates[type];

  from.CheckSkill( SkillName.Tracking, 0.1, 100.0 ); // Passive gain

  int range = 25 + (int)(from.Skills[SkillName.Tracking].Value / 2);

  ArrayList list = new ArrayList();
  IPooledEnumerable eable = map.GetMobilesInRange( from.Location, range );

  foreach ( Mobile m in eable )
  {
   if ( m != from && (!m.Hidden || m.AccessLevel == AccessLevel.Player || from.AccessLevel > m.AccessLevel) && check( m ) )
    list.Add( m );
  }

  eable.Free();

  if ( list.Count > 0 )
  {
   list.Sort( new InternalSorter( from ) );

   from.SendGump( new TrackWhoGump( from, list, range ) );
   from.SendLocalizedMessage( 1018093 ); // Select the one you would like to track.
  }
  else
  {
   if ( type == 0 )
    from.SendLocalizedMessage( 502991 ); // You see no evidence of animals in the area.
   else if ( type == 1 )
    from.SendLocalizedMessage( 502993 ); // You see no evidence of creatures in the area.
   else
    from.SendLocalizedMessage( 502995 ); // You see no evidence of people in the area.
  }
 }

 private static bool IsAnimal( Mobile m )
 {
  return ( !m.Player && m.Body.IsAnimal );
 }

 private static bool IsMonster( Mobile m )
 {
  return ( !m.Player && m.Body.IsMonster );
 }

 private static bool IsHumanNPC( Mobile m )
 {
  return ( !m.Player && m.Body.IsHuman );
 }

 private static bool IsPlayer( Mobile m )
 {
  return m.Player;
 }

 private ArrayList m_List;

 private TrackWhoGump( Mobile from, ArrayList list, int range ) : base( 20, 30 )
 {
  m_From = from;
  m_List = list;
  m_Range = range;

  AddPage( 0 );

  AddBackground( 0, 0, 440, 155, 5054 );

  AddBackground( 10, 10, 420, 75, 2620 );
  AddBackground( 10, 85, 420, 45, 3000 );

  if ( list.Count > 4 )
  {
   AddBackground( 0, 155, 440, 155, 5054 );

   AddBackground( 10, 165, 420, 75, 2620 );
   AddBackground( 10, 240, 420, 45, 3000 );

   if ( list.Count > 8 )
   {
    AddBackground( 0, 310, 440, 155, 5054 );

    AddBackground( 10, 320, 420, 75, 2620 );
    AddBackground( 10, 395, 420, 45, 3000 );
   }
  }

  for ( int i = 0; i < list.Count && i < 12; ++i )
  {
   Mobile m = (Mobile)list[i];

   AddItem( 20 + ((i % 4) * 100), 20 + ((i / 4) * 155), ShrinkTable.Lookup( m ) );
   AddButton( 20 + ((i % 4) * 100), 130 + ((i / 4) * 155), 4005, 4007, i + 1, GumpButtonType.Reply, 0 );

   if ( m.Name != null )
    AddHtml( 20 + ((i % 4) * 100), 90 + ((i / 4) * 155), 90, 40, m.Name, false, false );
  }
 }

 public override void OnResponse( NetState state, RelayInfo info )
 {
  int index = info.ButtonID - 1;

  if ( index >= 0 && index < m_List.Count && index < 12 )
  {
   Mobile m = (Mobile)m_List[index];

   m_From.QuestArrow = new TrackArrow( m_From, m, m_Range * 2 );
  }
 }
}

public class TrackArrow : QuestArrow
{
 private Mobile m_From;
 private Timer m_Timer;

 public TrackArrow( Mobile from, Mobile target, int range ) : base( from )
 {
  m_From = from;
  m_Timer = new TrackTimer( from, target, range, this );
  m_Timer.Start();
 }

 public override void OnClick( bool rightClick )
 {
  if ( rightClick )
  {
   m_From = null;

   Stop();
  }
 }

 public override void OnStop()
 {
  m_Timer.Stop();

  if ( m_From != null )
   m_From.SendLocalizedMessage( 503177 ); // You have lost your quarry.
 }
}

public class TrackTimer : Timer
{
 private Mobile m_From, m_Target;
 private int m_Range;
 private int m_LastX, m_LastY;
 private QuestArrow m_Arrow;

 public TrackTimer( Mobile from, Mobile target, int range, QuestArrow arrow ) : base( TimeSpan.FromSeconds( 0.25 ), TimeSpan.FromSeconds( 2.5 ) )
 {
  m_From = from;
  m_Target = target;
  m_Range = range;

  m_Arrow = arrow;
 }

 protected override void OnTick()
 {
  if ( !m_Arrow.Running )
  {
   Stop();
   return;
  }
  else if ( m_From.NetState == null || m_From.Deleted || m_Target.Deleted || m_From.Map != m_Target.Map || !m_From.InRange( m_Target, m_Range ) )
  {
   m_From.Send( new CancelArrow() );
   m_From.SendLocalizedMessage( 503177 ); // You have lost your quarry.

   Stop();
   return;
  }

  if ( m_LastX != m_Target.X || m_LastY != m_Target.Y )
  {
   m_LastX = m_Target.X;
   m_LastY = m_Target.Y;

   m_Arrow.Update( m_LastX, m_LastY );
  }
 }
}}}



Shariz - September 18, 2003 12:40 PM (GMT)
[code]
//from c'est la personne qui double click.
public override void OnDoubleClick( Mobile from)
{
Tracking; //ou this.Tracking;
}
[code]

T'es pas obliger de mettre this. pour name,ect...
this c'est pour faire référence au script même et pas à l'objet. (l'objet est composé de plusieurs script(dont Item)

J'ai pas tester
Signé : Shariz l'ami des plus petits.

Didi - June 7, 2004 03:17 PM (GMT)
this sert surtout pour l'appel de fonction (timer = new PitiTimer(form,this) )

L'art de remonter les posts

slade15 - June 8, 2004 12:26 AM (GMT)
this veux dire l'objet en lui meme (soit meme), c'est a dire dans un script de item this c'est l'item concerné , une bonne utilisation de this c'est comme dit didi dans un appel de fonction auquel on doit passer passer en parametre le l'objet qu'on est en train de scripter

autre exemple :

class test : Item

public string nom;

public test(string nom);
{
this.nom = nom;
}

ici le this. est obligatoire pour ne pas avoir confusion en la varible du item et celle recu en parametre, dont l'utilite de l'appeler par exemple i_nom;




Hosted for free by InvisionFree