Lopaskurwa
Active Member
- Joined
- Oct 6, 2017
- Messages
- 873
- Solutions
- 2
- Reaction score
- 49
How to add random items into a this script
reward_id = 16857 and count should be not random. But i want to add more items into this one chest and those items are random so, 16857 is not random and 100,101,102 is random, so you get 16857 and random item from (100,101,102) i though about combining with this script Random reward Chest (https://otland.net/threads/random-reward-chest.253684/) but then every item will be random so i have no idea
Lua:
local storage_id = 2544
TFS 1.2
local rewards = {
[1] = {chest_uid = 1575, reward_id = 16857, reward_count = 25}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local storage = player:getStorageValue(storage_id)
if storage > 0 then
return player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
end
local reward
for i = 1, #rewards do
if rewards[i].chest_uid == item.uid then
reward = rewards[i]
break
end
end
local reward_type = ItemType(reward.reward_id)
if reward_type then
if player:addItem(reward.reward_id, reward.reward_count, false, 1, CONST_SLOT_WHEREEVER) then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a " .. reward_type:getName():lower() .. ".")
player:setStorageValue(storage_id, 1)
else
local weight = reward_type:getWeight()
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found an item weighing ' .. weight / 100 .. ' oz it\'s too heavy or you do not have enough room.')
end
end
return true
end