slp13at420

WD world trades banker

Jan 1st, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.98 KB | None | 0 0
  1. -- by Rochet2 of ac-web.com modified by Black Wolf for The Wolf Den modified by Rochet2
  2.  
  3.  
  4. local npcid = 50120
  5.  
  6.  
  7.  
  8.  
  9.  
  10. function On_Gossip(pUnit,event,player)
  11.  
  12.  
  13.         pUnit:GossipCreateMenu(100, player, 0)
  14.  
  15.  
  16.         pUnit:GossipMenuAddItem(0, "Purchase 500 custom coins. Cost: 50 mg", 101, 0)
  17.  
  18.  
  19.         pUnit:GossipMenuAddItem(0, "Purchase 1000 custom coins. Cost: 100 mg", 102, 0)
  20.  
  21.  
  22.         pUnit:GossipMenuAddItem(0, "Purchase 5000 custom coins. Cost: 500 mg", 103, 0)
  23.  
  24.  
  25.     pUnit:GossipMenuAddItem(0, "Deposit your Wolf Coins into the MG bank", 104, 0)
  26.  
  27.  
  28.         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)?
  29.  
  30.  
  31.         pUnit:GossipSendMenu(player)
  32.  
  33.  
  34. end
  35.  
  36.  
  37.  
  38.  
  39.  
  40. function On_Select(pUnit, event, player, id, intid, code)
  41.  
  42.  
  43.         -- Making Amt and Sur to be local inside the On_Select, yet still being possible to use as "global" inside the function.
  44.  
  45.  
  46.         local Amt
  47.     local wcc
  48.         local Sur
  49.  
  50.  
  51.         if (intid == 100) then
  52.  
  53.  
  54.                 -- this prevents menu freezing and invalid queries due to missing variables
  55.  
  56.  
  57.                 On_Gossip(pUnit,event,player) -- Back to "main" menu
  58.  
  59.  
  60.                 return -- Do not execute the rest of the code
  61.  
  62.     elseif (intid == 104) then
  63.         wcc = player:GetItemCount(44209)
  64.         player:SendBroadcastMessage("you will deposit "..wcc.." for mg")
  65.         WorldDBQuery("UPDATE logon.accounts SET `mg` = `mg` + "..wcc.."  WHERE `login` = '"..player:GetAccountName().."'; "); -- adds the count of item 44209 to db mg count
  66.         player:SendBroadcastMessage(""..wcc.." mg have been added to your mg bank.")
  67.         player:RemoveItem(44209, wcc)
  68.         return
  69.  
  70.         elseif (intid == 101) then
  71.  
  72.  
  73.                 Amt = 500 -- amount requested
  74.  
  75.  
  76.                 Sur = 50 -- transaction fee of 10 percent
  77.  
  78.  
  79.         elseif (intid == 102) then
  80.  
  81.  
  82.                 Amt = 1000 -- amount requested
  83.  
  84.  
  85.                 Sur = 100 -- transaction fee of 10 percent
  86.  
  87.  
  88.         elseif (intid == 103) then
  89.  
  90.  
  91.                 Amt = 5000 -- amount requested
  92.  
  93.  
  94.                 Sur = 500 -- transaction fee of 10 percent
  95.  
  96.  
  97.         end
  98.  
  99.  
  100.         local CheckMG = WorldDBQuery("SELECT `mg` FROM logon.accounts WHERE `login` = '"..player:GetAccountName().."';"); -- queries variable data from db mg location.
  101.  
  102.  
  103.         if(not CheckMG) then -- Check if the query was succesful, if not: error and do nothing more
  104.  
  105.  
  106.                 print("Query failed")
  107.  
  108.  
  109.                 return -- Stop executing the rest of the code since the query did not return anything.
  110.  
  111.  
  112.         end
  113.  
  114.  
  115.         local MagicGold = CheckMG:GetColumn(0):GetULong() -- Get MagicGold
  116.  
  117.  
  118.         if (MagicGold < Amt + Sur) then
  119.  
  120.  
  121.                 player:SendAreaTriggerMessage("You don't have enough. Balance: "..MagicGold.." mg.") -- inform player about balance and error
  122.  
  123.  
  124.         else
  125.  
  126.  
  127.                 local rest = MagicGold - (Amt + Sur) -- How much the player has MG left after cashing out
  128.  
  129.  
  130.                 if(player:AddItem(44209, Amt)) then --  adds variable based item count. 44209 is custom item
  131.  
  132.  
  133.                         -- This IF statement also checks if adding the items was succesful (full inventory?)
  134.  
  135.  
  136.                         WorldDBQuery("UPDATE logon.accounts SET `mg` = "..rest.."  WHERE `login` = '"..player:GetAccountName().."'; "); -- zero's out mg in db location
  137.  
  138.  
  139.                         player:SendBroadcastMessage("You have purchased "..amt.." custom Coins") -- informs player of amount recieved
  140.  
  141.  
  142.                 else
  143.  
  144.  
  145.                         player:SendAreaTriggerMessage("Your inventory is full") -- Adding the item failed. Do no changes to DB and send error msg.
  146.  
  147.  
  148.                 end
  149.  
  150.  
  151.     end
  152.  
  153.  
  154.         On_Gossip(pUnit,event,player) -- Back to "main" menu
  155.  
  156.  
  157. end
  158.  
  159.  
  160.  
  161.  
  162.  
  163. RegisterUnitGossipEvent(npcid, 1, "On_Gossip")
  164.  
  165.  
  166. RegisterUnitGossipEvent(npcid, 2, "On_Select")
Add Comment
Please, Sign In to add comment