Advertisement
Rochet2

Untitled

Feb 16th, 2012
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local npcid = 50120 -- by Black Wolf for The Wolf Den
  2.  
  3. function On_Gossip(pUnit,event,player)
  4.     pUnit:GossipCreateMenu(100, player, 0)
  5.     pUnit:GossipMenuAddItem(0, "Cash out all of my MG for Golden Vote Certificates. Cost: 5 mg", 100, 0)
  6.     pUnit:GossipMenuAddItem(0, "You must have a minimum balance of 500 mg", 100, 0)
  7.     pUnit:GossipSendMenu(player)
  8. end
  9.  
  10. function On_Select(pUnit, event, player, id, intid, code)
  11.     local CheckMG = WorldDBQuery("SELECT `mg` FROM logon.accounts WHERE `login` = '"..player:GetAccountName().."';"); -- queries variable data from db mg location. location .
  12.     if(not CheckMG) then -- Check if the query was succesful, if not: error and do nothing more
  13.         print("Query failed")
  14.         return
  15.     end
  16.     local MagicGold = CheckMG:GetColumn(0):GetULong() -- Get MagicGold
  17.     if (MagicGold < 500) then
  18.         player:SendAreaTriggerMessage("You don't have enough. Balance: "..MagicGold.." mg.") -- inform player about balance and error
  19.     else
  20.         local Amount = math.floor(MagicGold / 5) -- The amount of Golden vote certificates the player can buy
  21.         local rest = MagicGold - Amount * 5 -- How much the player has MG left after cashing out
  22.         if(player:AddItem(62005, Amount)) then --  adds variable based item count. 62005 is custom item
  23.             -- This IF statement also checks if adding the items was succesful (full inventory?)
  24.             WorldDBQuery("UPDATE logon.accounts SET `mg` = "..rest.."  WHERE `login` = '"..player:GetAccountName().."'; "); -- zero's out mg in db location
  25.             player:SendBroadcastMessage("you have purchased "..Amount.." Golden Vote Certificates ") -- informs player of amount recieved
  26.         else
  27.             player:SendAreaTriggerMessage("Your inventory is full") -- Adding the item failed. Do no changes to DB and send error msg.
  28.         end
  29.     end
  30.     On_Gossip(pUnit,event,player) -- Back to "main" menu
  31. end
  32.  
  33. RegisterUnitGossipEvent(npcid, 1, "On_Gossip")
  34. RegisterUnitGossipEvent(npcid, 2, "On_Select")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement