function onUse(cid, item, fromPosition, itemEx, toPosition)
local chest = {
vocs = { 4, 8, 12 },
level = 100,
storage = 23315,
items = {
{2160,1},
{2152,1}
}
}
if(getPlayerStorageValue(cid, chest.storage) == -1) then
if(isInArray(chest.vocs, getPlayerVocation(cid)) == true) then
if(getPlayerLevel(cid) >= chest.level) then
for i = 1, #chest.items do
local v = chest.items[i]
local rewards = doCreateItemEx(v[1], v[2])
if(doPlayerAddItemEx(cid, rewards, true) ~= RETURNVALUE_NOERROR) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You do not have enough capacity to carry your reward.")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Here is your reward.")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
setPlayerStorageValue(cid, chest.storage, 1)
end
end
else
doPlayerSendCancel(cid, "Your level is not high enough.")
end
else
doPlayerSendCancel(cid, "Only knights may open this chest.")
end
else
doPlayerSendCancel(cid, "The " .. getItemName(item.uid) .. " is empty.")
end
return true
end