• 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 3.3.5 Need some help with sql querys in eluna

lovekilz

Emulation Addict
Hello, i need some help using sql queryes in eluna.
Let's say i want to get a value from account table in database (coins)
In basic sql i do Select * coins from account.account where id = $accountid
How do i do that in eluna and return the value via gossip ?
Need help also with update/substract querys, i want to make a donor npc.
Thanks.
 

Rochet2

Moderator / Eluna Dev

lovekilz

Emulation Addict
Tyvm rochet for the help but i still recieve the error :
View attachment 615
Script
local function OnGossipHello(event, player, object)
player:GossipClearMenu()
player:GossipMenuAddItem(0, "Check my coins", 1, 1)
player:GossipSendMenu(1, object, MenuId) -- MenuId required for player gossip
end

local function OnGossipSelect(event, player, object, sender, intid, code, menuid)
if (intid == 1) then
local q = AuthDBQuery("Select coins from account where id = "..Player:GetAccountId().."")
if q then -- check if query returned something
local coins = q:GetUInt32(0) -- get the value of first column (column index 0)
end
player:SendAreaTriggerMessage("You got "..coins.." gold coins")
player:GossipComplete()
end
end
RegisterCreatureGossipEvent(190030, 1, OnGossipHello)
RegisterCreatureGossipEvent(190030, 2, OnGossipSelect)
 

Rochet2

Moderator / Eluna Dev
cannot see the error. image is nonexistant

btw this is wrong Player:GetAccountId
you should be using player, not Player
 

lovekilz

Emulation Addict
it was bad self argument.

i did it like this and it works :
local function OnGossipSelect(event, player, object, sender, intid, code, menuid)
if (intid == 1) then
local q = AuthDBQuery("Select coins from auth.account where id = "..player:GetAccountId().."")
local coins = q:GetUInt32(0) -- get the value of first column (column index 0)
player:SendAreaTriggerMessage("You got "..coins.." gold coins")
player:GossipComplete()
end
end
 

lovekilz

Emulation Addict
One more thing so i dont open a new thread.
I want to use tables like this :
Items =
{
-- item , cost
{{57006, 15},
{57006, 5}},
}
Can you point me how i can extract the items from the tables and show them ?
Like in addmenuitem show the ItemID and put the value in a local variable ? Tyvm.

Or maybe show me an example script of table usage where it uses them the same way im trying to.
 

lovekilz

Emulation Addict
Sorry for double post.
Im stuck here :

local Donor = {
Items = {
-- {ItemEntry, Cost},
{58024, 4},
{30611, 4},
{30612, 5},
};
};

local function OnGossipHello(event, player, object)
local q = AuthDBQuery("Select coins from auth.account where id = "..player:GetAccountId().."")
local coins = q:GetUInt32(0)
player:GossipClearMenu()
for i = 1, #Donor.Items do
player:GossipMenuAddItem(0, ""..GetItemLink(Donor.Items[1]).." Gold:"..Donor.Items[2].."", 0, Donor.Items[1])
end
player:GossipSendMenu(1, object, MenuId) -- MenuId required for player gossip
player:SendAreaTriggerMessage("You got "..coins.." gold coins")
end

local function OnGossipSelect(event, player, object, sender, intid, code, menuid)
local q = AuthDBQuery("Select coins from auth.account where id = "..player:GetAccountId().."")
local coins = q:GetUInt32(0)
end
RegisterCreatureGossipEvent(190030, 1, OnGossipHello)
RegisterCreatureGossipEvent(190030, 2, OnGossipSelect)

dunno how to do on select to check item id and price from table, any help really apreciated it, Thanks
 

lovekilz

Emulation Addict
i did that earlier , figured out the tables , but now how do i send from hello option to the select menu so i know wich item the players selected and at what cost

local Items =
{
-- item , cost
{57006, 15},
{57006, 5},
}


local function OnGossipHello(event, player, object, item, cost)
local q = AuthDBQuery("Select coins from auth.account where id = "..player:GetAccountId().."")
local coins = q:GetUInt32(0)
player:GossipClearMenu()
for i = 1, #Items do
local item, cost = Items[1], Items[2]
player:GossipMenuAddItem(0, ""..GetItemLink(item).." Gold:"..cost.."", 0, item )
end
player:GossipSendMenu(1, object, MenuId)
--player:SendAreaTriggerMessage("You got "..coins.." gold coins")
end

local function OnGossipSelect(event, player, sender, intid, menuid, item, cost)

player:SendAreaTriggerMessage("You selected "..item)

end
RegisterCreatureGossipEvent(190030, 1, OnGossipHello)
RegisterCreatureGossipEvent(190030, 2, OnGossipSelect)
 

Cryhme187

New member
why not use direct access? That's whats used in my AutoLearnSkill script.
Code:
local ITEMS = {
  [57006]=5,
  [57007]=10,
  [57008]=15,
}

And that is how it is being accessed
Code:
function ITEMS.getItemCost(player, ItemID)
        
        if( ITEMS[ItemID] ~= nil ) then
          return ITEMS[ItemID]
        else
          return nil
        end
end

no iterating needed here but i did not test the above code.
 
Top