Last active
January 10, 2025 21:45
-
-
Save PrivateDonut/6bf8a96802f14c5e5a447f1e5b22c51a to your computer and use it in GitHub Desktop.
Russian Roulette Gambler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local GOSSIP_ICON_CHAT = 0 | |
local GOSSIP_ICON_MONEY = 6 | |
local NPC_ENTRY = 100002 -- Entry ID to your in-game gossip NPC | |
local ITEM_ENTRY = 20880 -- Replace with your item entry ID | |
local BASE_REWARD = 1 -- Number of items | |
local REWARD_MULTIPLIER = 2 -- Double the reward each round | |
local MAX_ROUNDS = 6 | |
local BASE_DEATH_CHANCE = 1 -- Start with 1/6 chance of losing | |
local DEATH_CHANCE_INCREMENT = 0.5 -- Increase death chance by 0.5 each round | |
local INITIAL_BET = 1 -- Number of items to bet | |
local ITEM_ENTRY = 20880 -- Replace with your item entry ID | |
local function OnGossipHello(event, player, object) | |
player:GossipClearMenu() | |
player:GossipMenuAddItem(GOSSIP_ICON_CHAT, "Play Russian Roulette (Bet: " .. INITIAL_BET .. " " .. GetItemLink(ITEM_ENTRY) .. ")", 0, 1) | |
player:GossipMenuAddItem(GOSSIP_ICON_CHAT, "Nevermind", 0, 2) | |
player:GossipSendMenu(1, object) | |
end | |
local function OnGossipSelect(event, player, object, sender, intid, code, menu_id) | |
if (intid == 1) then | |
-- Start the game | |
if player:GetItemCount(ITEM_ENTRY) < INITIAL_BET then | |
player:SendBroadcastMessage("|cffff0000[Russian Roulette]|r You don't have enough " .. GetItemLink(ITEM_ENTRY) .. " to play!") | |
player:GossipComplete() | |
return | |
end | |
player:RemoveItem(ITEM_ENTRY, INITIAL_BET) | |
player:SetData("RR_ROUND", 1) | |
player:SetData("RR_REWARD", INITIAL_BET * REWARD_MULTIPLIER) | |
player:SetData("RR_CURRENT_BET", INITIAL_BET) | |
PlayRound(player, object) | |
elseif (intid == 2) then | |
-- Exit | |
player:GossipComplete() | |
elseif (intid == 3) then | |
-- Continue playing | |
local round = player:GetData("RR_ROUND") | |
local currentBet = player:GetData("RR_CURRENT_BET") | |
local newBet = currentBet * REWARD_MULTIPLIER | |
local additionalBet = newBet - currentBet | |
if player:GetItemCount(ITEM_ENTRY) < additionalBet then | |
player:SendBroadcastMessage("|cffff0000[Russian Roulette]|r You don't have enough " .. GetItemLink(ITEM_ENTRY) .. " to continue!") | |
CashOut(player) | |
return | |
end | |
player:RemoveItem(ITEM_ENTRY, additionalBet) | |
if round < MAX_ROUNDS then | |
round = round + 1 | |
player:SetData("RR_ROUND", round) | |
local reward = player:GetData("RR_REWARD") | |
reward = reward * REWARD_MULTIPLIER | |
player:SetData("RR_REWARD", reward) | |
player:SetData("RR_CURRENT_BET", newBet) | |
PlayRound(player, object) | |
else | |
-- Player has won the maximum number of rounds | |
local finalReward = player:GetData("RR_REWARD") | |
player:AddItem(ITEM_ENTRY, finalReward) | |
player:SendBroadcastMessage("|cffff0000[Russian Roulette]|r Congratulations! You made it through all 6 rounds. Your reward: " .. finalReward .. " " .. GetItemLink(ITEM_ENTRY)) | |
player:GossipComplete() | |
end | |
elseif (intid == 4) then | |
-- Cash out | |
CashOut(player) | |
end | |
end | |
function PlayRound(player, object) | |
local round = player:GetData("RR_ROUND") | |
local reward = player:GetData("RR_REWARD") | |
local currentBet = player:GetData("RR_CURRENT_BET") | |
local nextBet = currentBet * REWARD_MULTIPLIER | |
local additionalBet = nextBet - currentBet | |
local deathChance = BASE_DEATH_CHANCE + (round - 1) * DEATH_CHANCE_INCREMENT | |
if (math.random() < (deathChance / 6)) then | |
-- Player loses | |
player:SendBroadcastMessage("|cffff0000[Russian Roulette]|r BANG! You lost everything!") | |
player:kill(player) | |
player:GossipComplete() | |
else | |
-- Player survives | |
player:GossipClearMenu() | |
local riskPercentage = math.floor((deathChance / 6) * 100) | |
player:GossipMenuAddItem(GOSSIP_ICON_CHAT, string.format("Continue playing \nCurrent Reward: %d %s \nNext Bet: %d %s, \nYour Current Risk: %d%%", | |
reward, GetItemLink(ITEM_ENTRY), additionalBet, GetItemLink(ITEM_ENTRY), riskPercentage), 0, 3) | |
player:GossipMenuAddItem(GOSSIP_ICON_MONEY, string.format("Cash out %d %s", reward, GetItemLink(ITEM_ENTRY)), 0, 4) | |
player:GossipSendMenu(1, object) | |
end | |
end | |
function CashOut(player) | |
local reward = player:GetData("RR_REWARD") | |
player:AddItem(ITEM_ENTRY, reward) | |
player:SendBroadcastMessage("|cffff0000[Russian Roulette]|r You've cashed out " .. reward .. " " .. GetItemLink(ITEM_ENTRY)) | |
player:GossipComplete() | |
end | |
RegisterCreatureGossipEvent(NPC_ENTRY, 1, OnGossipHello) | |
RegisterCreatureGossipEvent(NPC_ENTRY, 2, OnGossipSelect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment