Lottery: Difference between revisions

From Revenant Elegy Wiki
Jump to navigation Jump to search
Line 19: Line 19:


# Totals all tickets sold in the current round.
# Totals all tickets sold in the current round.
# Computes the prize as a percentage of the total pool (default: '''95%''').
# Computes the prize as a percentage of the total pool ('''95%''').
# Selects a winning ticket at random — each ticket a player holds represents one entry, so more tickets means proportionally better odds.
# Selects a winning ticket at random — each ticket a player holds represents one entry, so more tickets means proportionally better odds.
# Deposits the prize into a pending winnings table and makes a server-wide announcement.
# Deposits the prize into a pending winnings table and makes a server-wide announcement.

Revision as of 07:33, 6 April 2026


The Lottery is a pool-based raffle system that allows players to purchase tickets for a chance to win a large zeny prize. Tickets are sold continuously throughout a round; at the end of each round a winner is drawn at random and awarded a percentage of the total pool.

The current jackpot is displayed as a live chatroom bubble above the NPC's head, updated after every purchase and every draw.

How It Works

Buying Tickets

Players speak to the Lottery Master NPC in Prontera (147, 174) to purchase tickets for the current round. Each ticket costs 100,000z. A player may hold up to 10 tickets per round. Tickets can be purchased one at a time or in bulk up to the remaining allowance.

Zeny is deducted immediately upon confirming the purchase. If a player does not have sufficient funds, or has already reached the ticket cap, the purchase is declined.

The Draw

A draw is performed automatically on a scheduled interval (every 7 days). At draw time the script:

  1. Totals all tickets sold in the current round.
  2. Computes the prize as a percentage of the total pool (95%).
  3. Selects a winning ticket at random — each ticket a player holds represents one entry, so more tickets means proportionally better odds.
  4. Deposits the prize into a pending winnings table and makes a server-wide announcement.
  5. Advances to the next round.

If no tickets were sold when the draw fires, the round is simply skipped and a new one begins.

Claiming Winnings

When a winner speaks to the Lottery Master NPC, they are shown their unclaimed prize and given the option to claim it immediately. The zeny is added directly to their character whether they are online or offline at the time of the draw. Winnings accumulate if a player wins multiple rounds before claiming.

Odds

Odds are proportional to the number of tickets held relative to the total tickets sold that round.

<math>\text{Win probability} = \frac{\text{Your tickets}}{\text{Total tickets sold}}</math>

A player holding 5 of 50 tickets sold has a 10% chance of winning. Buying more tickets always improves odds, up to the per-player cap.

Configuration

All configurable values are set inside the LotteryController script NPC:

Variable Default Description
.ticket_price 100,000z Zeny cost per ticket
.max_tickets 10 Maximum tickets a single player may hold per round
.prize_ratio 95 Percentage of the total pool paid to the winner; the rest is a zeny sink
.draw_interval 604800 (7 days) Seconds between automatic draws

Common Draw Intervals

Interval Seconds
Daily 86,400
Weekly 604,800
Monthly 2,592,000

NPC Locations

NPC Name Map Coordinates Sprite
Lottery Master prontera 147, 174, South 717

Additional locations can be added by duplicating the Lottery Master NPC block: <syntaxhighlight lang="text"> prontera,X,Y,D duplicate(Lottery Master) Lottery Master#2 717 </syntaxhighlight>

GM Commands

Command Minimum Level Description
@lottodraw 99 Forces an immediate draw and announces it server-wide

Technical Notes

  • Prize and pool totals are computed in SQL to avoid 32-bit integer overflow on high-volume servers.
  • Prizes are written directly to the winner's character row in the database, so they are received even if the player is offline at the time of the draw.
  • The chatroom display updates after every ticket purchase, every scheduled draw, and every minute tick so that passersby always see the current jackpot.
  • Changing .draw_interval only affects the next scheduled draw. To reset the timer immediately, delete the global variable $lottery_next_draw via @setglobalvar and then reload the NPC with @reloadnpc.
  • If a winner accumulates multiple prizes before claiming (e.g., wins back-to-back rounds), the unclaimed amounts stack and are paid out together.

Database Tables

The system creates two tables automatically on first load:

lottery_tickets
Stores ticket purchases per player per round. Cleared at the end of each round.
lottery_winnings
Holds unclaimed prizes. A row persists until the winner visits the NPC and claims their winnings. On duplicate wins the prize column accumulates.

See Also