pError en comando !shop, problema de Script.lua

J

jeswilldbm

Invited
Hola buenas, estoy presentando un problema con el siguiente script:

Estuve probando el script y funciona muy bien, se sincroniza con lo que se compra en la pagina y todo bien, solo tengo un inconveniente.
que cuando digo el comando !shop y no he comprado nada, me arroja un error en la consola.

me gustaría saber como o que se tendría que modificar en el script para que el comando no arroje ese error en consola cuando un jugador que no ha comprado lo ejecute.

Estoy usando la versión del servidor canary como base, pero actualizado a la versión 13.10.
lo compile en windows y estoy usando Uniserver.

https://github.com/opentibiabr/canary

El codigo utilizado es el siguiente:

JavaScript:
local znoteShop = TalkAction ("!Shop")
function znoteShop.onSay(cid, words, param)
    local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
    local cooldown = 15 -- in seconds.
    local player = Player(cid)
    if player:getStorageValue(storage) <= os.time() then
        player:setStorageValue(storage, os.time() + cooldown)
        local type_desc = {
            "itemids",
            "pending premium (skip)",
            "pending gender change (skip)",
            "pending character name change (skip)",
            "Outfit and addons",
            "Mounts",
            "Instant house purchase"
        }
        print("Player: " .. player:getName() .. " triggered !shop talkaction.")
        -- Create the query
        local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. player:getAccountId() .. ";")
        orderQuery = orderQuery and true or false
        local served = false
        -- Detect if we got any results
        if orderQuery ~= false then
            repeat
                -- Fetch order values
                local q_id = result.getNumber(orderQuery, "id")
                local q_type = result.getNumber(orderQuery, "type")
                local q_itemid = result.getNumber(orderQuery, "itemid")
                local q_count = result.getNumber(orderQuery, "count")
                local description = "Unknown or custom type"
                if type_desc[q_type] ~= nil then
                    description = type_desc[q_type]
                end
                print("Processing type "..q_type..": ".. description)
                -- ORDER TYPE 1 (Regular item shop products)
                if q_type == 1 then
                    served = true
                    -- Get weight
                    if player:getFreeCapacity() >= ItemType(q_itemid):getWeight(q_count) then
                        db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
                        player:addItem(q_itemid, q_count)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. q_count .. " x " .. ItemType(q_itemid):getName() .. "!")
                    else
                        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Need more CAP!")
                    end
                end
                -- ORDER TYPE 5 (Outfit and addon)
                if q_type == 5 then
                    served = true
                    local itemid = q_itemid
                    local outfits = {}
                    if itemid > 1000 then
                        local first = math.floor(itemid/1000)
                        table.insert(outfits, first)
                        itemid = itemid - (first * 1000)
                    end
                    table.insert(outfits, itemid)
                    for _, outfitId in pairs(outfits) do
                        -- Make sure player don't already have this outfit and addon
                        if not player:hasOutfit(outfitId, q_count) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
                            player:addOutfit(outfitId)
                            player:addOutfitAddon(outfitId, q_count)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
                        else
                            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
                        end
                    end
                end
                    -- ORDER TYPE 6 (Mounts)
                if q_type == 6 then
                    served = true
                        -- Make sure player don't already have this outfit and addon
                    if not player:hasMount(q_itemid) then
                        db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
                        player:addMount(q_itemid)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!")
                    else
                        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
                    end
                end
                -- ORDER TYPE 7 (Direct house purchase)
                if orderType == 7 then
                    served = true
                    local house = House(orderItemId)
                    -- Logged in player is not necessarily the player that bough the house. So we need to load player from db.
                    local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
                    if buyerQuery ~= false then
                        local buyerName = result.getString(buyerQuery, "name")
                        result.free(buyerQuery)
                        if house then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            house:setOwnerGuid(orderCount)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
                            print("Process complete. [".. buyerName .."] has received house: ["..house:getName().."]")
                        end
                    end
                end
                -- Add custom order types here
                -- Type 1 is for itemids (Already coded here)
                -- Type 2 is for premium (Coded on web)
                -- Type 3 is for gender change (Coded on web)
                -- Type 4 is for character name change (Coded on web)
                -- Type 5 is for character outfit and addon (Already coded here)
                -- Type 6 is for mounts (Already coded here)
                -- Type 7 is for Instant house purchase (Already coded here)
                -- So use type 8+ for custom stuff, like etc packages.
                -- if q_type == 8 then
                -- end
            until not result.next(orderQuery)
            result.free(orderQuery)
            if not served then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders.")
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(storage) - os.time())
    end
    return false
