• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua I am not able to query the database

MorganaSacani

Active Member
Joined
Sep 20, 2022
Messages
87
Solutions
1
Reaction score
32
I have a problem with my script
Whenever I use the !shop command, the result of my Tibia Coins increases.
I don't understand. Maybe some problem getting the value from the database?
For example, when I use the !shop command, trim the value 15 the first time, if I use the command again, 17 appears, and so on.
The script is not returning me the actual value in the database.

Lua:
local shop = TalkAction("!shop")

function shop.onSay(player, words, param)
    player:registerEvent("ModalShop")
    local getCoins = db.storeQuery("SELECT `coins` FROM `accounts` WHERE `id` = " .. player:getAccountId())
    
    local title = "Game Store"
    local message = "You have ".. getCoins .." Tibia Coins."
 
    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")
 
    window:addChoice(1, "Premium Scroll - Price: ".. premiumScrollPrice ..".")
    window:addChoice(2, "Magic Gold Converter - Price: ".. magicGoldConverterPrice ..".")
 
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
 
    window:sendToPlayer(player)
    return true
end

shop:register()
 
Check how this script gets the value from the DB
 
Lua:
local shop = TalkAction("!shop")

function shop.onSay(player, words, param)
    player:registerEvent("ModalShop")
    
    local resultId = db.storeQuery("SELECT `coins` FROM `accounts` WHERE `id` = " .. player:getAccountId())
    if not resultId then
       result.free(resultId)
       return true
    end
    
    
    local getCoins = result.getNumber(resultId, "coins")
    result.free(resultId)
    
    local title = "Game Store"
    local message = "You have ".. getCoins .." Tibia Coins."
 
    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")
 
    window:addChoice(1, "Premium Scroll - Price: ".. premiumScrollPrice ..".")
    window:addChoice(2, "Magic Gold Converter - Price: ".. magicGoldConverterPrice ..".")
 
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
 
    window:sendToPlayer(player)
    return true
end

shop:register()
 
Back
Top