Tbol
Well-Known Member
- Joined
- Apr 7, 2019
- Messages
- 625
- Reaction score
- 71
Hello,
im using this chest so im thinking it would be nice to add like instead if items toit give premium x days. Im using this chest code
I know that i need to use player:addPremiumDays but im not sure overall about code because if i remove local reward pretty much whole code becomes not usable because rewards variable associates in every line. And is it possible to make this chest work just once overall in whole account?
im using this chest so im thinking it would be nice to add like instead if items toit give premium x days. Im using this chest code
LUA:
local storage_id = 2550
local rewards = {
[1] = {chest_uid = 1587, reward_id = 1536, reward_count = 1},
[2] = {chest_uid = 1588, reward_id = 1531, reward_count = 1},
[3] = {chest_uid = 1589, reward_id = 12747, reward_count = 1},
[4] = {chest_uid = 1590, reward_id = 14681, reward_count = 1}
}
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