end
znoteShop:separator(" ")
znoteShop:register()


muchas gracias de antemano, estaré atento a nueva información.
 

Attachments

  • error consola.png
    error consola.png
    18.8 KB · Views: 2
Hola buenas, estoy presentando un problema con el siguiente script:

Estuve probando el script y funciona muy bien, se sincroniza con lo que se compra en la pagina y todo bien, solo tengo un inconveniente.
que cuando digo el comando !shop y no he comprado nada, me arroja un error en la consola.

me gustaría saber como o que se tendría que modificar en el script para que el comando no arroje ese error en consola cuando un jugador que no ha comprado lo ejecute.

Estoy usando la versión del servidor canary como base, pero actualizado a la versión 13.10.
lo compile en windows y estoy usando Uniserver.

https://github.com/opentibiabr/canary

El codigo utilizado es el siguiente:

JavaScript:
local znoteShop = TalkAction ("!Shop")
function znoteShop.onSay(cid, words, param)
    local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks.
    local cooldown = 15 -- in seconds.
    local player = Player(cid)
    if player:getStorageValue(storage) <= os.time() then
        player:setStorageValue(storage, os.time() + cooldown)
        local type_desc = {
            "itemids",
            "pending premium (skip)",
            "pending gender change (skip)",
            "pending character name change (skip)",
            "Outfit and addons",
            "Mounts",
            "Instant house purchase"
        }
        print("Player: " .. player:getName() .. " triggered !shop talkaction.")
        -- Create the query
        local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. player:getAccountId() .. ";")
        orderQuery = orderQuery and true or false
        local served = false
        -- Detect if we got any results
        if orderQuery ~= false then
            repeat
                -- Fetch order values
                local q_id = result.getNumber(orderQuery, "id")
                local q_type = result.getNumber(orderQuery, "type")
                local q_itemid = result.getNumber(orderQuery, "itemid")
                local q_count = result.getNumber(orderQuery, "count")
                local description = "Unknown or custom type"
                if type_desc[q_type] ~= nil then
                    description = type_desc[q_type]
                end
                print("Processing type "..q_type..": ".. description)
                -- ORDER TYPE 1 (Regular item shop products)
                if q_type == 1 then
                    served = true
                    -- Get weight
                    if player:getFreeCapacity() >= ItemType(q_itemid):getWeight(q_count) then
                        db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
                        player:addItem(q_itemid, q_count)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. q_count .. " x " .. ItemType(q_itemid):getName() .. "!")
                    else
                        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Need more CAP!")
                    end
                end
                -- ORDER TYPE 5 (Outfit and addon)
                if q_type == 5 then
                    served = true
                    local itemid = q_itemid
                    local outfits = {}
                    if itemid > 1000 then
                        local first = math.floor(itemid/1000)
                        table.insert(outfits, first)
                        itemid = itemid - (first * 1000)
                    end
                    table.insert(outfits, itemid)
                    for _, outfitId in pairs(outfits) do
                        -- Make sure player don't already have this outfit and addon
                        if not player:hasOutfit(outfitId, q_count) then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
                            player:addOutfit(outfitId)
                            player:addOutfitAddon(outfitId, q_count)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new outfit!")
                        else
                            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this outfit and addon!")
                        end
                    end
                end
                    -- ORDER TYPE 6 (Mounts)
                if q_type == 6 then
                    served = true
                        -- Make sure player don't already have this outfit and addon
                    if not player:hasMount(q_itemid) then
                        db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";")
                        player:addMount(q_itemid)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received a new mount!")
                    else
                        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have this mount!")
                    end
                end
                -- ORDER TYPE 7 (Direct house purchase)
                if orderType == 7 then
                    served = true
                    local house = House(orderItemId)
                    -- Logged in player is not necessarily the player that bough the house. So we need to load player from db.
                    local buyerQuery = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = "..orderCount.." LIMIT 1")
                    if buyerQuery ~= false then
                        local buyerName = result.getString(buyerQuery, "name")
                        result.free(buyerQuery)
                        if house then
                            db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                            house:setOwnerGuid(orderCount)
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have successfully bought the house "..house:getName().." on "..buyerName..", be sure to have the money for the rent in the bank.")
                            print("Process complete. [".. buyerName .."] has received house: ["..house:getName().."]")
                        end
                    end
                end
                -- Add custom order types here
                -- Type 1 is for itemids (Already coded here)
                -- Type 2 is for premium (Coded on web)
                -- Type 3 is for gender change (Coded on web)
                -- Type 4 is for character name change (Coded on web)
                -- Type 5 is for character outfit and addon (Already coded here)
                -- Type 6 is for mounts (Already coded here)
                -- Type 7 is for Instant house purchase (Already coded here)
                -- So use type 8+ for custom stuff, like etc packages.
                -- if q_type == 8 then
                -- end
            until not result.next(orderQuery)
            result.free(orderQuery)
            if not served then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders to process in-game.")
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have no orders.")
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(storage) - os.time())
    end
    return false
