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

Ring that increases loot rate TFS 1.3

nanduzenho

Member
Joined
Mar 21, 2021
Messages
187
Solutions
1
Reaction score
15
GitHub
nanduzenho
Good afternoon, can someone make a script for a Ring that increases the chance of dropping loot from monsters? You can use any ring as an example. Thank u!
 
Solution
I don't know how to edit
As simple as this but probably you didnt even tried

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            local ring = player:getSlotItem(CONST_SLOT_RING)
            if ring and ring:getId() == 2123 then
                local extraPercent = 20
                local default = monsterLoot[i].chance
             
                if default < 100000 then...
when I first done this script in 2014 it was crazy difficult to achieve that without source editing. Nowadays you have drop of monster in Lua, all you need to do is create a simple onEquip/OnDequip movements to set a storage for the player. Then in the dropLoot function you can sum this storage value in the chance. It's really as simple as that.
 
I don't know how to edit
If you don't know how to edit and you're not keen to learn it, then why do you try to host an OT? It won't be successful.
In the best case scenario you will attract 10 players and in the worst case, your server will be hacked or crashed by abusing known bugs in released distros.
 
You could make a ring that sets X storage value (on equip, movement) when worn and then add to Monster:onDropLoot function in events/monster.lua:

Lua:
local LootPercent = 0
if player:getStorageValue(YOUR_STORAGE_HERE) < 1 then
    local percent = 20 -- 20% extra loot
    if percent then
        LootPercent = (percent / 100)
    end
end
monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * LootPercent)

Just an idea, code mostly extracted from thread quoted above, so I didn't test.
 
I don't know how to edit
As simple as this but probably you didnt even tried

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            local ring = player:getSlotItem(CONST_SLOT_RING)
            if ring and ring:getId() == 2123 then
                local extraPercent = 20
                local default = monsterLoot[i].chance
             
                if default < 100000 then
                    monsterLoot[i].chance = default + ((extraPercent * (default / 1000) / 100) * 1000)
                end
            end
            -- // NEW CODE

            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 = ("Loot of %s: %s"):format(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
As simple as this but probably you didnt even tried

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            local ring = player:getSlotItem(CONST_SLOT_RING)
            if ring and ring:getId() == 2123 then
                local extraPercent = 20
                local default = monsterLoot[i].chance
           
                if default < 100000 then
                    monsterLoot[i].chance = default + ((extraPercent * (default / 1000) / 100) * 1000)
                end
            end
            -- // NEW CODE

            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 = ("Loot of %s: %s"):format(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()
Can u make it for VIP please, if you are VIP u can wear it for x time then it is separated while the time ends. VIP System [The Forgotten Server 1.0] (https://otland.net/threads/vip-system-the-forgotten-server-1-0.224910/) for this script
 
Last edited:
As simple as this but probably you didnt even tried

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            local ring = player:getSlotItem(CONST_SLOT_RING)
            if ring and ring:getId() == 2123 then
                local extraPercent = 20
                local default = monsterLoot[i].chance
            
                if default < 100000 then
                    monsterLoot[i].chance = default + ((extraPercent * (default / 1000) / 100) * 1000)
                end
            end
            -- // NEW CODE

            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 = ("Loot of %s: %s"):format(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()

Excuse my ignorance, how do i install this script?
 
As simple as this but probably you didnt even tried

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            local ring = player:getSlotItem(CONST_SLOT_RING)
            if ring and ring:getId() == 2123 then
                local extraPercent = 20
                local default = monsterLoot[i].chance
            
                if default < 100000 then
                    monsterLoot[i].chance = default + ((extraPercent * (default / 1000) / 100) * 1000)
                end
            end
            -- // NEW CODE

            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 = ("Loot of %s: %s"):format(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()
ec.JPG
i think my TFS 1.3 doesn't have EventCallback function
 
data/scripts/eventcallbacks/monster/default_onDropLoot.lua
my server is TFS 1.3 - version 8.6, it doesn't have eventcallback folder
Post automatically merged:

data/scripts/eventcallbacks/monster/default_onDropLoot.lua
ec.JPG
Post automatically merged:

Well, I located the monster.lua file and added the ring part as the friend posted above and it worked, thank you all for your patience!!! Thank u!!!!!!!!!!!!!
 
Last edited:
As simple as this but probably you didnt even tried

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            local ring = player:getSlotItem(CONST_SLOT_RING)
            if ring and ring:getId() == 2123 then
                local extraPercent = 20
                local default = monsterLoot[i].chance
          
                if default < 100000 then
                    monsterLoot[i].chance = default + ((extraPercent * (default / 1000) / 100) * 1000)
                end
            end
            -- // NEW CODE

            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 = ("Loot of %s: %s"):format(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()

Great Code!
Are you able to do some kind of global event that increases loot for players who are online at the time?
E.g. for a few hours?

Or when player have storagetime > os.time ? (in chest)
When I change ring to: if self:getStorageValue(44444) > os.time() then
Not working.
When I change to : if player:getStorageValue(44444) > os.time() then
All players have double loot, not only player who have storage 44444.

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()
        for i = 1, #monsterLoot do

            -- // NEW CODE
            -- // local ring = player:getSlotItem(CONST_SLOT_RING)
            -- //if ring and ring:getId() == 2123 then
               if self:getStorageValue(44444) > os.time() then
                local extraPercent = 20
                local default = monsterLoot[i].chance
            
                if default < 100000 then
                    monsterLoot[i].chance = default + ((extraPercent * (default / 1000) / 100) * 1000)
                end
            end
            -- // NEW CODE

            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 = ("Loot of %s: %s"):format(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:
Back
Top