• 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 Help with this script

Vitich

Member
Joined
Nov 28, 2012
Messages
266
Reaction score
11
Hello, I wanted put change on this quest. (TFS 1.2)

Ex: id - 18402 / 5% chance.
id - 18396 / 15% chance.

Code:
local config = {
    [9172] = {items = {{18402}, {18414, 12}, {18396}, {18500}, {2160, 5}, {18423, 2}}, storage = Storage.QuestChests.WarzoneReward1, containerId = 18394},
    [9173] = {items = {{18402}, {18415, 7}, {18396}, {18504}, {2160, 3}, {18423, 2}}, storage = Storage.QuestChests.WarzoneReward2, containerId = 18393},
    [9174] = {items = {{18402}, {18413, 10}, {18396}, {18508}, {2160, 4}, {18423, 2}}, storage = Storage.QuestChests.WarzoneReward3, containerId = 18394}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local useItem = config[item.uid]
    if not useItem then
        return true
    end

    local player, cStorage = player, useItem.storage
    if player:getStorageValue(cStorage) > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.')
        return true
    end

    local container = player:addItem(useItem.containerId)
    if not container then
        return true
    end

    for i = 1, #useItem.items do
        container:addItem(useItem.items[i][1], useItem.items[i][2] or 1)
    end

    player:setStorageValue(cStorage, os.time() + 20 * 60 * 60)
    local itemType = ItemType(container.itemid)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. itemType:getArticle() .. ' ' .. itemType:getName() .. '.')
    return true
end

Thanks!
 
Lua:
local config = {
    [9172] = {
        items = {
            {chance = 5, id = 18402},
            {id = 18414, count = 12},
            {chance = 15, id = 18396},
            {id = 18500},
            {id = 2160, count = 5},
            {id = 18423, count = 2},
        },
        storage = Storage.QuestChests.WarzoneReward1,
        containerId = 18394,
    },
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local useItem = config[item.uid]
    if not useItem then
        return true
    end
    local cStorage = useItem.storage
    if player:getStorageValue(cStorage) > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.')
        return true
    end
    local container = player:addItem(useItem.containerId)
    if not container then
        return true
    end
    for i = 1, #useItem.items do
        if not useItem.items[i].chance or useItem.items[i].chance >= math.random(100) then
            container:addItem(useItem.items[i].id, useItem.items[i].count or 1)
        end
    end
    player:setStorageValue(cStorage, os.time() + 20 * 60 * 60)
    local itemType = ItemType(container.itemid)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. itemType:getArticle() .. ' ' .. itemType:getName() .. '.')
    return true
end
 
Back
Top