So I'm trying to give the player an Item with 1000 charges on it (fiery clerical mace) and it will give the item, but wont set the charges even with the script set up properly. No errors in console, it just gives a clerical mace with only 1 charge.
As you see "reward:getCharges()" is there, but it doesn't work for some reason. It's 2AM in the morning, I must just be looking at it wrong. If anyone see's the problem, I'd greatly appreciate the help!
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(), 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
As you see "reward:getCharges()" is there, but it doesn't work for some reason. It's 2AM in the morning, I must just be looking at it wrong. If anyone see's the problem, I'd greatly appreciate the help!