Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- by Rochet2 of ac-web.com modified by Black Wolf for The Wolf Den modified by Rochet2
- local npcid = 50120
- function On_Gossip(pUnit,event,player)
- pUnit:GossipCreateMenu(100, player, 0)
- pUnit:GossipMenuAddItem(0, "Purchase 500 custom coins. Cost: 50 mg", 101, 0)
- pUnit:GossipMenuAddItem(0, "Purchase 1000 custom coins. Cost: 100 mg", 102, 0)
- pUnit:GossipMenuAddItem(0, "Purchase 5000 custom coins. Cost: 500 mg", 103, 0)
- pUnit:GossipMenuAddItem(0, "You must have a minimum balance of 550 mg to conduct business with me.", 100, 0) -- Write this in the header text (npc_text)?
- pUnit:GossipSendMenu(player)
- end
- function On_Select(pUnit, event, player, id, intid, code)
- -- Making Amt and Sur to be local inside the On_Select, yet still being possible to use as "global" inside the function.
- local Amt
- local Sur
- if (intid == 100) then
- -- this prevents menu freezing and invalid queries due to missing variables
- On_Gossip(pUnit,event,player) -- Back to "main" menu
- return -- Do not execute the rest of the code
- elseif (intid == 101) then
- Amt = 500 -- amount requested
- Sur = 50 -- transaction fee of 10 percent
- elseif (intid == 102) then
- Amt = 1000 -- amount requested
- Sur = 100 -- transaction fee of 10 percent
- elseif (intid == 103) then
- Amt = 5000 -- amount requested
- Sur = 500 -- transaction fee of 10 percent
- end
- local CheckMG = WorldDBQuery("SELECT `mg` FROM logon.accounts WHERE `login` = '"..player:GetAccountName().."';"); -- queries variable data from db mg location.
- if(not CheckMG) then -- Check if the query was succesful, if not: error and do nothing more
- print("Query failed")
- return -- Stop executing the rest of the code since the query did not return anything.
- end
- local MagicGold = CheckMG:GetColumn(0):GetULong() -- Get MagicGold
- if (MagicGold < Amt + Sur) then
- player:SendAreaTriggerMessage("You don't have enough. Balance: "..MagicGold.." mg.") -- inform player about balance and error
- else
- local rest = MagicGold - (Amt + Sur) -- How much the player has MG left after cashing out
- if(player:AddItem(62005, Amt)) 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 "..amt.." custom Coins") -- 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