Skip to content

Instantly share code, notes, and snippets.

@DeluxtDev
Created July 12, 2024 06:32
Show Gist options
  • Save DeluxtDev/c4d40aed011925bdd5e2ae0a5786c0b7 to your computer and use it in GitHub Desktop.
Save DeluxtDev/c4d40aed011925bdd5e2ae0a5786c0b7 to your computer and use it in GitHub Desktop.
Roll The Dice
-- Created for WowEmulation.com by Deluxt
-- This script is a casino like game where you roll a pair of dice and the highest number wins.
local config = {
-- Creature entry must be a gossip creature.
creature_entry = 100007,
-- Token (Cost to play)
token_entry = 100001,
token_amount = 1,
-- Reward
reward_entry = 100001,
reward_amount = 5,
-- Texts
text_not_enough_tokens = "You don't have enough tokens!",
text_win = "You win!",
text_lose = "You lose!",
text_tie = "It's a tie! No chips were taken from you."
}
local function HasToken(player)
return player:GetItemCount(config.token_entry) >= config.token_amount
end
local function OnGossipHello(event, player, object)
if (not HasToken(player)) then
player:SendBroadcastMessage(config.text_not_enough_tokens)
player:GossipComplete()
return
end
player:GossipClearMenu()
player:GossipMenuAddItem(0, "Play roll the dice!", 0, 1)
player:GossipMenuAddItem(0, "Maybe later.", 0, 99)
player:GossipSendMenu(1, object)
end
local function OnGossipSelect(event, player, object, sender, intid, code)
if (intid == 1) then
local player_die_1 = math.random(1, 6)
local player_die_2 = math.random(1, 6)
local player_total = player_die_1 + player_die_2
local bot_die_1 = math.random(1, 6)
local bot_die_2 = math.random(1, 6)
local bot_total = bot_die_1 + bot_die_2
player:SendBroadcastMessage("You rolled "..player_die_1.." and "..player_die_2.." for a total of "..player_total)
player:SendBroadcastMessage("The bot rolled "..bot_die_1.." and "..bot_die_2.." for a total of "..bot_total)
if (player_total > bot_total) then
player:SendBroadcastMessage(config.text_win)
player:AddItem(config.reward_entry, config.reward_amount)
elseif (player_total == bot_total) then
player:SendBroadcastMessage(config.text_tie)
player:GossipComplete()
return
else
player:SendBroadcastMessage(config.text_lose)
end
end
player:RemoveItem(config.token_entry, config.token_amount)
player:GossipComplete()
end
RegisterCreatureGossipEvent(config.creature_entry, 1, OnGossipHello)
RegisterCreatureGossipEvent(config.creature_entry, 2, OnGossipSelect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment