View Full Version: Script à "automatiser"

RunUO.FR Support > Probleme de script > Script à "automatiser"


Title: Script à "automatiser"


Kaervek - October 26, 2003 07:51 PM (GMT)
Volà, j'ai créé ce script pour intégrer une sorte de système boursier au serveur (simplifié bien entendu de manière à le faire apparaitre sous forme de "jeu")

Seulement, je suis obligé de modifier moi même la valeur des actions manuellement. N'y aurait-il aucun moyen pour modifier cette valeur de base (en insérant une nouvelle valeur aléatoire comprise par ex entre 0,94 et 1,05 qui multiplierait la valeur de base) de manière automatique toutes les 24h?

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

namespace Server.Gumps
{
  public class GumpActions001 : Gump
  {
     public static void Initialize()
     {
        Commands.Register( "Actions", AccessLevel.Player, new CommandEventHandler( GumpActions001_OnCommand ) );
     }

     private static void GumpActions001_OnCommand( CommandEventArgs e )
     {
        e.Mobile.SendGump( new GumpActions001( e.Mobile ) );
     }

     public GumpActions001( Mobile owner ) : base( 50,50 )
     {
       
        AddPage( 0 );
        AddBackground( 0, 0, 500, 320, 2600 );
        AddImage( 320, 40, 60468, 0x34 );
        AddImage( 320, 40, 120 );
        AddImage( 320, 40, 60441 );
        AddImage( 320, 40, 60999, 0x34 );
        AddImage( 320, 40, 60476, 0x134 );
        AddImage( 320, 40, 50937, 0x134 );
        AddImage( 320, 40, 60438, 0x134 );
        AddImage( 320, 40, 60439, 0x134 );
        AddImage( 320, 40, 60440, 0x134 );
       
       
        AddPage( 1 );
         AddHtml( 20, 20, 460, 27," Désirez-vous vendre ou acheter ?", true, false );
       
         
        AddButton( 35, 63, 0x2623, 0x2622, 11, GumpButtonType.Page, 2 );
        AddLabel( 55, 60, 0x34, "Acheter" );

        AddButton( 35, 93, 0x2623, 0x2622, 12, GumpButtonType.Page, 3 );
        AddLabel( 55, 90, 0x34, "Vendre" );
 
 
 
 
 
   AddPage( 2 );
         AddHtml( 20, 20, 460, 27," Voici les différentes actions disponibles. ", true, false );
         
         AddButton( 165, 260, 0x119a, 0x119a, 1, GumpButtonType.Page, 1 );
       
        AddButton( 35, 63, 0x2623, 0x2622, 21, GumpButtonType.Reply, 0 );
        AddLabel( 55, 60, 0x34, "Meliok (1000po)" );

        AddButton( 35, 93, 0x2623, 0x2622, 22, GumpButtonType.Reply, 0 );
        AddLabel( 55, 90, 0x34, "Christellya (2000po)" );

        AddButton( 35, 123, 0x2623, 0x2622, 23, GumpButtonType.Reply, 0 );
        AddLabel( 55, 120, 0x34, "Alchor (5000po)" );
 
 
 
 
   AddPage( 3 );
         AddHtml( 20, 20, 460, 27," Que désirez-vous vendre ? ", true, false );
         
         AddButton( 165, 260, 0x119a, 0x119a, 1, GumpButtonType.Page, 1 );
       
        AddButton( 35, 63, 0x2623, 0x2622, 31, GumpButtonType.Reply, 0 );
        AddLabel( 55, 60, 0x34, "Meliok (1000po)" );

        AddButton( 35, 93, 0x2623, 0x2622, 32, GumpButtonType.Reply, 0 );
        AddLabel( 55, 90, 0x34, "Christellya (2000po)" );

        AddButton( 35, 123, 0x2623, 0x2622, 33, GumpButtonType.Reply, 0 );
        AddLabel( 55, 120, 0x34, "Alchor (5000po)" );



       
       
       
         
 }

