I'm trying to add a function so that when a player uses an item (like a chest) and they dont have any capacity or they don't have any space in their backpack then they get denied the reward and sent a message. I've looked around a bit but nothing fits what I'm trying to do.
Code:
NOT_CLEARED = -1
CLEARED = 1
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
local chest = 5001 -- The chest UID / Unique ID.
--local moneyReward = 70000 -- The amount of money.
--local xpReward = 7000 -- The amount of xp.
local questName = "Treasure Island Quest" -- The name of the quest.
if item.uid == chest then
local p = Player(cid)
isCleared = p:getStorageValue(chest)
if isCleared == NOT_CLEARED then
p:addItem(10532, 1)
p:addItem(9971, 3)
p:addItem(2148, 78)
p:addItem(24115, 1)
p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You look through the chest and find a bejeweled ship's telescope, 3 gold ingots, and a boss token. You also pick up some gold coins scattered about.")
--p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've earned 7k for completing the " .. questName .. ".")
--p:addMoney(moneyReward)
--p:addExperience(xpReward)
p:setStorageValue(chest, CLEARED)
else
p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This chest is empty.")
end
end
return true
end