So, here we are having yet another weird issue with a script. It works great, don't get me wrong.. if you place any item that doesn't have "count" as a value, the chests work as intended. 1 use, then will report it is empty.
But with some chests, for example with rewards: 1x small ruby and a battle hammer.
The chest will be able to be looted multiple times, its quite strange.
Error when using a chest with a count item in it:
Personally, I think it has something to do with this line, but Im not quite sure at the moment:
player:addItem(reward:getId(), reward:getCount(), false, reward:getCharges()):setActionId(reward:getActionId())
Any ideas are greatly appreciated!
But with some chests, for example with rewards: 1x small ruby and a battle hammer.
The chest will be able to be looted multiple times, its quite strange.
Error when using a chest with a count item in it:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/reward.lua:onUse
data/actions/scripts/quests/reward.lua:33: attempt to call method 'setActionId'
(a nil value)
stack traceback:
[C]: in function 'setActionId'
data/actions/scripts/quests/reward.lua:33: in function <data/actions/scr
ipts/quests/reward.lua:1>
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local chest = Container(item.uid)
if not chest then
return true
end
local uniqueid = chest:getUniqueId()
if player:getStorageValue(uniqueid) == -2 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
return true
end
local reward = nil
local start = player:getStorageValue(uniqueid) == -1 and 0 or player:getStorageValue(uniqueid)
for i = start, chest:getSize() do
reward = chest:getItem(i)
if not reward then
break
end
if reward:getWeight() > player:getFreeCapacity() then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. reward:getWeight()/100 .. ' oz it\'s too heavy.')
player:setStorageValue(uniqueid, i)
break
else
local reward_container = Container(reward:getUniqueId())
if reward_container then
reward_container = reward_container:clone()
reward_container:moveTo(player)
else
player:addItem(reward:getId(), reward:getCount(), false, reward:getCharges()):setActionId(reward:getActionId())
end
local reward_msg = reward:getArticle() .. ' ' .. reward:getName()
if reward:getCount() > 1 then
reward_msg = reward:getCount() .. ' ' .. reward:getPluralName()
end
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. reward_msg .. '.')
player:setStorageValue(uniqueid, -2)
end
end
return true
end
Personally, I think it has something to do with this line, but Im not quite sure at the moment:
player:addItem(reward:getId(), reward:getCount(), false, reward:getCharges()):setActionId(reward:getActionId())
Any ideas are greatly appreciated!
Last edited: