• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Codigo] GLOBALEVENTS SHOP.LUA

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1default [Codigo] GLOBALEVENTS SHOP.LUA el Sáb Abr 25, 2020 9:28 pm

    damatio

    damatio
    Nuevo Miembro
    Nuevo Miembro
    Descripcion escribió:TFS 1.3 OT 8.6

    ayúdame a hacer que el artículo llegue al buzón de correo electrónico amablemente
    ¡desde ya gracias!

    ID MAIL BOX
    You see your inbox (Vol:30).
    Item ID: 14404







    Código:
    -- ### CONFIG ###
    -- message to player "type", if delivery of item debugs client, it can be because of undefinied type (type that does not exist in your server LUA)
    SHOP_MSG_TYPE = MESSAGE_EVENT_ADVANCE
    -- ### END OF CONFIG ###

    function onThink(interval)
     local resultId = db.storeQuery("SELECT * FROM z_ots_comunication")
     if resultId ~= false then
     repeat
     local transactionId = tonumber(result.getDataInt(resultId, "id"))
     local player = Player(result.getDataString(resultId, "name"))

     if player then
     local itemId = result.getDataInt(resultId, "param1")
     local itemCount = result.getDataInt(resultId, "param2")
     local containerId = result.getDataInt(resultId, "param3")
     local containerItemsInsideCount = result.getDataInt(resultId, "param4")
     local shopOfferType = result.getDataString(resultId, "param5")
     local shopOfferName = result.getDataString(resultId, "param6")

    -- DELIVER ITEM
     if shopOfferType == 'item' then
     local newItemUID = doCreateItemEx(itemId, itemCount)
     --  item does not exist, wrong id OR count
     if not newItemUID then
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
     return true
     end
     -- change item UniqueID to object of class Item
     local newItem = Item(newItemUID)

     -- get player store inbox as container, so we can add item to it
     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
     -- cannot open Store Inbox, report problem
     if not playerStoreInbox then
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot open player "Store Inbox" - it is not supported in your server OR variable "CONST_SLOT_STORE_INBOX" is not definied in LUA')
     return true
     end
     -- add container with items to Store Inbox
     receivedItemStatus = playerStoreInbox:addItemEx(newItem)

     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
     player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
     db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
     db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
     else
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot add item to STORE INBOX - unknown reason, is it\'s size limited and it is full? - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
     end

    -- DELIVER CONTAINER
     elseif shopOfferType == 'container' then
     -- create empty container
     local newContainerUID = doCreateItemEx(containerId, 1)
     -- container item does not exist OR item is not Container
     if not newContainerUID or not Container(newContainerUID) then
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create container - invalid container ID - CONTAINER ID:' .. containerId)
     return true
     end
     -- change container UniqueID to object of class Container
     local newContainer = Container(newContainerUID)

     -- add items to container
     for i = 1, containerItemsInsideCount do
     -- create new item
     local newItemUID = doCreateItemEx(itemId, itemCount)
     --  item does not exist, wrong id OR count
     if not newItemUID then
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
     return true
     end
     -- change item UniqueID to object of class Item
     local newItem = Item(newItemUID)

     -- add item to container
     local addItemToContainerResult = newContainer:addItemEx(newItem)
     -- report error if it's not possible to add item to container
     if type(addItemToContainerResult) ~= "number" or addItemToContainerResult ~= RETURNVALUE_NOERROR then
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot add item to container - item is not pickable OR variable "RETURNVALUE_NOERROR" is not definied in LUA - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
     return true
     end
     end

     -- get player store inbox as container, so we can add item to it
     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
     -- cannot open Store Inbox, report problem
     if not playerStoreInbox then
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot open player "Store Inbox" - it is not supported in your server OR variable "CONST_SLOT_STORE_INBOX" is not definied in LUA')
     return true
     end
     -- add container with items to Store Inbox
     receivedItemStatus = playerStoreInbox:addItemEx(newContainer)

     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
     player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
     db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
     db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
     else
     player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
     print('ERROR! Website Shop (' .. player:getName() .. ') - cannot add container with items to STORE INBOX - unknown reason, is it\'s size limited and it is full? - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount .. ', CONTAINER ID:' .. containerId .. ', ITEMS IN CONTAINER COUNT:' .. containerItemsInsideCount)
     end

    -- DELIVER YOUR CUSTOM THINGS
     elseif shopOfferType == 'mount' then -- addon, mount etc.
     player:addMount(itemId)
     player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
     player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop.')
     db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
     db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)

     elseif shopOfferType == 'addon' then
     player:addOutfit(itemId)
     player:addOutfitAddon(itemId, 3)
     player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
     player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop.')
     db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
     db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
     end
     end
     until not result.next(resultId)
     result.free(resultId)
     end

     return true
    end
    Código:

    [quote="Captura del Error"][b]Imagen del error:[/b] [img]https://2img.net/i/fa/empty.gif[/img]
    [b]El error radica en:[/b] GlobalEvents

    2default Re: [Codigo] GLOBALEVENTS SHOP.LUA el Sáb Abr 25, 2020 11:07 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    use esta que le llega al player
    Código:



    -- ### CONFIG ###
    -- message send to player by script "type" (types you can check in "global.lua")
    SHOP_MSG_TYPE = 36
    -- ### END OF CONFIG ###
    function onThink(interval)
        local deliveryInterval = interval / 1000
        local resultId = db.storeQuery("SELECT * FROM z_ots_comunication")
        if(resultId) then
            repeat
                local id = result.getNumber(resultId, "id")
                local player = Player(result.getString(resultId, "name"))
                if(player) then
                    local addItemType = result.getString(resultId, "param5")

                    if(addItemType == 'item' or addItemType == 'container') then
                        local itemId = result.getNumber(resultId, "param1")
                        local itemCount = result.getNumber(resultId, "param2")
                        local containerId = result.getNumber(resultId, "param3")
                        local containerCount = result.getNumber(resultId, "param4")
                        local addItemName = result.getString(resultId, "param6")

                        local itemReceivedStatus = 0
                        local itemItemType = ItemType(itemId)
                        local containerItemType = ItemType(containerId)
                        local itemsWeight = 0
                        if(itemItemType:isRune() or itemItemType:isFluidContainer() or itemItemType:getCharges() > 0) then
                            itemsWeight = itemItemType:getWeight(1)
                        else
                            itemsWeight = itemItemType:getWeight(itemCount)
                        end
                        if(addItemType == 'container') then
                            itemsWeight = itemsWeight * containerCount + containerItemType:getWeight(1)
                        end
                        local freeCapacity = player:getFreeCapacity()
                        if(itemsWeight <= freeCapacity) then
                            local itemForPlayer = 0
                            if(addItemType == 'container') then
                                itemForPlayer = Container(doCreateItemEx(containerId, 1))
                                itemForPlayer:setAttribute("description", containerItemType:getDescription() .. "\nBought by " .. player:getName() .. ".")
                                local innerContainerItem = 0
                                for i = 1, containerCount do
                                    innerContainerItem = Item(doCreateItemEx(itemId, itemCount))
                                    if(not itemItemType:isRune() and not itemItemType:isFluidContainer() and not itemItemType:isStackable()) then
                                        innerContainerItem:setAttribute("description", itemItemType:getDescription() .. "\nBought by " .. player:getName() .. ".")
                                    end
                                    itemForPlayer:addItemEx(innerContainerItem)
                                end
                            else
                                itemForPlayer = Item(doCreateItemEx(itemId, itemCount))
                                if(not itemItemType:isRune() and not itemItemType:isFluidContainer() and not itemItemType:isStackable()) then
                                    itemForPlayer:setAttribute("description", itemItemType:getDescription() .. "\nBought by " .. player:getName() .. ".")
                                end
                            end
                            itemReceivedStatus = player:addItemEx(itemForPlayer, false)
                            if(type(itemReceivedStatus) == "number" and itemReceivedStatus == 0) then
                                player:sendTextMessage(SHOP_MSG_TYPE, 'You received >> '.. addItemName ..' << from OTS shop.')
                                db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                                db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                            else
                                player:sendTextMessage(SHOP_MSG_TYPE, '>> '.. addItemName ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. deliveryInterval ..' seconds to get it.')
                            end
                        else
                            player:sendTextMessage(SHOP_MSG_TYPE, '>> '.. addItemName ..' << from OTS shop is waiting for you. It weight is '.. (itemsWeight / 100) ..' oz., you have only '.. (freeCapacity / 100) ..' oz. free capacity. Put some items in depot and wait about '.. deliveryInterval ..' seconds to get it.')
                        end
                    elseif(addItemType == 'addon') then
                        local outfitOneId = result.getNumber(resultId, "param1")
                        local outfitOneAddon = result.getNumber(resultId, "param2")
                        local outfitTwoId = result.getNumber(resultId, "param3")
                        local outfitTwoAddon = result.getNumber(resultId, "param4")
                        local outfitName = result.getString(resultId, "param6")
                    end
                end
            until not result.next(resultId)
            result.free(resultId)
        end
        return true
    end



    [Codigo] GLOBALEVENTS  SHOP.LUA YNU5B25
    https://www.tibiaface.com

    3default Re: [Codigo] GLOBALEVENTS SHOP.LUA el Sáb Abr 25, 2020 11:46 pm

    damatio

    damatio
    Nuevo Miembro
    Nuevo Miembro
    [Codigo] GLOBALEVENTS  SHOP.LUA Addon10
    [Codigo] GLOBALEVENTS  SHOP.LUA Addons10
    [Codigo] GLOBALEVENTS  SHOP.LUA Error10





    al recibir el artículo, esto aparece en la distribución y pronto le da dbug al cliente


    [Error - DBResultNumber] Column 'param3' has an invalid value set: bad lexical cast: source type value could not be interpreted as target
    [Error - DBResultNumber] Column 'param4' has an invalid value set: bad lexical cast: source type value could not be interpreted as target


    e no estoy obteniendo el traje de gesior Sad

    [/quote]

    4default Re: [Codigo] GLOBALEVENTS SHOP.LUA el Dom Abr 26, 2020 12:40 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    borre de su estructura de su base de datos z_ots_comunication

    y ejecute esta nueva

    Código:

    CREATE TABLE IF NOT EXISTS `z_ots_comunication` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(255) NOT NULL,
    `type` varchar(255) NOT NULL,
    `action` varchar(255) NOT NULL,
    `param1` varchar(255) NOT NULL,
    `param2` varchar(255) NOT NULL,
    `param3` varchar(255) NOT NULL,
    `param4` varchar(255) NOT NULL,
    `param5` varchar(255) NOT NULL,
    `param6` varchar(255) NOT NULL,
    `param7` varchar(255) NOT NULL,
    `delete_it` int(2) NOT NULL DEFAULT '1',
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=230 ;



    [Codigo] GLOBALEVENTS  SHOP.LUA YNU5B25
    https://www.tibiaface.com

    5default Re: [Codigo] GLOBALEVENTS SHOP.LUA el Dom Abr 26, 2020 12:59 am

    damatio

    damatio
    Nuevo Miembro
    Nuevo Miembro
    el error ya no ocurre, pero el outfiit no llega: '(

    6default Re: [Codigo] GLOBALEVENTS SHOP.LUA el Dom Abr 26, 2020 3:40 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    [Tienes que estar registrado y conectado para ver este vínculo] escribió:el error ya no ocurre, pero el outfiit no llega: '(

    amigo beto a saber de que outfit me hablas si de la shop lo siento no se que sistema estara usando para vender outfit doy como tema soluciona

    Tema solucionado



    [Codigo] GLOBALEVENTS  SHOP.LUA YNU5B25
    https://www.tibiaface.com

    Contenido patrocinado


    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).