RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

More RandomDouble functions

Kamron

Knight
I made a few changes to make it more standard to the other RunUO code. Nothing major, or even eventful.
 

Kamron

Knight
I updated this code to fix a bug. You can find the updated code OFF-SITE. Please check the original thread for the link.
 

Sunshine

Wanderer
Thank you for offering the information, I was doing a search for how to add random drops when you double click a deed.


If you know of a place where I can find more information to help me to create the random drop on double click of a deed( then it would disappear) please point me in the direction. I am not afraid to try and to come back and offer what I have and ask for help. But I have done many searches here and can not seem to find what would be simular.

Thank you for your time and effort.

It is apprecated
 

Kamron

Knight
If you want to get a random chance, lets say 20%, you would do this

if ( 0.20 > Utility.RandomDouble() )
{
20% chance stuff goes here
}
else
{
80% chance stuff goes here
}

All basic percent chances are based on that format.
 

Sunshine

Wanderer
hmm not sure as I have more than 2 things ..

I was thinking the

switch ( Utility.Random( 29 ))
{
case 0: PackItem( new item() ); break;
case 1: PackItem( new item() ); break;
case 2: PackItem( new item() ); break;

}


But I am not figuring it out correctly..here is what I have so far

I just want the deed to allow them to double click it and randomly get 1 of 3 things

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;
using Server.Gumps;
namespace Server.Items
{
 public class PinataTicket : Item
 {
  private Mobile m_Owner;
  [CommandProperty( AccessLevel.GameMaster )]
  public Mobile Owner
  {
   get{ return m_Owner; }
   set{ m_Owner = value; }
  }
  [Constructable]
  public PinataTicket() : base( 0x14EF )
  {
   Weight = 1.0;
   LootType = LootType.Blessed;
  }
 
  public override bool DisplayLootType{ get{ return false; } }
  public PinataTicket( Serial serial ) : base( serial )
  {
  }
  public override void Serialize( GenericWriter writer )
  {
   base.Serialize( writer );
   writer.Write( (int) 0 ); // version
   writer.Write( (Mobile) m_Owner );
  }
  public override void Deserialize( GenericReader reader )
  {
   base.Deserialize( reader );
   int version = reader.ReadInt();
   switch ( version )
   {
    case 0:
    {
     m_Owner = reader.ReadMobile();
     break;
    }
   }
   if ( Name == "Pinata Ticket" )
    Name = null;
  }
  public override void OnDoubleClick( Mobile from )
  {
 
    if ( !IsChildOf( from.Backpack ) )
   {
    from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
   }
 
  private class InternalTarget : Target
  {
   private PinataTicket m_Ticket;
   public InternalTarget( PinataTicket ) : base( 2, false, TargetFlags.None )
   {
    m_Ticket = ticket;
   }
   protected override void OnTarget( Mobile from, object targeted )
   {
    if ( targeted == m_Ticket )
 
 
 
    if ( m_Ticket.Deleted )
     return;
    int number = 0;
    Item item = null;
    Item item2 = null;
    switch ( info.ButtonID )
 
    if ( item != null )
    {
     m_Ticket.Delete();
     m_From.SendLocalizedMessage( number );
     m_From.AddToBackpack( item );
     if ( item2 != null )
      m_From.AddToBackpack( item2 );
    }
   }
  }
 }
}

Not that it is not painful obvious but I am trying to learn and soo new at this I am still green.
I am modifying or trying to mod the new player ticket...it is the only base I could find that came close
 

Kamron

Knight
there are multiple ways to approach this..

If you want an even chance for 6 objects to be used, you would do

switch ( Utility.Random( 6 ) )
{
case 0: blah blah; break;
case 1: blah blah; break;
....
case 5: blah blah; break;
}

if you want a 20% chance for one thing, a 40% chance for another, and a 30% chance for a third, and the rest for a fourth, you would do it like this

double random = Utility.RandomDouble();
if ( 0.20 > random )
blah blah;
else if ( 0.60 > random )
blah blah;
else if ( 0.90 > random )
blah blah;
else
blah blah;
 

Sunshine

Wanderer
Code:
RunUO - [www.runuo.com] Version 1.0.0, Build 36918
Scripts: Compiling C# scripts...failed (4 errors, 31 warnings)
 - Error: Scripts\Custom\PinataTicket.cs: CS0103: (line 73, column 35) The name
'PackItem' does not exist in the class or namespace 'Server.Items.PinataTicket'
 - Error: Scripts\Custom\PinataTicket.cs: CS0103: (line 74, column 35) The name
'PackItem' does not exist in the class or namespace 'Server.Items.PinataTicket'
 - Error: Scripts\Custom\PinataTicket.cs: CS0103: (line 75, column 34) The name
'PackItem' does not exist in the class or namespace 'Server.Items.PinataTicket'
 - Error: Scripts\Custom\PinataTicket.cs: CS1501: (line 79, column 17) No overlo
ad for method 'Target' takes '0' arguments
 Scripts: One or more scripts failed to compile or no script files were found.
 - Press return to exit, or R to try again.

that is the errors ..I been working on this sence I seen your reply even before I posted back....but am now at my wits in ...feeling hopeless please can you help me, anyone?


Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;
using Server.Gumps;
namespace Server.Items
{
 public class PinataTicket : Item
 {
  private Mobile m_Owner;
  [CommandProperty( AccessLevel.GameMaster )]
  public Mobile Owner
  {
   get{ return m_Owner; }
   set{ m_Owner = value; }
  }
  [Constructable]
  public PinataTicket() : base( 0x14EF )
  {
   Weight = 1.0;
   LootType = LootType.Blessed;
  }