     public override void OnResponse( NetState state, RelayInfo info )
     {
        Mobile from = state.Mobile;

        switch ( info.ButtonID )
        {
           case 0:
           {  break; }
  case 11:
           {  break; }
  case 12:
           { break; }
 
 
  case 21:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( Gold ), 990 ) )  // Lors de mise à jour, multiplier par 0,94 à 1,05
 {
          from.SendMessage( "Voici votre Action" );
    from.AddToBackpack( new ActionMELIOK ());
    from.SendGump( new GumpActions001( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Il vous faut plus d'or." );
    from.SendGump( new GumpActions001( from ) );
 }
              break;
           }
 
 
 
  case 22:
          {
    Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( Gold ), 2000 ) ) // Lors de mise à jour, multiplier par 0,95 à 1,06
 {
          from.SendMessage( "Voici votre Action" );
    from.AddToBackpack( new ActionCHRISTELLYA ());
    from.SendGump( new GumpActions001( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Il vous faut plus d'or." );
    from.SendGump( new GumpActions001( from ) );
 }
              break;
           }
 
 
  case 23:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( Gold ), 4700 ) ) // Lors de mise à jour, multiplier par 0,94 à 1,07
 {
          from.SendMessage( "Voici votre Action" );
    from.AddToBackpack( new ActionALCHOR ());
    from.SendGump( new GumpActions001( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Il vous faut plus d'or." );
    from.SendGump( new GumpActions001( from ) );
 }
              break;
           }
 
 
 
  case 31:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( ActionMELIOK ), 1 ) )
 {
          from.SendMessage( "Merci pour cet échange." );
    from.AddToBackpack( new Gold (990));
    from.SendGump( new GumpActions001( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Vous n'avez pas d'action de ce type à vendre." );
    from.SendGump( new GumpActions001( from ) );
 }
              break;
           }
 
  case 32:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( ActionCHRISTELLYA ), 1 ) )
 {
          from.SendMessage( "Merci pour cet échange." );
    from.AddToBackpack( new Gold (2000));
    from.SendGump( new GumpActions001( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Vous n'avez pas d'action de ce type à vendre." );
    from.SendGump( new GumpActions001( from ) );
 }
              break;
           }
 
 
  case 33:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( ActionALCHOR ), 1 ) )
 {
          from.SendMessage( "Merci pour cet échange." );
    from.AddToBackpack( new Gold (4700));
    from.SendGump( new GumpActions001( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Vous n'avez pas d'action de ce type à vendre." );
    from.SendGump( new GumpActions001( from ) );
 }
              break;
           }
 
 
         
        }
     }
  }
}

crystal - October 27, 2003 02:04 AM (GMT)
tu met ta valeur dans une variable , puis tu fait un timer qui au bout de 24H va mettre cette valeur a jour

valeur = 990 * ((Rand 11 + 94) /100) // pas sur pour le random c'est peut etre RND

Tips : met la valeur a jour puis declenche le timer pour la remettre a jour que la valeur soit pas 0 si ton serveur reboot

tu comprend le principe ?

Kaervek - October 27, 2003 06:14 PM (GMT)
Heu vi merci mais comment je fais pour intégrer ca? *rougit de honte*

Kaervek - November 5, 2003 07:51 PM (GMT)
Bon bon bon... J'ai essayé un truc mais c'est déjà la cata avant que je ne touche aux valeurs en elles memes :P

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



