Finaltwist submitted a new resource:

[RUNUO] Lady Luck - Lottery system for runuo

This is a script i butchered from DATT99's OWTLR. originally part of the token system there, i wanted a simple lottery system for my solo server. This script works with RUNUO, so some minor changes may be required for servUO.

how it works:

place lady luck somewhere
players can buy lottery tickets from the lady luck
the lottery will draw every 168 hours (7 days) as configured in the script.

Note: no winners guaranteed. The prize is set at random between 5000 and 1000000. the...

Read more about this resource...
 
Found BUGs, the purchase of lottery tickets will not deduct the check in the bank safe.

int i_Bank;
int i_Total;
i_Bank = Banker.GetBalance( m_From );
i_Total = i_BuyTickets * i_TicketCost;

if ( i_Bank > i_Total )
{
m_From.BankBox.ConsumeTotal(typeof(Gold), i_Total);
m_From.SendLocalizedMessage( 1060398, i_Total.ToString() ); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
m_From.SendLocalizedMessage( 1060022, Banker.GetBalance( m_From ).ToString() ); // You have ~1_AMOUNT~ gold in cash remaining in your bank box.

LotteryTicket lottery = new LotteryTicket();
lottery.DrawingNumber = i_Drawing;
lottery.StartTicketNumber = i_Ticket;
lottery.EndTicketNumber = (i_Ticket + i_BuyTickets - 1);
m_From.AddToBackpack( lottery );

i_Ticket = (i_Ticket + i_BuyTickets);
m_From.CloseGump( typeof( LadyLuckSellingGump ) );
m_From.SendMessage("You bought {0} lottery tickets.", i_BuyTickets);
i_Reward = ( i_Reward + ( i_BuyTickets * (i_TicketCost/2) ) );
}
else
{
m_From.PlaySound(1069); //play Hey!! sound
m_From.SendMessage("You don't have enough Money!!!!");
m_From.SendMessage("Please make sure you have enough gold in your bank.");
m_From.SendGump( new LadyLuckSellingGump( m_From ) );
}
 

Attachments

  • Lady Luck.cs
    18.6 KB · Views: 2
Last edited:
Found BUGs, the purchase of lottery tickets will not deduct the check in the bank safe.

int i_Bank;
int i_Total;
i_Bank = Banker.GetBalance( m_From );
i_Total = i_BuyTickets * i_TicketCost;

if ( i_Bank > i_Total )
{
m_From.BankBox.ConsumeTotal(typeof(Gold), i_Total);
m_From.SendLocalizedMessage( 1060398, i_Total.ToString() ); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
m_From.SendLocalizedMessage( 1060022, Banker.GetBalance( m_From ).ToString() ); // You have ~1_AMOUNT~ gold in cash remaining in your bank box.

LotteryTicket lottery = new LotteryTicket();
lottery.DrawingNumber = i_Drawing;
lottery.StartTicketNumber = i_Ticket;
lottery.EndTicketNumber = (i_Ticket + i_BuyTickets - 1);
m_From.AddToBackpack( lottery );

i_Ticket = (i_Ticket + i_BuyTickets);
m_From.CloseGump( typeof( LadyLuckSellingGump ) );
m_From.SendMessage("You bought {0} lottery tickets.", i_BuyTickets);
i_Reward = ( i_Reward + ( i_BuyTickets * (i_TicketCost/2) ) );
}
else
{
m_From.PlaySound(1069); //play Hey!! sound
m_From.SendMessage("You don't have enough Money!!!!");
m_From.SendMessage("Please make sure you have enough gold in your bank.");
m_From.SendGump( new LadyLuckSellingGump( m_From ) );
}
Works for me using runuo. perhaps there's difference in how the bankbox is called if you are using servuo?
 
Works for me using runuo. perhaps there's difference in how the bankbox is called if you are using servuo?

My UO station is runuo。
It is now found that there is also a problem with winning the lottery. The lottery number is 300,000 and the winning number is 500,000, which is a number that has not been purchased at all.
 
okay lets walk through this. the section that determines winner ticket is

C#:
                s_WinnerName = "Not claimed";
                
                // calculate odds based on amount being drawn
                
                double mixit = Utility.RandomDouble();
                if ( mixit > 0.80 ) mixit = 0.80;
                if ( mixit < 0.20 ) mixit = 0.20;
                
                double oddsdouble = ( (i_Reward / i_TicketCost) * mixit ) + i_Ticket;
                int odds = Convert.ToInt32(oddsdouble);
                
                i_Winner = Utility.RandomMinMax(1, odds);

                i_WinnerReward = i_Reward;
                dt_NextDrawing = DateTime.Now + TimeSpan.FromHours( i_DrawingDelay );
                World.Broadcast( 38, true, "And the lucky ticket that won {0} gold for drawing number {1} is {2}.", i_WinnerReward, i_Drawing, i_Winner);               
                i_Reward = Utility.RandomMinMax(5000, 1000000);
                i_Drawing++;
                i_Ticket = 1;
                World.Broadcast( 89, true, "If a player has the winning ticket, hand it in to Lady Luck!" );
                World.Broadcast( 66, true, "The next drawing will take place at {0}.", dt_NextDrawing );

