Znote / ZnoteAAC

Developement repository for the Znote AAC project. A website portal to represent and manage your Open Tibia server.
MIT License
145 stars 127 forks source link

Issue with globalevents (mounts) shopsystem #452

Open Fiimpz opened 3 years ago

Fiimpz commented 3 years ago

Hello!

Im getting this error

Lua Script Error: [GlobalEvent Interface] data/globalevents/scripts/znoteshop.lua:onThink data/globalevents/scripts/znoteshop.lua:6: attempt to call field 'getClientVersion' (a nil value) stack traceback: [C]: in function 'getClientVersion' data/globalevents/scripts/znoteshop.lua:6: in function <data/globalevents/scripts/znoteshop.lua:3> [Error - GlobalEvents::think] Failed to execute event: Znote Shop

I've tried ot change getclientversion to 870, 770,980 and everything but nothing happens. Also Im getting when I order stuffs that player with ID [34] is not online, but im online.

Thanks in advance.

Znote commented 3 years ago

Which server, version and client do you use?

Fiimpz commented 3 years ago

Nostalrius, 7.7 client

Znote commented 3 years ago

Try this, let me know if it works:

-- <globalevent name="Znote Shop" interval="30000" script="znoteshop.lua"/>
-- Znote Auto Shop v2.1 for Znote AAC on TFS 1.2+
function onThink(interval, lastExecution)
    local shopTypes = {1,7}
    local orderQuery = db.storeQuery([[
        SELECT
            MIN(`p`.`name`) AS `player_name`,
            `shop`.`id`,
            `shop`.`type`,
            `shop`.`itemid`,
            `shop`.`count`
        FROM `players_online` AS `po`
        INNER JOIN `players` AS `p`
            ON `po`.`player_id` = `p`.`id`
        INNER JOIN `znote_shop_orders` AS `shop`
            ON `p`.`account_id` = `shop`.`account_id`
        WHERE `shop`.`type` IN(]] .. table.concat(shopTypes, ",") .. [[)
        GROUP BY `shop`.`id`
    ]])
    -- Detect if we got any results
    if orderQuery ~= false then
        local type_desc = {
            "itemids",
            "pending premium (skip)",
            "pending gender change (skip)",
            "pending character name change (skip)",
            "Outfit and addons (skip)",
            "Mounts (skip)",
            "Instant house purchase"
        }
        repeat
            local player_name = result.getNumber(orderQuery, 'player_name')
            local orderId = result.getNumber(orderQuery, 'id')
            local orderType = result.getNumber(orderQuery, 'type')
            local orderItemId = result.getNumber(orderQuery, 'itemid')
            local orderCount = result.getNumber(orderQuery, 'count')
            local served = false

            local player = Player(player_name)
            if player ~= nil then

                local description = "Unknown or custom type"
                if type_desc[orderType] ~= nil then
                    description = type_desc[orderType]
                end
                print("Processing type "..orderType..": ".. description)
                print("Processing shop order for: [".. player:getName() .."] type "..orderType..": ".. description)

                local tile = Tile(player:getPosition())
                if tile ~= nil and tile:hasFlag(TILESTATE_PROTECTIONZONE) then

                    -- ORDER TYPE 1 (Regular item shop products)
                    if orderType == 1 then
                        served = true
                        local itemType = ItemType(orderItemId)
                        -- Get weight
                        if player:getFreeCapacity() >= itemType:getWeight(orderCount) then
                            local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
                            -- variable = (condition) and (return if true) or (return if false)
                            local needslots = itemType:isStackable() and math.floor(orderCount / 100) + 1 or orderCount
                            if backpack ~= nil and backpack:getEmptySlots(false) >= needslots then
                                db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. orderId .. ";")
                                player:addItem(orderItemId, orderCount)
                                player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. "!")
                                print("Process complete. [".. player:getName() .."] has received " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
                            else -- not enough slots
                                player:sendTextMessage(MESSAGE_STATUS_WARNING, "Your main backpack is full. You need to free up "..needslots.." available slots to get " .. orderCount .. " " .. ItemType(orderItemId):getName() .. "!")
                                print("Process canceled. [".. player:getName() .."] need more space in his backpack to get " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
                            end
                        else -- not enough cap
                            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You need more CAP to carry this order!")
                            print("Process canceled. [".. player:getName() .."] need more cap to carry " .. orderCount .. "x " .. ItemType(orderItemId):getName() .. ".")
                        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().."]")
                            else
                                print("Process canceled. Failed to load house with ID: "..orderItemId)
                            end
                        else
                            print("Process canceled. Failed to load player with ID: "..orderCount)
                        end
                    end

                    if not served then -- If this order hasn't been processed yet (missing type handling?)
                        print("Znote shop: Type ["..orderType.."] not properly processed. Missing Lua code?")
                    end
                else -- Not in protection zone
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have a pending shop order, please enter protection zone.')
                    print("Skipped one shop order. Reason: Player: [".. player:getName() .."] is not inside protection zone.")
                end
            else -- player not logged in
                print("Skipped one shop order. Reason: Player with name [".. player_name .."] is not online.")
            end

        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end

I don't think nostalrius supports addons and mounts so removed those options. I don't think nostalrius supports player initialization by player id, so replaced it with player name.

Fiimpz commented 3 years ago

Got this error after copy your new script:

Lua Script Error: [GlobalEvent Interface] data/globalevents/scripts/znoteShop.lua:onThink data/globalevents/scripts/znoteShop.lua:106: attempt to concatenate global 'player_id' (a nil value) stack traceback: [C]: in function '__concat' data/globalevents/scripts/znoteShop.lua:106: in function <data/globalevents/scripts/znoteShop.lua:3> [Error - GlobalEvents::think] Failed to execute event: Znote Shop

Also I have implented mounts/addons to nostalrius so it does support.

Znote commented 3 years ago

Got this error after copy your new script:

Lua Script Error: [GlobalEvent Interface] data/globalevents/scripts/znoteShop.lua:onThink data/globalevents/scripts/znoteShop.lua:106: attempt to concatenate global 'player_id' (a nil value) stack traceback: [C]: in function '__concat' data/globalevents/scripts/znoteShop.lua:106: in function <data/globalevents/scripts/znoteShop.lua:3> [Error - GlobalEvents::think] Failed to execute event: Znote Shop

Also I have implented mounts/addons to nostalrius so it does support.

Updated the script

Fiimpz commented 3 years ago

image

This was the next error Also, plesae activate mount/outfits/addon since ive them on the server Thanks!

Fiimpz commented 3 years ago

Seen any issues on this? :P