• 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 Increase loot by chance timing

Kawaki69

Member
Joined
Mar 4, 2022
Messages
72
Reaction score
8
Greetings, searching for usable item that increase your loot by chance for 5 hours. and print text message when you kill any monster "Loot_increase":- the items that dropped
thanks
using tfs 1.4.1
 
Solution
Lua:
local plural = function(int, str)
    return int..' '..(int <= 1 and str:sub(1, #str - 1) or str)
end

local timeFormat = function(timestamp)
    local ret = {}
    if timestamp then
        local time = timestamp
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if (hours > 0) then
            ret[1] = plural(hours, 'hours')
            if (time % 3600) ~= 0 then
                ret[2] = plural(minutes, 'minutes')
            end
        elseif (minutes > 0) then
            ret[1] = plural(minutes, 'minutes')
            if (time % 60) ~= 0 then
                ret[2] = plural(seconds, 'seconds')...
Lua:
local plural = function(int, str)
    return int..' '..(int <= 1 and str:sub(1, #str - 1) or str)
end

local timeFormat = function(timestamp)
    local ret = {}
    if timestamp then
        local time = timestamp
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if (hours > 0) then
            ret[1] = plural(hours, 'hours')
            if (time % 3600) ~= 0 then
                ret[2] = plural(minutes, 'minutes')
            end
        elseif (minutes > 0) then
            ret[1] = plural(minutes, 'minutes')
            if (time % 60) ~= 0 then
                ret[2] = plural(seconds, 'seconds')
            end
        else
            ret[1] = plural(seconds, 'seconds')
        end
    end
    return table.concat(ret, ' and ')
end

local config = {}
config.increaseTime = 5 * 60 * 60
config.increaseStorage = 12500

local increaseLoot = Action()
function increaseLoot.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.increaseStorage) > os.time() then
        return player:getPosition():sendMagicEffect(CONST_ME_POFF),
        player:sendCancelMessage("You still have "..timeFormat(player:getStorageValue(config.increaseStorage) - os.time()).." of increased loot.")
    end

    item:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    player:setStorageValue(config.increaseStorage, os.time() + config.increaseTime)
    return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your loot rate has been increased for "..timeFormat(config.increaseTime)..".")
end

increaseLoot:id(5865)
increaseLoot:register()

sadly you have to set manually storage and extrapercent on scripts/evencallbacks/default_onDropLoot.lua

here is the example (you can use this one tho)
Lua:
local ec = EventCallback

ec.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    if not player or player:getStamina() > 840 then
        local monsterLoot = mType:getLoot()

        local increaseLoot = false
        local extraLootPercent = 15
        if player and player:getStorageValue(12500) > os.time() then
            increaseLoot = true
        end

        for i = 1, #monsterLoot do
            if increaseLoot then
                local default = monsterLoot[i]
                if default.chance < 100000 then
                    default.chance = default.chance + ((extraLootPercent * (default.chance / 1000) / 100) * 1000)
                end
            end
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
        end

        if player then
            local text = ("%s of %s: %s"):format((increaseLoot and "Increased loot" or "Loot"), mType:getNameDescription(), corpse:getContentDescription())
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text)
            else
                player:sendTextMessage(MESSAGE_LOOT, text)
            end
        end
    else
        local text = ("Loot of %s: nothing (due to low stamina)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_LOOT, text)
        end
    end
end

ec:register()
 
Last edited:
Solution
Lua:
local plural = function(int, str)
    return (int > 1 and int..' '..str..'s' or int..' '..str)
end

local timeFormat = function(timestamp)
    local ret = {}
    if timestamp then
        local time = timestamp
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if (time >= 3600) then
            ret[1] = plural(hours, 'hour')
            if (time % 3600) > 0 then
                ret[2] = plural(minutes, 'minute')
            end
        elseif (time >= 60) then
            ret[1] = plural(minutes, 'minute')
            if (time % 60) > 0 then
                ret[2] = plural(seconds, 'second')
            end
        else
            ret[1] = plural(seconds, 'second')
        end
    end
    return table.concat(ret, ' and ')
end

local config = {}
config.increaseTime = 5 * 60 * 60
config.increaseStorage = 12500

local increaseLoot = Action()
function increaseLoot.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.increaseStorage) > os.time() then
        return player:getPosition():sendMagicEffect(CONST_ME_POFF),
        player:sendCancelMessage("You still have "..timeFormat(player:getStorageValue(config.increaseStorage) - os.time()).." of increased loot.")
    end

    item:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your loot rate has been increased for "..timeFormat(config.increaseTime)..".")
    return player:setStorageValue(config.increaseStorage, os.time() + config.increaseTime)
end

increaseLoot:id(5865)
increaseLoot:register()

sadly you have to set manually storage and extrapercent on scripts/evencallbacks/default_onDropLoot.lua

here is the example (you can use this one tho)
Lua:
local ec = EventCallback
ec.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    if not player or player:getStamina() > 840 then
        local monsterLoot = mType:getLoot()

        local increaseLoot = false
        local extraLootPercent = 15
        if player then
            if player:getStorageValue(12500) > os.time() then
                increaseLoot = true
            end
        end
       
        for i = 1, #monsterLoot do
            if increaseLoot then
                local default = monsterLoot[i]
                if default.chance < 100000 then
                    default.chance = default.chance + ((extraLootPercent * (default.chance / 1000) / 100) * 1000)
                end
            end
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
        end

        if player then
            local text = ("%s of %s: %s"):format((increaseLoot and "Increased loot" or "Loot"), mType:getNameDescription(), corpse:getContentDescription())
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text)
            else
                player:sendTextMessage(MESSAGE_LOOT, text)
            end
        end
    else
        local text = ("Loot of %s: nothing (due to low stamina)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_LOOT, text)
        end
    end
end

ec:register()
1652126986141.png awww it works thanks @Roddet god bless you boss! works!!
 
Lua:
local plural = function(int, str)
    return int..' '..(int <= 1 and str:sub(1, #str - 1) or str)
end

local timeFormat = function(timestamp)
    local ret = {}
    if timestamp then
        local time = timestamp
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if (hours > 0) then
            ret[1] = plural(hours, 'hours')
            if (time % 3600) ~= 0 then
                ret[2] = plural(minutes, 'minutes')
            end
        elseif (minutes > 0) then
            ret[1] = plural(minutes, 'minutes')
            if (time % 60) ~= 0 then
                ret[2] = plural(seconds, 'seconds')
            end
        else
            ret[1] = plural(seconds, 'seconds')
        end
    end
    return table.concat(ret, ' and ')
end

local config = {}
config.increaseTime = 5 * 60 * 60
config.increaseStorage = 12500

local increaseLoot = Action()
function increaseLoot.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.increaseStorage) > os.time() then
        return player:getPosition():sendMagicEffect(CONST_ME_POFF),
        player:sendCancelMessage("You still have "..timeFormat(player:getStorageValue(config.increaseStorage) - os.time()).." of increased loot.")
    end

    item:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    player:setStorageValue(config.increaseStorage, os.time() + config.increaseTime)
    return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your loot rate has been increased for "..timeFormat(config.increaseTime)..".")
end

increaseLoot:id(5865)
increaseLoot:register()

sadly you have to set manually storage and extrapercent on scripts/evencallbacks/default_onDropLoot.lua

here is the example (you can use this one tho)
Lua:
local ec = EventCallback

ec.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    if not player or player:getStamina() > 840 then
        local monsterLoot = mType:getLoot()

        local increaseLoot = false
        local extraLootPercent = 15
        if player and player:getStorageValue(12500) > os.time() then
            increaseLoot = true
        end

        for i = 1, #monsterLoot do
            if increaseLoot then
                local default = monsterLoot[i]
                if default.chance < 100000 then
                    default.chance = default.chance + ((extraLootPercent * (default.chance / 1000) / 100) * 1000)
                end
            end
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
        end

        if player then
            local text = ("%s of %s: %s"):format((increaseLoot and "Increased loot" or "Loot"), mType:getNameDescription(), corpse:getContentDescription())
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text)
            else
                player:sendTextMessage(MESSAGE_LOOT, text)
            end
        end
    else
        local text = ("Loot of %s: nothing (due to low stamina)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_LOOT, text)
        end
    end
end

ec:register()
Sorry @Roddet I meant by increasing the loot increase the chance instead from the items can u please adjust it :)
 
Back
Top