vexler222
Active Member
- Joined
- Apr 22, 2012
- Messages
- 714
- Solutions
- 15
- Reaction score
- 46
Hi, i found this script for random item from box, but i don't know how to fix it, problem is when from box we got item with X count, i got error nil value count
For items with count 1, not more, it working normally
For items with count 1, not more, it working normally
Code:
local presentbox = Action()
local presents = {
[10503] = { -- item id of the item that will give u random items
{2687, 10}, {6394, 3}, 6280, 6574, 6578, 6575, 6577, 6569, 6576, 6572, 2114 --Setup the rewards here
}
}
function presentbox.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local count = 1
local targetItem = presents[item.itemid]
if not targetItem then
return true
end
local gift = targetItem[math.random(#targetItem)]
if type(gift) == "table" then
gift = gift[1]
count = gift[2]
end
player:addItem(gift, count)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You got ".. ItemType(gift):getName() ..".")
item:remove(1)
fromPosition:sendMagicEffect(CONST_ME_GIFT_WRAPS)
return true
end
presentbox:id(10503)
presentbox:register()