• 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!

Lua TFS 1.2 How to add multiple items/extra feature and level requirement in this chest script

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
783
Solutions
2
Reaction score
42
Hello how can i add multiple items in this code and extra feature which i have in my functions.lua which is
Lua:
      addExtraHealth = Howmuchyouwanttoadd
        addExtraMana = Howmuchyouwanttoadd,

And need level requirement

Not sure whats the right structure for it maybe something should look like this
Lua:
local rewards = {
    [1] = {chest_uid = 1587},
    {
    rewards = {
        addExtraHealth = 1000,
        addExtraMana = 1000,
        addItem = {{id = 14316, count = 1}, {id = 14317, count = 1}, {id = 14318, count = 1}},
    },
    needLevel = 300,
}
   [2] and etc

Lua:
local storage_id = 2550

local rewards = {
    [1] = {chest_uid = 1587, reward_id = 1531, reward_count = 1},
    [2] = {chest_uid = 1588, reward_id = 1533, 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
 
Solution
Install this.
[TFS 1.X] Give player items by table | OTLand

Then, try this.
Lua:
local rewards = {
    [1587] = { storage_id = 2550, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = {
            {1531, 1}, -- {reward_id, reward_count}
            {1531, 1},
            {1531, 1}
        }
    },
    [1588] = { storage_id = 2551, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = {
            {1531, 1},
            {1531, 1},
            {1531, 1}
        }
    },
    [1589] = { storage_id = 2552, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,678
Solutions
406
Reaction score
3,789
Install this.
[TFS 1.X] Give player items by table | OTLand

Then, try this.
Lua:
local rewards = {
    [1587] = { storage_id = 2550, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = {
            {1531, 1}, -- {reward_id, reward_count}
            {1531, 1},
            {1531, 1}
        }
    },
    [1588] = { storage_id = 2551, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = {
            {1531, 1},
            {1531, 1},
            {1531, 1}
        }
    },
    [1589] = { storage_id = 2552, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = { {1531, 1}, {1531, 1}, {1531, 1} }
    },
    [1590] = { storage_id = 2553, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = { {1531, 1}, {1531, 1}, {1531, 1} }
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    -- confirm index
    local index = rewards[item:getUniqueId()]
    if not index then
        print("UniqueId not in table.")
        return true
    end
    
    -- check storage
    if player:getStorageValue(index.storage_id) > 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end
    
    -- check level
    if player:getLevel() < index.level_required then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You require level " .. index.level_required .. ".")
        return true
    end
    
    -- give health/mana increases
    if index.maximum_Health_Increase and index.maximum_Health_Increase > 0 then
        local newMaxHealth = player:getMaxHealth() + index.maximum_Health_Increase
        player:setMaxHealth(newMaxHealth)
    end
    
    if index.maximum_Mana_Increase and index.maximum_Mana_Increase > 0 then
        local newMaxMana = player:getMaxMana() + index.maximum_Mana_Increase
        player:setMaxMana(newMaxMana)
    end
    
    -- give item rewards
    if index.item_rewards and #index.item_rewards > 0 then
        player:giveItems(index.item_rewards)
    end
    
    -- give storage
    player:setStorageValue(index.storage_id, 1)
    return true
end
 
Last edited:
Solution
OP
OP
Lopaskurwa

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
783
Solutions
2
Reaction score
42
Install this.
[TFS 1.X] Give player items by table | OTLand

Then, try this.
Lua:
local rewards = {
    [1587] = { storage_id = 2550, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = {
            {1531, 1}, -- {reward_id, reward_count}
            {1531, 1},
            {1531, 1}
        }
    },
    [1588] = { storage_id = 2551, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = {
            {1531, 1},
            {1531, 1},
            {1531, 1}
        }
    },
    [1589] = { storage_id = 2552, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = { {1531, 1}, {1531, 1}, {1531, 1} }
    },
    [1590] = { storage_id = 2553, level_required = 200,
        maximum_Health_Increase = 1000,
        maximum_Mana_Increase = 1000,
        item_rewards = { {1531, 1}, {1531, 1}, {1531, 1} }
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
    -- confirm index
    local index = rewards[item:getUniqueId()]
    if not index then
        print("UniqueId not in table.")
        return true
    end
   
    -- check storage
    if player:getStorageValue(index.storage_id) > 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end
   
    -- check level
    if player:getLevel() < index.level_required then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You require level " .. index.level_required .. ".")
        return true
    end
   
    -- give health/mana increases
    if index.maximum_Health_Increase and index.maximum_Health_Increase > 0 then
        local newMaxHealth = player:getMaxHealth() + index.maximum_Health_Increase
        player:setMaxHealth(newMaxHealth)
    end
   
    if index.maximum_Mana_Increase and index.maximum_Mana_Increase > 0 then
        local newMaxMana = player:getMaxMana() + index.maximum_Mana_Increase
        player:setMaxMana(newMaxMana)
    end
   
    -- give item rewards
    if index.item_rewards and #index.item_rewards > 0 then
        player:giveItems(index.item_rewards)
    end

    return true
end
Okay it works but i can spam one chest as many times as i want, lets say i take this chest

[1587] = { storage_id = 2550, level_required = 200,
maximum_Health_Increase = 1000,
maximum_Mana_Increase = 1000,
item_rewards = {
{1531, 1}, -- {reward_id, reward_count}
{1531, 1},
{1531, 1}
}
},
i cant take it anymore if i took it
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,678
Solutions
406
Reaction score
3,789
Okay it works but i can spam one chest as many times as i want, lets say i take this chest

[1587] = { storage_id = 2550, level_required = 200,
maximum_Health_Increase = 1000,
maximum_Mana_Increase = 1000,
item_rewards = {
{1531, 1}, -- {reward_id, reward_count}
{1531, 1},
{1531, 1}
}
},
i cant take it anymore if i took it
Edited my post. Copy and try again.
 
Top