  public override bool DisplayLootType{ get{ return false; } }
  public PinataTicket( Serial serial ) : base( serial )
  {
  }
  public override void Serialize( GenericWriter writer )
  {
   base.Serialize( writer );
   writer.Write( (int) 0 ); // version
   writer.Write( (Mobile) m_Owner );
  }
  public override void Deserialize( GenericReader reader )
  {
   base.Deserialize( reader );
   int version = reader.ReadInt();
   switch ( version )
   {
    case 0:
    {
     m_Owner = reader.ReadMobile();
     break;
    }
   }
   if ( Name == "Pinata Ticket" )
    Name = null;
  }
  public override void OnDoubleClick( Mobile from )
  {
  
    if ( !IsChildOf( from.Backpack ) )
   {
    from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
   }
   
                      switch ( Utility.Random( 3 ) )
                      {
                          case 0: PackItem(new Pinatagold() ); break;
                          case 1: PackItem(new Pinata() ); break;
                         case 2: PackItem(new Pinatatoken() ); break;
                     } }
  private class InternalTarget : Target
  {
   private PinataTicket m_Ticket;
    }
   }
  }

I just want to make a simple ticket when double clicked the player is given 1 of 3 items equal chance of all of them appearing in the back pack. then ticket dissappears


sounds soo easy but is soo hard
 

Packer898

Knight
Try this instead...

Code:
switch ( Utility.Random( 3 ) )
                      {
                          case 0: [COLOR="Red"]from.AddToBackpack[/COLOR](new Pinatagold() ); break;
                          case 1: [COLOR="Red"]from.AddToBackpack[/COLOR](new Pinata() ); break;
                         case 2: [COLOR="Red"]from.AddToBackpack[/COLOR](new Pinatatoken() ); break;
                     }

Now on a different note why are you posting help for this here? This has nothing to do with SP!DERS new random double functions. This should have gone in Script Support instead of here. Im sure that SP!DER is being nice about it but alot of others would be rather upset at the hijack of the thread for something that doesnt have anything to do with the authors post.
 

Sunshine

Wanderer
thank you for your offer of help

Yes spider was very kind in helping me with another double click thing I was looking for. It was not my intent to hyjack or upset anyone. But I am grateful for the help I recieved and in the future will be more careful where I ask things. I am sorry but I thank you for your kindness in helping and not flaming me.
 
Top