end
znoteShop:separator(" ")
znoteShop:register()


muchas gracias de antemano, estaré atento a nueva información.

Claro, para 13x, no sabria decirte.
Algo del código no es para esa versión, y aquí creo que algunos scripts ya no servirán para esa versión, alguna parte es distinto.

Funcionar funciona a la hora de comprar un item, si alguien lo escribe sin haber comprado mostrará un error.

Hay un método barbaro para quitarlo, pero no se si puede interferir con otra cosa, sale un mensaje dicho Message Type is wrong... en rojo en el juego.
Este mensaje se encuentra en protocolgame.cpp:

JavaScript:
 {
    if (message.type == MESSAGE_NONE) {
        SPDLOG_ERROR("[ProtocolGame::sendTextMessage] - Message type is wrong, missing or invalid for player with name {}, on position {}", player->getName(), player->getPosition().toString());
        player->sendTextMessage(MESSAGE_ADMINISTRADOR, "There was a problem requesting your message, please contact the administrator");
        return;
    }

Se borra la parte de SPDLOG_ERROR y player->sendTextMessage, lo demas se deja y se compila, evita dar ese error en la consola, si el cierto miedo es que usen o spameen el comando para caer la consola, que no pienso que caiga.
Pero hay que verificar con Znote si en 13 algo cambio.
 

Tibia Server Lists

#1 FEATURED US Ultron OT 1,495 / 5,000Online EXPStages PROTO8.6 ENGINEUltron OT RANK PTS5.9 +100% VOTES0 #2 FEATURED US Nefera 165 / 0Online EXPx1 PROTO15.20 ENGINECrystal Server RANK PTS5.1 +100% VOTES0 #3 FEATURED ES Deixis 1 / 0Online EXPStages PROTO1098 ENGINETFS RANK PTS3.7 +100% VOTES1 #4 FEATURED ES Maeli 10 / 150Online EXPx10 PROTO10.98 ENGINETFS 1.4.2 RANK PTS3.7 +100% VOTES0 #5 MX Marlboro War 30 / 300Online EXP999 PROTO8.6 ENGINETFS 0.3.7 RANK PTS5.5 -33% VOTES0 #6 BR Tibinha YurOts 18 / 150Online EXPStages PROTO7.4 ENGINEYurOTS 1.5 RANK PTS5.2 -14% VOTES0 #7 US Halera 3 / 0Online EXPStages PROTO10.98 ENGINETFS 1.4.2 RANK PTS4.9 -83% VOTES0 #8 BR Exordion Legacy 52 / 2,000Online EXPx2 PROTO7.72 ENGINEExordion RANK PTS4.9 +100% VOTES0 #9 PL Lubelski 6 / 1,000Online EXP200 PROTO7.6 ENGINELubelskiOTS 2.56.0 RANK PTS4.6 -15% VOTES0 #10 DE DBU Online 0 / 400Online EXP11 PROTO8.6 ENGINETFS 1.0 RANK PTS4.3 +100% VOTES0 #11 PL ReWar 0 / 2,000Online EXPcustom PROTO8.6 ENGINEOther RANK PTS4.3 0% VOTES0 #12 PL Velesta 0 / 1,000Offline EXP20 PROTO8.0 ENGINETFS 1.4.2 RANK PTS4.3 -99% VOTES0 #13 ES JustRL FreeTC 1530 22 / 250Online EXPx2 PROTO15.30 ENGINECrystal Server RANK PTS4.3 +100% VOTES0 #14 ES Farlia Global 2026 0 / 333Offline EXPx5 PROTO15.25 ENGINEFarliaServ 1.525 RANK PTS3.9 -22% VOTES0 #15 SE MortalisOT Custom 0 / 500Offline EXP100x -1.2x PROTO10.98 ENGINEMortalisOT V1 RANK PTS3.8 +100% VOTES0 #16 US Rommania 0 / 500Online EXPstages, x10 PROTO7.4 ENGINETFS 0.4 RANK PTS3.6 +100% VOTES0 #17 US BerethaOnline 1 / 2,000Online EXPStages PROTO10.98 ENGINETFS RANK PTS3.5 +100% VOTES0
Top