SHOW:
|
|
- or go back to the newest paste.
1 | - | local npcid = 50120 -- by Black Wolf for The Wolf Den |
1 | + | -- by Rochet2 of ac-web.com modified by Black Wolf for The Wolf Den modified by Rochet2 |
2 | local npcid = 50120 | |
3 | ||
4 | function On_Gossip(pUnit,event,player) | |
5 | - | pUnit:GossipMenuAddItem(0, "Cash out all of my MG for Golden Vote Certificates. Cost: 5 mg", 100, 0) |
5 | + | |
6 | - | pUnit:GossipMenuAddItem(0, "You must have a minimum balance of 500 mg", 100, 0) |
6 | + | pUnit:GossipMenuAddItem(0, "Purchase 500 custom coins. Cost: 50 mg", 101, 0) |
7 | pUnit:GossipMenuAddItem(0, "Purchase 1000 custom coins. Cost: 100 mg", 102, 0) | |
8 | pUnit:GossipMenuAddItem(0, "Purchase 5000 custom coins. Cost: 500 mg", 103, 0) | |
9 | 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)? | |
10 | pUnit:GossipSendMenu(player) | |
11 | - | local CheckMG = WorldDBQuery("SELECT `mg` FROM logon.accounts WHERE `login` = '"..player:GetAccountName().."';"); -- queries variable data from db mg location. location . |
11 | + | |
12 | ||
13 | function On_Select(pUnit, event, player, id, intid, code) | |
14 | - | return |
14 | + | -- Making Amt and Sur to be local inside the On_Select, yet still being possible to use as "global" inside the function. |
15 | local Amt | |
16 | local Sur | |
17 | - | if (MagicGold < 500) then |
17 | + | if (intid == 100) then |
18 | -- this prevents menu freezing and invalid queries due to missing variables | |
19 | On_Gossip(pUnit,event,player) -- Back to "main" menu | |
20 | - | local Amount = math.floor(MagicGold / 5) -- The amount of Golden vote certificates the player can buy |
20 | + | return -- Do not execute the rest of the code |
21 | - | local rest = MagicGold - Amount * 5 -- How much the player has MG left after cashing out |
21 | + | elseif (intid == 101) then |
22 | - | if(player:AddItem(62005, Amount)) then -- adds variable based item count. 62005 is custom item |
22 | + | Amt = 500 -- amount requested |
23 | Sur = 50 -- transaction fee of 10 percent | |
24 | elseif (intid == 102) then | |
25 | - | player:SendBroadcastMessage("you have purchased "..Amount.." Golden Vote Certificates ") -- informs player of amount recieved |
25 | + | Amt = 1000 -- amount requested |
26 | Sur = 100 -- transaction fee of 10 percent | |
27 | elseif (intid == 103) then | |
28 | Amt = 5000 -- amount requested | |
29 | Sur = 500 -- transaction fee of 10 percent | |
30 | end | |
31 | local CheckMG = WorldDBQuery("SELECT `mg` FROM logon.accounts WHERE `login` = '"..player:GetAccountName().."';"); -- queries variable data from db mg location. | |
32 | if(not CheckMG) then -- Check if the query was succesful, if not: error and do nothing more | |
33 | print("Query failed") | |
34 | return -- Stop executing the rest of the code since the query did not return anything. | |
35 | end | |
36 | local MagicGold = CheckMG:GetColumn(0):GetULong() -- Get MagicGold | |
37 | if (MagicGold < Amt + Sur) then | |
38 | player:SendAreaTriggerMessage("You don't have enough. Balance: "..MagicGold.." mg.") -- inform player about balance and error | |
39 | else | |
40 | local rest = MagicGold - (Amt + Sur) -- How much the player has MG left after cashing out | |
41 | if(player:AddItem(62005, Amt)) then -- adds variable based item count. 62005 is custom item | |
42 | -- This IF statement also checks if adding the items was succesful (full inventory?) | |
43 | WorldDBQuery("UPDATE logon.accounts SET `mg` = "..rest.." WHERE `login` = '"..player:GetAccountName().."'; "); -- zero's out mg in db location | |
44 | player:SendBroadcastMessage("You have purchased "..amt.." custom Coins") -- informs player of amount recieved | |
45 | else | |
46 | player:SendAreaTriggerMessage("Your inventory is full") -- Adding the item failed. Do no changes to DB and send error msg. | |
47 | end | |
48 | end | |
49 | On_Gossip(pUnit,event,player) -- Back to "main" menu | |
50 | end | |
51 | ||
52 | RegisterUnitGossipEvent(npcid, 1, "On_Gossip") | |
53 | RegisterUnitGossipEvent(npcid, 2, "On_Select") |