• 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 Problem with converting "game store" units

Kownikuzyt

Member
Joined
Feb 11, 2020
Messages
170
Solutions
1
Reaction score
8
Hello,
I have a problem if you want to buy "Crystal Coins" in quantity "5".
When you get the message that you purchased "5" "Store Inbox" number "25" appears (same is with "Potion of Health")

gamesstore.png

Can you fix it somehow?



data/modules/scripts/gamestore/init.lua

data/modules/scripts/gamestore/gamestore.lua
 

Attachments

Solution
In init.lua you're adding the item to the player X times X:
Lua:
        -- If offer is item.
        if offer.type == GameStore.OfferTypes.OFFER_TYPE_ITEM then
            local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
            if inbox and inbox:getEmptySlots() > offer.count then
                for t = 1,offer.count do
                    inbox:addItem(offer.thingId, offer.count or 1)
                end
            else
                return addPlayerEvent(sendStoreError, 250, player, GameStore.StoreErrors.STORE_ERROR_NETWORK, "Please make sure you have free slots in your store inbox.")
            end
Specifically lines 5-6. On line 5 you're looping the offer count (in this case 5) then on line 6 you're adding the...
In init.lua you're adding the item to the player X times X:
Lua:
        -- If offer is item.
        if offer.type == GameStore.OfferTypes.OFFER_TYPE_ITEM then
            local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
            if inbox and inbox:getEmptySlots() > offer.count then
                for t = 1,offer.count do
                    inbox:addItem(offer.thingId, offer.count or 1)
                end
            else
                return addPlayerEvent(sendStoreError, 250, player, GameStore.StoreErrors.STORE_ERROR_NETWORK, "Please make sure you have free slots in your store inbox.")
            end
Specifically lines 5-6. On line 5 you're looping the offer count (in this case 5) then on line 6 you're adding the item with the same count (5 again). 5x5=25. If you were to buy the 10x crystal coins you would get 100. To fix it, just remove the loop and add the item with the count.
 
Solution
In init.lua you're adding the item to the player X times X:
Lua:
        -- If offer is item.
        if offer.type == GameStore.OfferTypes.OFFER_TYPE_ITEM then
            local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
            if inbox and inbox:getEmptySlots() > offer.count then
                for t = 1,offer.count do
                    inbox:addItem(offer.thingId, offer.count or 1)
                end
            else
                return addPlayerEvent(sendStoreError, 250, player, GameStore.StoreErrors.STORE_ERROR_NETWORK, "Please make sure you have free slots in your store inbox.")
            end
Specifically lines 5-6. On line 5 you're looping the offer count (in this case 5) then on line 6 you're adding the item with the same count (5 again). 5x5=25. If you were to buy the 10x crystal coins you would get 100. To fix it, just remove the loop and add the item with the count.
@jo3bingham

Thanks for your help for solving the problem.



Lua:
-- If offer is item.
        if offer.type == GameStore.OfferTypes.OFFER_TYPE_ITEM then
            local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
            if inbox and inbox:getEmptySlots() > 0 then
                for t = 1,offer.count do
                    inbox:addItem(offer.thingId, 1)
                end
            else
                return addPlayerEvent(sendStoreError, 250, player, GameStore.StoreErrors.STORE_ERROR_NETWORK, "Please make sure you have free slots in your store inbox.")
            end
 
Back
Top