Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. local NPC_ID = 15280
  2. local TOKEN_ID = 46691
  3.  
  4. function Gambler_Gossip(event, plr, unit)
  5.     plr:GossipMenuAddItem(6, "You ready to gamble, "..plr:GetName().."?", 0, 1, true, "Insert amount of tokens you want to gamble!")
  6.     plr:GossipMenuAddItem(0, "Nevermind", 0, 2)
  7.     plr:GossipSendMenu(1, unit)
  8. end
  9.  
  10. function Gambler_Event(event, plr, unit, sender, intid, code)
  11.     local chance = math.random(1,5) -- This'll give you a 20% chance to win.
  12.     if(intid == 1) then
  13.         if (tonumber(code)) then -- Check if player actually specified an amount in numbers
  14.             if(plr:GetItemCount(TOKEN_ID) < tonumber(code)) then
  15.                 plr:SendBroadcastMessage("|cFFFFFF9F"..unit:GetName().." says: You do not have "..tonumber(code).." tokens!")
  16.             else
  17.                 if(chance == 1) then
  18.                     plr:SendBroadcastMessage("|cFFFFFF9F"..unit:GetName().." says: Congratulations! You won "..math.ceil(code*0.8).." Tokens!")
  19.                     plr:AddItem(TOKEN_ID, math.ceil(tonumber(code)*0.8))
  20.                 else
  21.                     plr:SendBroadcastMessage("|cFFFFFF9F"..unit:GetName().." says: Too bad "..plr:GetName()..", better luck next time!")
  22.                     plr:RemoveItem(TOKEN_ID, tonumber(code))
  23.                 end
  24.             end
  25.         else
  26.             plr:SendBroadcastMessage("|cFFFFFF9F"..unit:GetName().." says: You need to use numbers, not letters.")
  27.         end
  28.     end
  29.     plr:GossipComplete()
  30. end
  31.  
  32. RegisterCreatureGossipEvent(NPC_ID, 1, Gambler_Gossip)
  33. RegisterCreatureGossipEvent(NPC_ID, 2, Gambler_Event)