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