so step 1: creating a mixit variable to spruce things up with a value between 0.20 and 0.80
step2: calculate the odds of winning (oddsdouble) by:
- dividing the total reward of the draw by ticket price
- multiply this value by mixit variable
- add to this value the number of tickets purchased
-convert this oddsdouble to integer to get the odds
step3: determine the winning ticket randomly between 1 and the variable odds.

in this manner, the odds of winning should always be between 20% to 80% of the winning amount divided by the ticket price (plus the number of tickets sold). for example, if the lottery is for 500,000 gold and 10 tickets were sold, for 1000 each the winning ticket will have to be between 110 and 410.

Did you change the ticket price? Did you change any other variables? As stated before, the bank instruction works on my version of runuo so it could just be a matter of a different way of calling functions in your version of runuo.

to note: the winning ticket has to be submitted before the next lottery is over.
so if you have the winning ticket for drawing #1 and the lottery is now at drawing #3 you lost your chance to win

Post automatically merged:

okay lets walk through this. the section that determines winner ticket is


in this manner, the odds of winning should always be between 20% to 80% of the winning amount divided by the ticket price (plus the number of tickets sold). for example, if the lottery is for 500,000 gold and 10 tickets were sold, for 1000 each the winning ticket will have to be between 110 and 410.
i misquoted that... what i meant was that the total odds will be between 1 in 110 to 1 in 410
Post automatically merged:

if you changed the lottery ticket value (which it seems you have), that would affect the odds significantly.
at 1 gold a ticket, a drawing of 500,000 gold the odds will be i in 110,000 and 410,000
 
Last edited:
runuo SVN 1091,Client7.0.7.1
Still, bank cheques will not be deducted and money will not be reduced, you can buy lottery tickets
The draw number is much larger than the lottery number purchased, which means that no one won.
headache. . .
 
the draw number is the number of the lottery. etc. lottery draw #1, #2, etc. I have no idea why it's so high on your server. did you edit the file?
draw number should be based on how many draws there have been.

delete lady luck, save the server, restart and spawn her again. You have to save/restart before adding her for the variables to reset.
you should see draw #1 after doing that. Can you let me know if you changed any variables?
Post automatically merged:

1586799403878.png

this is what you should see. drawing #1
Post automatically merged:

I have verified that bank cheques do not go down however. I"ll try to work on this.
Post automatically merged:

I've taken care of the gold/bankcheck issue. Now the person needs to have gold in their backpack or in their bank for the sale to go through. If the person only has cheques in the bank, the sale won't go through.

changed to check gold in the player's backpack as well and use that first if there is enough

Main download changed
 
Last edited:
I did not modify any code。Purchased lottery number 100, winning number is always 200+
Last operation,I added 99999999 and bought 99999 lottery tickets and won. For the second lottery ticket, I bought 100,000 gold coins, 100 numbers, and the number was over 200. Can't win at all.
 
Last edited:
What's your ticket price? Still 1000?

The winning number is a function of the prize size. I just tried it on my server and it works (winning lotter number was 196 for a draw of over 700,000 gold).
Have you deleted lady luck, saved server, restarted server and added a new lady luck? This resets the variable: just deleting lady luck won't work.

If you think it doesn't work, tell me the winning number, how many tickets you bought, and the prize size. if the prize size is over 200,000 gold, the winning number may be over 200...)
 
Yes, the fare is 1000, I have not modified any code.
I collected the NPCs and prevented players from buying lottery tickets. After the draw, the winning lottery number was 139.
 
If you removed lady luck, saved and restarted the server, then the system would have been reset.
I can't help you with the debugging of the script until you can test and tell me 1) the ticket cost, 2) the winning gold amount.
Those two things are what determine the odds.

Perhaps you can spawn lady luck in your jail or GM only area and give it a go. Perhaps edit the 168 timeframe in the script to 1 so that the lottery happens every day to you can test it easier. HAppy to help... but on my end it appears to be working well.

From your post above, the winning lotter number was 139, so that is likely because your winning amount was over 130,000.... that's as intended.
 
Back