Last active
July 12, 2024 23:47
-
-
Save DeluxtDev/8301681a2411df00bbad5c308cc9a645 to your computer and use it in GitHub Desktop.
Guess The Number
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
-- Created for WowEmulation.com by Deluxt | |
-- This script is a casino like game where you can guess a number between 1 and 10 winner gets reward. | |
local config = { | |
-- Creature entry must be a gossip creature. | |
creature_entry = 100005, | |
-- 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 guessed the number! Congratulations!", | |
text_lose = "You didn't guess the number! The number was " | |
} | |
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 guess the number!", 0, 1, 0, "Guess a number between 1 and 10") | |
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 number = math.random(1, 10) | |
local guess = tonumber(code) | |
if (guess < 1 or guess > 10) then | |
player:SendBroadcastMessage("Please enter a number between 1 and 10.") | |
player:GossipComplete() | |
return | |
end | |
if (guess == number) then | |
player:SendBroadcastMessage(config.text_win) | |
player:AddItem(config.reward_entry, config.reward_amount) | |
else | |
player:SendBroadcastMessage(config.text_lose .. number) | |
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