namespace Server.Items
{

public class BouledesActions : Item
{
private int m_VariabledesActions = 1;

[CommandProperty( AccessLevel.GameMaster )]
public int VariabledesActions
{
get
{
return m_VariabledesActions;
}
set
{
m_VariabledesActions = value;
InvalidateProperties();
}
}


[Constructable]
public BouledesActions() : base(0x139D)
{
 Weight = 10; // poid de l'item
 Name = "Boule des Actions"; // Nom de l'item
 Hue = 2; // couleur de l'item
}
    public override void OnDoubleClick( Mobile from ) // lorsqu'on doubleclique dessus
    {
ActionsTimer timer = new ActionsTimer(from); //Il cré un objet nommé timer
 timer.Start(); //Il lance le timer
 from.SendGump( new GumpActions002( from ) );
    }
   

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

public override void Serialize(GenericWriter writer)
{
 base.Serialize(writer);

 writer.Write((int) 0);
 writer.Write( (int) m_VariabledesActions );
}

public override void Deserialize(GenericReader reader)
{
 base.Deserialize(reader);

 int version = reader.ReadInt();
 
 switch ( version )
{
case 0:
{
m_VariabledesActions = reader.ReadInt();

break;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////LE TIMER////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
  public class ActionsTimer : Timer
{
private Mobile m; //On utilisera une variable m plus loin, on indique que ce sera un mobile
   

public ActionsTimer(Mobile from ) : base
( TimeSpan.FromSeconds (36000.0), TimeSpan.FromSeconds (36000.0) ) // On indique le temps que durera le script aux deux endroits. Ici 20 secondes
{
m = from; // on précise que la varibale m sera finalewment le mobile from
m.SendMessage("Début du timer"); // on précise a celui qui a activer le Timer que celui-ci démare
}

protected override void OnTick() //Ici c'est la fin du timer, autrement dit ici apres 20 secondes
{
m_VariabledesActions = 990 * ((Rand 11 + 94) /100);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////GUMP DES ACTIONS////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  public class GumpActions002 : Gump
  {
 
 
     public static void Initialize()
     {
        Commands.Register( "Actions", AccessLevel.Player, new CommandEventHandler( GumpActions002_OnCommand ) );
     }

     private static void GumpActions002_OnCommand( CommandEventArgs e )
     {
        e.Mobile.SendGump( new GumpActions002( e.Mobile ) );
 
     }

     public GumpActions002( Mobile owner ) : base( 50,50 )
     {
       
        AddPage( 0 );
        AddBackground( 0, 0, 500, 320, 2600 );
        AddImage( 320, 40, 60468, 0x34 );
        AddImage( 320, 40, 120 );
        AddImage( 320, 40, 60441 );
        AddImage( 320, 40, 60999, 0x34 );
        AddImage( 320, 40, 60476, 0x134 );
        AddImage( 320, 40, 50937, 0x134 );
        AddImage( 320, 40, 60438, 0x134 );
        AddImage( 320, 40, 60439, 0x134 );
        AddImage( 320, 40, 60440, 0x134 );
       
       
        AddPage( 1 );
         AddHtml( 20, 20, 460, 27," Désirez-vous vendre ou acheter ?", true, false );
       
         
        AddButton( 35, 63, 0x2623, 0x2622, 11, GumpButtonType.Page, 2 );
        AddLabel( 55, 60, 0x34, "Acheter" );

        AddButton( 35, 93, 0x2623, 0x2622, 12, GumpButtonType.Page, 3 );
        AddLabel( 55, 90, 0x34, "Vendre" );
 
 
 
 
 
   AddPage( 2 );
         AddHtml( 20, 20, 460, 27," Voici les différentes actions disponibles. ", true, false );
         
         AddButton( 165, 260, 0x119a, 0x119a, 1, GumpButtonType.Page, 1 );
       
        AddButton( 35, 63, 0x2623, 0x2622, 21, GumpButtonType.Reply, 0 );
        AddLabel( 55, 60, 0x34, "Meliok (980po)" );

        AddButton( 35, 93, 0x2623, 0x2622, 22, GumpButtonType.Reply, 0 );
        AddLabel( 55, 90, 0x34, "Christellya (1805po)" );

        AddButton( 35, 123, 0x2623, 0x2622, 23, GumpButtonType.Reply, 0 );
        AddLabel( 55, 120, 0x34, "Alchor (4841po)" );
 
 
 
 
   AddPage( 3 );
         AddHtml( 20, 20, 460, 27," Que désirez-vous vendre ? ", true, false );
         
         AddButton( 165, 260, 0x119a, 0x119a, 1, GumpButtonType.Page, 1 );
       
        AddButton( 35, 63, 0x2623, 0x2622, 31, GumpButtonType.Reply, 0 );
        AddLabel( 55, 60, 0x34, "Meliok (980po)" );

        AddButton( 35, 93, 0x2623, 0x2622, 32, GumpButtonType.Reply, 0 );
        AddLabel( 55, 90, 0x34, "Christellya (1805po)" );

        AddButton( 35, 123, 0x2623, 0x2622, 33, GumpButtonType.Reply, 0 );
        AddLabel( 55, 120, 0x34, "Alchor (4841po)" );



       
       
       
         
 }

     public override void OnResponse( NetState state, RelayInfo info )
     {
        Mobile from = state.Mobile;

        switch ( info.ButtonID )
        {
           case 0:
           {  break; }
  case 11:
           {  break; }
  case 12:
           { break; }
 
 
  case 21:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( Gold ), 980 ) )  // Lors de mise à jour, multiplier par 0,94 à 1,05
 {
          from.SendMessage( "Voici votre Action" );
    from.AddToBackpack( new ActionMELIOK ());
    from.SendGump( new GumpActions002( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Il vous faut plus d'or." );
    from.SendGump( new GumpActions002( from ) );
 }
              break;
           }
 
 
 
  case 22:
          {
    Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( Gold ), 1805 ) ) // Lors de mise à jour, multiplier par 0,95 à 1,06
 {
          from.SendMessage( "Voici votre Action" );
    from.AddToBackpack( new ActionCHRISTELLYA ());
    from.SendGump( new GumpActions002( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Il vous faut plus d'or." );
    from.SendGump( new GumpActions002( from ) );
 }
              break;
           }
 
 
  case 23:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( Gold ), 4841 ) ) // Lors de mise à jour, multiplier par 0,94 à 1,07
 {
          from.SendMessage( "Voici votre Action" );
    from.AddToBackpack( new ActionALCHOR ());
    from.SendGump( new GumpActions002( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Il vous faut plus d'or." );
    from.SendGump( new GumpActions002( from ) );
 }
              break;
           }
 
 
 
  case 31:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( ActionMELIOK ), 1 ) )
 {
          from.SendMessage( "Merci pour cet échange." );
    from.AddToBackpack( new Gold (980));
    from.SendGump( new GumpActions002( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Vous n'avez pas d'action de ce type à vendre." );
    from.SendGump( new GumpActions002( from ) );
 }
              break;
           }
 
  case 32:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( ActionCHRISTELLYA ), 1 ) )
 {
          from.SendMessage( "Merci pour cet échange." );
    from.AddToBackpack( new Gold (1805));
    from.SendGump( new GumpActions002( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Vous n'avez pas d'action de ce type à vendre." );
    from.SendGump( new GumpActions002( from ) );
 }
              break;
           }
 
 
  case 33:
           {
  Container pack = from.Backpack;
  if ( pack != null && pack.ConsumeTotal( typeof( ActionALCHOR ), 1 ) )
 {
          from.SendMessage( "Merci pour cet échange." );
    from.AddToBackpack( new Gold (4841));
    from.SendGump( new GumpActions002( from ) );
 }
  else
 {
    from.SendMessage( 0x22, "Vous n'avez pas d'action de ce type à vendre." );
    from.SendGump( new GumpActions002( from ) );
 }
              break;
           }
 
 
         
        }
     }
   
 
 
 


}}


Ca me dit que m_VariabledesActions n'existe pas dans Actions.Timer


Hmmm c'est vraiment la foret vierge là mon truc... Je vais refaire ca bien au calme plus tard je pense car là... Hum... :wacko:

Didi - November 5, 2003 09:27 PM (GMT)
CODE
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////LE TIMER////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 public class ActionsTimer : Timer
{
private Mobile m;
private int m_VariabledesActions;  

public ActionsTimer(Mobile from ) : base
( TimeSpan.FromSeconds (36000.0), TimeSpan.FromSeconds (36000.0) )
{
m = from;
m.SendMessage("Début du timer");
}

protected override void OnTick()
{
m_VariabledesActions = 990 * ((Rand 11 + 94) /100);
}
}

Kaervek - November 6, 2003 05:21 AM (GMT)
Merci pour le timer :)

Sinon pour la valeur
CODE
m_VariabledesActions = 990 * ((Rand 11 + 94) /100);

ou meme
CODE
m_VariabledesActions = 990 * ((RND 11 + 94) /100);


Ca ne fonctionnait pas, donc j'ai essayé ceci:
switch ( Utility.Random( 13 ))
CODE
{
   case 0: m_VariabledesActions *= 0.95; break;
   case 1: m_VariabledesActions *= 0.96; break;
   case 2: m_VariabledesActions *= 0.97; break;
   case 3: m_VariabledesActions *= 0.98; break;
   case 4: m_VariabledesActions *= 0.99; break;
   case 5: m_VariabledesActions *= 1; break;
   case 6: m_VariabledesActions *= 1.01; break;
   case 7: m_VariabledesActions *= 1.02; break;
   case 8: m_VariabledesActions *= 1.03; break;
   case 9: m_VariabledesActions *= 1.04; break;
   case 10: m_VariabledesActions *= 1.05; break;
   case 11: m_VariabledesActions *= 1.06; break;
   case 12: m_VariabledesActions *= 1.07; break;
  }

Et ca me dit qu'on ne peut pas convertir implicitement un "double" en un "int"




* Hosted for free by InvisionFree