• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore WotLK Buying item at vendor

mjafko

Epic Member
Hellou.

I got a question.

Well let's say I have a vendor with 3 items. If player wanna buy 1. item I wanna check with eluna if player got like 10 XY Point's, if do he can buy it.

And XY point's are basecly local XY = 100; on first login for example.

Greeting's Marko!
 

Rochet2

Moderator / Eluna Dev
Its not really possible to block buying.
You could try prevent the player from viewing the vendor.
 

bizzlesnaff

Emulation Addict
Just a gossip script with (for example) 3 options, where the player can choose one, get any item and the script take the points.
 

slp13at420

Mad Scientist
why not use custom currency?
then apply the custom currency to the vendor item.
Then you can have a script that uses and resets a 1d/2d table.
so when a player logs in it will check the table `DailyGift[player:GetGUIDLow()]` and if false then set the players inventory count of the custom currency to 100.
if `DailyGift[player:GetGUIDLow()]` is true then player was allready rewarded.

Every morning at oo:eek:ohrs the script could reset the table `DailyGift ={};` using a timer.
`reload eluna` or `reload server` will reset the table and allow players to take advantage of extra points . so maybe store the GetGameTime() to an SQl table every time the script resets the table at 00:00hrs.
 

Tommy

Founder
why not use custom currency?
then apply the custom currency to the vendor item.
Then you can have a script that uses and resets a 1d/2d table.
so when a player logs in it will check the table `DailyGift[player:GetGUIDLow()]` and if false then set the players inventory count of the custom currency to 100.
if `DailyGift[player:GetGUIDLow()]` is true then player was allready rewarded.

Every morning at oo:eek:ohrs the script could reset the table `DailyGift ={};` using a timer.
`reload eluna` or `reload server` will reset the table and allow players to take advantage of extra points . so maybe store the GetGameTime() to an SQl table every time the script resets the table at 00:00hrs.

Custom currency would require dbc edit whereas making a table and gathering data from it would not. Existing currency will work, but again you'd still have to save the time and if the player retrieve said points. BUT, I'd probably suggest using some type of currency in the long run, that way it will knock out most of the querying.

However, by "first login" you mean the FIRST time the player ever logged into that character or first login everyday on that character? Regardless I wrote a script and worked it around login everyday.

I'm not sure if this is the route you should go honestly, who knows. I don't normally tolerate querying like this. Below isn't tested, but it is basically the gist of what slp explained without the custom currency.

Code:
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)
 

slp13at420

Mad Scientist
yea your right you would need to store the value of received/not-received in the DB to cover a reload/restart.
I would just go 1/0 and then when the timer triggers just set all to 0, and store the current time.
once a player receives the gift then push the change '1' to the DB keyed by guid.
a new char first login would cause it to add the guid.

lol yea I meant any login.
 

Tommy

Founder
yea your right you would need to store the value of received/not-received in the DB to cover a reload/restart.
I would just go 1/0 and then when the timer triggers just set all to 0, and store the current time.
once a player receives the gift then push the change '1' to the DB keyed by guid.

It's better the way I wrote it. If not added to the table, add the character + points and store os.time. Afterwards when they login in the next 24h or greater they will receive the points again by comparing saved os.time to os.time + 86400 (24h).

lol yea I meant any login.

Was talking about @OP's post.

And XY point's are basecly local XY = 100; on first login for example.
 

slp13at420

Mad Scientist
Was talking about @OP's post.

lol in the immortal words of Towelieee "I'm sorry, i'm high" lol

tbh I was thinking more of a singe reset time for all players , just so they know when it happens , but with your way using individual reset times you could actually compensate for more than 1 day from last time stored. i.e. the player doesn't login for couple days, yea that would be easy math.floor(current time - stored time / day)..
 

Tommy

Founder
lol in the immortal words of Towelieee "I'm sorry, i'm high" lol

tbh I was thinking more of a singe reset time for all players , just so they know when it happens , but with your way using individual reset times you could actually compensate for more than 1 day from last time stored. i.e. the player doesn't login for couple days, yea that would be easy math.floor(current time - stored time / day)..

Would be a waste if people aren't actually logging in to get the points. You don't want people to make characters and farm the points, you'd rather have them actually login to the server. It is incentive to get players to play on your server and a way to earn the points.
 
Top