View Single Post
02-15-24, 01:16 AM   #1
DennytXVII
A Murloc Raider
Join Date: Feb 2024
Posts: 6
Exclamation New to Lua, and making AddOns. Need Help.

I'm trying to create a simple Death Dice (More so known as Death Rolling) addon, but loading up WoW Classic and testing it with my brother I get the /help error stating it's an invalid/incorrect command. I do see the AddOn in the AddOns tab, I made sure it's the correct "interface" number, and in the .toc file the .lua name matches the .lua file name exactly. Any help would be amazing, please and thank you ♥ Here is the code:

StaticPopupDialogs["DEATHDICE_CONFIRM"] = {
text = "",
button1 = "YES",
button2 = "NO",
OnAccept = function(self, data)
StartGame(data.player, data.target, data.amount, data.unit)
SendMessage("You start a Death Dice game with " .. data.target .. "! Type '/roll' to make your first roll.")
end,
OnCancel = function(self)
SendMessage("You declined the Death Dice game.")
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}

-- Update the SlashCmdList.DEATHDICE function to handle initiating and declining a match
function SlashCmdList.DEATHDICE(msg)
if isGameInProgress then
SendMessage("A Death Dice game is already in progress!")
return
end

local player = UnitName("player")
local targetName = UnitName("target")
local amount, unit = tonumber(msg:match("(%d+)")), msg:match("(%a+)")

if not targetName then
SendMessage("You must target a friendly player to start a Death Dice game.")
return
end

if not amount or not unit or (unit ~= "copper" and unit ~= "silver" and unit ~= "gold") then
SendMessage("Usage: /deathdice <amount> <unit> (e.g., /deathdice 100 gold)")
return
end

local confirmation = StaticPopup_Show("DEATHDICE_CONFIRM", "Do you want to start a Death Dice game with " .. targetName .. " for " .. amount .. " " .. unit .. "?")
if confirmation then
confirmation.data = { player = player, target = targetName, amount = amount, unit = unit }
end
end

-- Update the StartGame function to accept the initiating player's name and the target's name
local function StartGame(player, target, amount, unit)
SendMessage("Death Dice game started! " .. player .. " vs " .. target .. ".")
SendMessage("Bet amount: " .. amount .. " " .. unit .. ".")
isGameInProgress = true
currentPlayer = player
betAmount = ConvertToCopper(amount, unit)
end


Again, to reiterate the title, this is my first addon, and honestly my first lua code. So if I did anything incorrect please help the best you can, I'm still not fully savvy with the lingo if you will lol.

I did try a lua compiler on some site, but I get a nil error about the StaticPopupDialog not being implemented or something along those lines. I know that shouldn't be an issue within WoW since it's built into their 'system'.
  Reply With Quote