• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Chest that gives premium account

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
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
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?
 
Solution
Simple.
LUA:
local config = {
    daysToAdd = 3,
    storageKey = 14005
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.storageKey) == 1 then
        player:sendCancelMessage("You have already gotten this reward.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, config.daysToAdd .. " premium days have been added to your account.")
    player:addPremiumDays(config.daysToAdd)
    player:setStorageValue(config.storageKey, 1)
    fromPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    return true
end
Simple.
LUA:
local config = {
    daysToAdd = 3,
    storageKey = 14005
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.storageKey) == 1 then
        player:sendCancelMessage("You have already gotten this reward.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, config.daysToAdd .. " premium days have been added to your account.")
    player:addPremiumDays(config.daysToAdd)
    player:setStorageValue(config.storageKey, 1)
    fromPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    return true
end
 
Solution
Back
Top