GlobalEvent Shop System delivery for TFS 1.1+ with Store Inbox

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Gesior.pl, Sep 3, 2016.

  1. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,841
    Likes Received:
    650
    Best Answers:
    2
    If you use one of TFS 1.1+ based engines that got Store Inbox, you can use new LUA script for delivery from website shop.
    New code delivers items and containers with items to Store Inbox of players.
    There is also full error reporting. If anything is wrong with shop offer on website or server config, it will show error with description in server console and send message to player about problem with item delivery.

    Code tested on 'OTX 3 10.97':
    Code (Text):
    1. -- ### CONFIG ###
    2. -- 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)
    3. SHOP_MSG_TYPE = MESSAGE_EVENT_ADVANCE
    4. -- ### END OF CONFIG ###
    5.  
    6. function onThink(interval)
    7.    local resultId = db.storeQuery("SELECT * FROM z_ots_comunication")
    8.     if resultId ~= false then
    9.         repeat
    10.             local transactionId = tonumber(result.getDataInt(resultId, "id"))
    11.             local player = Player(result.getDataString(resultId, "name"))
    12.  
    13.             if player then
    14.                 local itemId = result.getDataInt(resultId, "param1")
    15.                 local itemCount = result.getDataInt(resultId, "param2")
    16.                 local containerId = result.getDataInt(resultId, "param3")
    17.                 local containerItemsInsideCount = result.getDataInt(resultId, "param4")
    18.                 local shopOfferType = result.getDataString(resultId, "param5")
    19.                 local shopOfferName = result.getDataString(resultId, "param6")
    20.  
    21. -- DELIVER ITEM
    22.                 if shopOfferType == 'item' then
    23.                     local newItemUID = doCreateItemEx(itemId, itemCount)
    24.                     --  item does not exist, wrong id OR count
    25.                     if not newItemUID then
    26.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    27.                         print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
    28.                         return true
    29.                     end
    30.                     -- change item UniqueID to object of class Item
    31.                     local newItem = Item(newItemUID)
    32.  
    33.                     -- get player store inbox as container, so we can add item to it
    34.                     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    35.                     -- cannot open Store Inbox, report problem
    36.                     if not playerStoreInbox then
    37.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    38.                         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')
    39.                         return true
    40.                     end
    41.                     -- add container with items to Store Inbox
    42.                     receivedItemStatus = playerStoreInbox:addItemEx(newItem)
    43.  
    44.                     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
    45.                         player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
    46.                         db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    47.                         db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    48.                     else
    49.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    50.                         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)
    51.                     end
    52.  
    53. -- DELIVER CONTAINER
    54.                 elseif shopOfferType == 'container' then
    55.                     -- create empty container
    56.                     local newContainerUID = doCreateItemEx(containerId, 1)
    57.                     -- container item does not exist OR item is not Container
    58.                     if not newContainerUID or not Container(newContainerUID) then
    59.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    60.                         print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create container - invalid container ID - CONTAINER ID:' .. containerId)
    61.                         return true
    62.                     end
    63.                     -- change container UniqueID to object of class Container
    64.                     local newContainer = Container(newContainerUID)
    65.  
    66.                     -- add items to container
    67.                     for i = 1, containerItemsInsideCount do
    68.                         -- create new item
    69.                         local newItemUID = doCreateItemEx(itemId, itemCount)
    70.                         --  item does not exist, wrong id OR count
    71.                         if not newItemUID then
    72.                             player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    73.                             print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
    74.                             return true
    75.                         end
    76.                         -- change item UniqueID to object of class Item
    77.                         local newItem = Item(newItemUID)
    78.  
    79.                         -- add item to container
    80.                         local addItemToContainerResult = newContainer:addItemEx(newItem)
    81.                         -- report error if it's not possible to add item to container
    82.                         if type(addItemToContainerResult) ~= "number" or addItemToContainerResult ~= RETURNVALUE_NOERROR then
    83.                             player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    84.                             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)
    85.                             return true
    86.                         end
    87.                     end
    88.  
    89.                     -- get player store inbox as container, so we can add item to it
    90.                     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    91.                     -- cannot open Store Inbox, report problem
    92.                     if not playerStoreInbox then
    93.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    94.                         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')
    95.                         return true
    96.                     end
    97.                     -- add container with items to Store Inbox
    98.                     receivedItemStatus = playerStoreInbox:addItemEx(newContainer)
    99.  
    100.                     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
    101.                         player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
    102.                         db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    103.                         db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    104.                     else
    105.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    106.                         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)
    107.                     end
    108.  
    109. -- DELIVER YOUR CUSTOM THINGS
    110.                 elseif shopOfferType == 'mything' then -- addon, mount etc.
    111.                     -- HERE YOUR CODE
    112.                 end
    113.             end
    114.         until not result.next(resultId)
    115.         result.free(resultId)
    116.     end
    117.  
    118.     return true
    119. end
    120.  
    GIST:
    https://gist.github.com/gesior/10ce453d85d0f3f3eab00c039e5ca2e1

    It's written in pure LUA object-oriented programming (TFS 1.1+) and uses 'asyncQueries' to increase execution speed when it's possible, so you can use it as example of 'new code'.
     
    Last edited: Sep 3, 2016
    danio4don, Raggaer, MartyX and 4 others like this.
  2. Fencore Team

    Fencore Team Member

    Joined:
    Sep 2, 2016
    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    first one that tested on the server with gesior ^^ Brilliant System!
     
  3. malucooo

    malucooo Member

    Joined:
    Sep 5, 2007
    Messages:
    81
    Likes Received:
    20
    Best Answers:
    0
    i include mounts and Addons! enjoy it =]~

    Code (Text):
    1. -- ### CONFIG ###
    2. -- 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)
    3. SHOP_MSG_TYPE = MESSAGE_EVENT_ADVANCE
    4. -- ### END OF CONFIG ###
    5.  
    6. function onThink(interval)
    7.     local resultId = db.storeQuery("SELECT * FROM z_ots_comunication")
    8.     if resultId ~= false then
    9.         repeat
    10.             local transactionId = tonumber(result.getDataInt(resultId, "id"))
    11.             local player = Player(result.getDataString(resultId, "name"))
    12.  
    13.             if player then
    14.                 local itemId = result.getDataInt(resultId, "param1")
    15.                 local itemCount = result.getDataInt(resultId, "param2")
    16.                 local containerId = result.getDataInt(resultId, "param3")
    17.                 local containerItemsInsideCount = result.getDataInt(resultId, "param4")
    18.                 local shopOfferType = result.getDataString(resultId, "param5")
    19.                 local shopOfferName = result.getDataString(resultId, "param6")
    20.  
    21. -- DELIVER ITEM
    22.                 if shopOfferType == 'item' then
    23.                     local newItemUID = doCreateItemEx(itemId, itemCount)
    24.                     --  item does not exist, wrong id OR count
    25.                     if not newItemUID then
    26.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    27.                         print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
    28.                         return true
    29.                     end
    30.                     -- change item UniqueID to object of class Item
    31.                     local newItem = Item(newItemUID)
    32.  
    33.                     -- get player store inbox as container, so we can add item to it
    34.                     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    35.                     -- cannot open Store Inbox, report problem
    36.                     if not playerStoreInbox then
    37.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    38.                         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')
    39.                         return true
    40.                     end
    41.                     -- add container with items to Store Inbox
    42.                     receivedItemStatus = playerStoreInbox:addItemEx(newItem)
    43.  
    44.                     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
    45.                         player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
    46.                         db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    47.                         db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    48.                     else
    49.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    50.                         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)
    51.                     end
    52.  
    53. -- DELIVER CONTAINER
    54.                 elseif shopOfferType == 'container' then
    55.                     -- create empty container
    56.                     local newContainerUID = doCreateItemEx(containerId, 1)
    57.                     -- container item does not exist OR item is not Container
    58.                     if not newContainerUID or not Container(newContainerUID) then
    59.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    60.                         print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create container - invalid container ID - CONTAINER ID:' .. containerId)
    61.                         return true
    62.                     end
    63.                     -- change container UniqueID to object of class Container
    64.                     local newContainer = Container(newContainerUID)
    65.  
    66.                     -- add items to container
    67.                     for i = 1, containerItemsInsideCount do
    68.                         -- create new item
    69.                         local newItemUID = doCreateItemEx(itemId, itemCount)
    70.                         --  item does not exist, wrong id OR count
    71.                         if not newItemUID then
    72.                             player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    73.                             print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
    74.                             return true
    75.                         end
    76.                         -- change item UniqueID to object of class Item
    77.                         local newItem = Item(newItemUID)
    78.  
    79.                         -- add item to container
    80.                         local addItemToContainerResult = newContainer:addItemEx(newItem)
    81.                         -- report error if it's not possible to add item to container
    82.                         if type(addItemToContainerResult) ~= "number" or addItemToContainerResult ~= RETURNVALUE_NOERROR then
    83.                             player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    84.                             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)
    85.                             return true
    86.                         end
    87.                     end
    88.  
    89.                     -- get player store inbox as container, so we can add item to it
    90.                     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    91.                     -- cannot open Store Inbox, report problem
    92.                     if not playerStoreInbox then
    93.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    94.                         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')
    95.                         return true
    96.                     end
    97.                     -- add container with items to Store Inbox
    98.                     receivedItemStatus = playerStoreInbox:addItemEx(newContainer)
    99.  
    100.                     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
    101.                         player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
    102.                         db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    103.                         db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    104.                     else
    105.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    106.                         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)
    107.                     end
    108.  
    109. -- DELIVER YOUR CUSTOM THINGS
    110.                 elseif shopOfferType == 'mount' then -- addon, mount etc.
    111.                 local player = Player(cid)
    112.                 if (getPlayerStorageValue(cid,itemId) == -1) then
    113.                 doPlayerAddMount(cid, itemId)
    114.                 setPlayerStorageValue(cid,itemId,1)
    115.                 doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYDAMAGE)
    116.                 doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. Please desconnect and re-connect you character!')
    117.                 db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
    118.                 db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
    119.                 else
    120.                 doPlayerSendTextMessage(cid,25,"You Already have this Mount.")
    121.                 end
    122.                 return TRUE
    123.                 end              
    124.  
    125.                 elseif shopOfferType == 'addon' then                 local player = Player(cid)
    126.                 if (getPlayerStorageValue(cid,itemId) == -1) then
    127.                 doPlayerAddOutfit(cid, itemId, 3)
    128.                 setPlayerStorageValue(cid,itemId,1)
    129.                 doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYDAMAGE)
    130.                 doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. Please desconnect and re-connect you character!')
    131.                 db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
    132.                 db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
    133.                 else
    134.                 doPlayerSendTextMessage(cid,25,"You Already have this Outfit.")
    135.                 end
    136.                 return TRUE
    137.                 end              
    138.             end
    139.         until not result.next(resultId)
    140.         result.free(resultId)
    141.     end
    142.  
    143.     return true
    144. end
     
  4. darkjav

    darkjav Senior Developer

    Joined:
    Apr 29, 2008
    Messages:
    195
    Likes Received:
    12
    Best Answers:
    0
    @malucooo I get this error:

    Code (Text):
    1. [Warning - Event::checkScript] Can not load script: scripts/others/shop.lua
    2. data/globalevents/scripts/others/shop.lua:138: 'until' expected (to close 'repeat' at line 9) near 'end'
    3.  
    EDIT:
    I already fix, thanks alot @Gesior.pl :D
     
    Last edited: Sep 3, 2016
  5. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,841
    Likes Received:
    650
    Best Answers:
    2
    I changed variable names and there is no 'cid' anymore, so your old mount and addon scripts will not work, but I will fix it on evening and post here.

    EDIT:
    Script with popular addon and mount system (these types are not available in normal Gesior 2012, you need to create shopsystem.php page by yourself or find it somewhere):
    Code (Text):
    1.  
    2. -- ### CONFIG ###
    3. -- 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)
    4. SHOP_MSG_TYPE = MESSAGE_EVENT_ADVANCE
    5. -- ### END OF CONFIG ###
    6.  
    7. function onThink(interval)
    8.     local resultId = db.storeQuery("SELECT * FROM z_ots_comunication")
    9.     if resultId ~= false then
    10.         repeat
    11.             local transactionId = tonumber(result.getDataInt(resultId, "id"))
    12.             local player = Player(result.getDataString(resultId, "name"))
    13.  
    14.             if player then
    15.                 local itemId = result.getDataInt(resultId, "param1")
    16.                 local itemCount = result.getDataInt(resultId, "param2")
    17.                 local containerId = result.getDataInt(resultId, "param3")
    18.                 local containerItemsInsideCount = result.getDataInt(resultId, "param4")
    19.                 local shopOfferType = result.getDataString(resultId, "param5")
    20.                 local shopOfferName = result.getDataString(resultId, "param6")
    21.  
    22. -- DELIVER ITEM
    23.                 if shopOfferType == 'item' then
    24.                     local newItemUID = doCreateItemEx(itemId, itemCount)
    25.                     --  item does not exist, wrong id OR count
    26.                     if not newItemUID then
    27.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    28.                         print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
    29.                         return true
    30.                     end
    31.                     -- change item UniqueID to object of class Item
    32.                     local newItem = Item(newItemUID)
    33.  
    34.                     -- get player store inbox as container, so we can add item to it
    35.                     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    36.                     -- cannot open Store Inbox, report problem
    37.                     if not playerStoreInbox then
    38.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    39.                         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')
    40.                         return true
    41.                     end
    42.                     -- add container with items to Store Inbox
    43.                     receivedItemStatus = playerStoreInbox:addItemEx(newItem)
    44.  
    45.                     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
    46.                         player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
    47.                         db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    48.                         db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    49.                     else
    50.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    51.                         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)
    52.                     end
    53.  
    54. -- DELIVER CONTAINER
    55.                 elseif shopOfferType == 'container' then
    56.                     -- create empty container
    57.                     local newContainerUID = doCreateItemEx(containerId, 1)
    58.                     -- container item does not exist OR item is not Container
    59.                     if not newContainerUID or not Container(newContainerUID) then
    60.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    61.                         print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create container - invalid container ID - CONTAINER ID:' .. containerId)
    62.                         return true
    63.                     end
    64.                     -- change container UniqueID to object of class Container
    65.                     local newContainer = Container(newContainerUID)
    66.  
    67.                     -- add items to container
    68.                     for i = 1, containerItemsInsideCount do
    69.                         -- create new item
    70.                         local newItemUID = doCreateItemEx(itemId, itemCount)
    71.                         --  item does not exist, wrong id OR count
    72.                         if not newItemUID then
    73.                             player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    74.                             print('ERROR! Website Shop (' .. player:getName() .. ') - cannot create item - invalid item ID OR count - ITEM ID: ' .. itemId .. ', ITEM COUNT: ' .. itemCount)
    75.                             return true
    76.                         end
    77.                         -- change item UniqueID to object of class Item
    78.                         local newItem = Item(newItemUID)
    79.  
    80.                         -- add item to container
    81.                         local addItemToContainerResult = newContainer:addItemEx(newItem)
    82.                         -- report error if it's not possible to add item to container
    83.                         if type(addItemToContainerResult) ~= "number" or addItemToContainerResult ~= RETURNVALUE_NOERROR then
    84.                             player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    85.                             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)
    86.                             return true
    87.                         end
    88.                     end
    89.  
    90.                     -- get player store inbox as container, so we can add item to it
    91.                     local playerStoreInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    92.                     -- cannot open Store Inbox, report problem
    93.                     if not playerStoreInbox then
    94.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    95.                         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')
    96.                         return true
    97.                     end
    98.                     -- add container with items to Store Inbox
    99.                     receivedItemStatus = playerStoreInbox:addItemEx(newContainer)
    100.  
    101.                     if type(receivedItemStatus) == "number" and receivedItemStatus == RETURNVALUE_NOERROR then
    102.                         player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop. You can find your item in STORE INBOX (under EQ).')
    103.                         db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    104.                         db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    105.                     else
    106.                         player:sendTextMessage(SHOP_MSG_TYPE, 'Website Shop bugged. Contact with administrator! Error is visible in server console.')
    107.                         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)
    108.                     end
    109.  
    110. -- DELIVER YOUR CUSTOM THINGS
    111.                 elseif shopOfferType == 'mount' then -- addon, mount etc.
    112.                     player:addMount(itemId)
    113.                     player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
    114.                     player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop.')
    115.                     db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    116.                     db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)    
    117.  
    118.                 elseif shopOfferType == 'addon' then
    119.                     player:addOutfit(itemId)
    120.                     player:addOutfitAddon(itemId, 3)
    121.                     player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
    122.                     player:sendTextMessage(SHOP_MSG_TYPE, 'You received ' .. shopOfferName .. ' from Website Shop.')
    123.                     db.asyncQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. transactionId)
    124.                     db.asyncQuery("UPDATE `z_shop_history_item` SET `trans_state`= 'realized', `trans_real`=" .. os.time() .. " WHERE `id` = " .. transactionId)
    125.                 end
    126.             end
    127.         until not result.next(resultId)
    128.         result.free(resultId)
    129.     end
    130.  
    131.     return true
    132. end
    GIST:
    https://gist.github.com/gesior/0de6fa34a7dfe5c5269f1765e8f6a9d4
     
    Last edited: Sep 4, 2016
  6. Majster12

    Majster12 Member

    Joined:
    Feb 20, 2009
    Messages:
    128
    Likes Received:
    11
    Best Answers:
    1
    Everything working fine but when player never opened Store Inbox before there are a lot of errors.
    [​IMG]
     
  7. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,841
    Likes Received:
    650
    Best Answers:
    2
    Report it to your distro authors. It's bug in server sources.
    You can add to message to player information that, he needs to open STORE INBOX to get his items.
    Thank you for report!
     
  8. Romenes Hasvu

    Romenes Hasvu Banned User

    Joined:
    Nov 20, 2015
    Messages:
    300
    Likes Received:
    12
    Best Answers:
    0
    Hey @Gesior.pl help!!
    My dont receiving addons/mounts, only receive the items
    can you help me?
     
  9. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,773
    Likes Received:
    580
    Best Answers:
    10
    cus there is not addons or mounts in the gesior script
     
  10. Romenes Hasvu

    Romenes Hasvu Banned User

    Joined:
    Nov 20, 2015
    Messages:
    300
    Likes Received:
    12
    Best Answers:
    0
    My shop script (working) > but I need to go in store inbox...

    @StreamSide you can give me one good??

    My code working (without store inbox) look:

    Code (Text):
    1. SHOP_MSG_TYPE = 18
    2. -- time (in seconds) between connections to SQL database by shop script
    3. SQL_interval = 30
    4. -- ### END OF CONFIG ###
    5. function onThink(interval, lastExecution)
    6.     local result_plr = db.storeQuery("SELECT * FROM z_ots_comunication")
    7.     if(result_plr ~= false) then
    8.         repeat
    9.             local id = tonumber(result.getDataInt(result_plr, "id"))
    10.             local action = tostring(result.getDataString(result_plr, "action"))
    11.             local delete = tonumber(result.getDataInt(result_plr, "delete_it"))
    12.             local cid = getPlayerByName(tostring(result.getDataString(result_plr, "name")))
    13.             if(cid) then
    14.                 local itemtogive_id = tonumber(result.getDataInt(result_plr, "param1"))
    15.                 local itemtogive_count = tonumber(result.getDataInt(result_plr, "param2"))
    16.                 local container_id = tonumber(result.getDataInt(result_plr, "param3"))
    17.                 local container_count = tonumber(result.getDataInt(result_plr, "param4"))
    18.                 local add_item_type = tostring(result.getDataString(result_plr, "param5"))
    19.                 local add_item_name = tostring(result.getDataString(result_plr, "param6"))
    20.                 local storage = tostring(result.getDataString(result_plr, "param7"))
    21.                 local received_item = 0
    22.                 local full_weight = 0
    23.                 if(add_item_type == 'container') then
    24.                     container_weight = getItemWeight(container_id, 1)
    25.                     if(isItemRune(itemtogive_id)) then
    26.                         items_weight = container_count * getItemWeight(itemtogive_id, 1)
    27.                     else
    28.                         items_weight = container_count * getItemWeight(itemtogive_id, itemtogive_count)
    29.                     end
    30.                     full_weight = items_weight + container_weight
    31.                 else
    32.                     full_weight = getItemWeight(itemtogive_id, itemtogive_count)
    33.                     if(isItemRune(itemtogive_id)) then
    34.                         full_weight = getItemWeight(itemtogive_id, 1)
    35.                     else
    36.                         full_weight = getItemWeight(itemtogive_id, itemtogive_count)
    37.                     end
    38.                 end
    39.                 local free_cap = getPlayerFreeCap(cid)
    40.                 if(full_weight <= free_cap) then
    41.                     if(add_item_type == 'container') then
    42.                         local new_container = doCreateItemEx(container_id, 1)
    43.                         local iter = 0
    44.                         while(iter ~= container_count) do
    45.                             doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
    46.                             iter = iter + 1
    47.                         end
    48.                         received_item = doPlayerAddItemEx(cid, new_container)
    49.                     else
    50.                         local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
    51.                         received_item = doPlayerAddItemEx(cid, new_item)
    52.                     end
    53.                     if(type(received_item) == "number" and received_item == RETURNVALUE_NOERROR) then
    54.                         doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received '.. add_item_name ..' from Tibia Shop.')
    55.                         setPlayerStorageValue(cid,storage+555884621212,1)
    56.                         db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
    57.                         db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
    58.                     else
    59.                         doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' from Tibia Shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
    60.                     end
    61.                 else
    62.                     doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' Tibia Shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
    63.                 end
    64.             end
    65.         until not result.next(result_plr)
    66.         result.free(result_plr)
    67.     end
    68.     return true
    69. end
     
  11. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,773
    Likes Received:
    580
    Best Answers:
    10
    https://gist.github.com/gesior/0de6fa34a7dfe5c5269f1765e8f6a9d4 this should work
     
  12. Romenes Hasvu

    Romenes Hasvu Banned User

    Joined:
    Nov 20, 2015
    Messages:
    300
    Likes Received:
    12
    Best Answers:
    0
    Last edited: Sep 23, 2016
  13. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,773
    Likes Received:
    580
    Best Answers:
    10
    tfs 1.2? errors?
     
  14. ayakuss

    ayakuss New Member

    Joined:
    Nov 7, 2016
    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Em meu inbox LOJA NO TEM LIMITE PAC, PLAYER pode colocar SET IN STORE INBOX, WHAT I DO FOR BLOCK STORE INBOX FOR NO ENTER OR MOVE ITENS;
     
  15. adrianootavares

    adrianootavares Member

    Joined:
    Jul 23, 2012
    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
  16. adrianootavares

    adrianootavares Member

    Joined:
    Jul 23, 2012
    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
  17. bok

    bok Member

    Joined:
    Apr 28, 2009
    Messages:
    322
    Likes Received:
    4
    Best Answers:
    0
    Sorry to relive this topic, but would it be possible to add Premium Account from shop.lua?

    Sorry to relive this topic, but would it be possible to add Premium Account from shop.lua?
     

Share This Page

Loading...