Shadow Dan
Sh4dowDan
Need some help with script.
If i buy something in shop without capacity it removes coins and no item will be added.
If i have capacity for like 44 runes and i buy x250 i will get only 44 and lose coins.
I wonder how to add check player free capacity for item that we are buying (example 250 runes or only 1 item).
There is loop for adding item and that makes it hard for me.
Example of check capacity.
If i buy something in shop without capacity it removes coins and no item will be added.
If i have capacity for like 44 runes and i buy x250 i will get only 44 and lose coins.
I wonder how to add check player free capacity for item that we are buying (example 250 runes or only 1 item).
There is loop for adding item and that makes it hard for me.
Code:
-- 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
-- If offer is Stackable.
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_STACKABLE then
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox and inbox:getEmptySlots() > 0 then
local parcel = inbox:addItem(23782, 1)
local packagename = ''.. offer.count..'x '.. offer.name ..' package.'
if parcel then
parcel:setAttribute(ITEM_ATTRIBUTE_NAME, packagename)
for e = 1,offer.count do
parcel:addItem(offer.thingId, 1)
end
end
else
return addPlayerEvent(sendStoreError, 250, player, GameStore.StoreErrors.STORE_ERROR_NETWORK, "Please make sure you have free slots in your store inbox.")
end
Example of check capacity.
Code:
if player:addItemEx(reward) ~= RETURNVALUE_NOERROR then
local weight = reward:getWeight()
if player:getFreeCapacity() < weight then
player:sendCancelMessage(string.format('You have found %s weighing %.2f oz. You have no capacity.', result, (weight / 100)))
else
player:sendCancelMessage('You have found ' .. result .. ', but you have no room to take it.')
end
return true
end