local Vendor = { }
function Vendor.Login(event, player)
local lowGuid = player:GetGUIDLow()
if (Vendor[lowGuid] == nil) then -- If not added yet, add them to the table..
CharDBExecute("INSERT INTO custom_vendor VALUES('"..lowGuid.."', '100', '"..os.time().."')")
else
if (Vendor[lowGuid].timesecs >= os.time() + 86400) -- If it is over 1 day give them more points
local p = Vendor[lowGuid].points + 100 -- New points + 100. Change 100 to whatever.
CharDBExecute("UPDATE custom_vendor SET timesecs='"..os.time().."' points='"..p.."' WHERE guid='"..lowGuid.."'")
Vendor[lowGuid].timesecs = os.time() -- Make sure we reset the time because we don't want it to keep spamming
end
end
end
function Vendor.OnHello(event, player, unit)
if (Vendor[player:GetGUIDLow()] == nil) then
return;
end
local p = Vendor[player:GetGUIDLow()].points
if (p >= 10) then
player:GossipMenuAddItem(0, "Item 1", 0, 1)
player:GossipMenuAddItem(0, "Item 2", 0, 2)
player:GossipMenuAddItem(0, "Item 3", 0, 3)
else
player:GossipMenuAddItem(0, "Not enough points to purchase these items.", 0, 0)
player:GossipMenuAddItem(0, "Leave.", 0, 0)
end
player:GossipSendMenu(1, unit)
end
function Vendor.OnSelect(event, player, unit, sender, intid, code)
local lowGuid = player:GetGUIDLow()
local p = Vendor[lowGuid].points
if (init == 0) then
player:GossipComplete()
elseif (init == 1) then
if (player:AddItem(1) ~= nil) then
CharDBExecute("UPDATE custom_vendor SET points='"..p.."' WHERE guid='"..lowGuid.."'")
end
elseif (init == 2) then
if (player:AddItem(1) ~= nil) then
CharDBExecute("UPDATE custom_vendor SET points='"..p.."' WHERE guid='"..lowGuid.."'")
end
elseif (init == 3) then
if (player:AddItem(1) ~= nil) then
CharDBExecute("UPDATE custom_vendor SET points='"..p.."' WHERE guid='"..lowGuid.."'")
end
end
end
function Vendor.WorldStart(event)
local query = CharDBQuery("SELECT * FROM custom_vendor")
if (query) then
repeat
-- Vendor[guid]
-- Vendor[guid].points
-- Vendor[guid].timesecs
Vendor[query:GetUInt32(0)] = {
points = query:GetUInt32(1)
timesecs = query:GetUInt32(2)
}
until not query:NextRow()
end
end
RegisterServerEvent(14, Vendor.WorldStart)
RegisterCreatureGossipEvent(12345, 1, Vendor.OnHello)
RegisterCreatureGossipEvent(12345, 2, Vendor.OnSelect)
RegisterPlayerEvent(3, Vendor.Login)