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

[TFS 1.X] Rarity Rolls & Custom Attributes Library

< 10.94
The first post is for versions earlier than 10.94, before crit and mana/life leech was added to the game.
Someone should try it on an 8.6 server ;)

10.94+
If you are using the latest TFS release, refer to the post here.

What is this?
A newer version of this:
A variant of this, this and this mod.
It gives items a chance to roll rare, epic or legendary when it drops from a monster:

iSCVyA6.png


With the following possible attributes:
(For config and if you want to understand the code, start at the stats table in lib/core/attributes.lua)
Lua:
[1] = { -- Attack
[2] = { -- Defense
[3] = { -- Extra Defense
[4] = { -- Armor
[5] = { -- Accuracy
[6] = { -- Range
[7] = { -- Equipment with < 50 charges
[8] = { -- Equipment with >= 50 charges
[9] = { -- Time
[10] = { -- Crit Chance
[11] = { -- Crit Amount (Currently Unused)
[12] = { -- Fire Damage
[13] = { -- Ice Damage
[14] = { -- Energy Damage
[15] = { -- Fire Resistance
[16] = { -- Ice Resistance
[17] = { -- Energy Resistance
[18] = { -- Earth Resistance
[19] = { -- Physical Resistance
[20] = { -- Death Resistance
[21] = { -- Spell Damage
[22] = { -- Multi Shot
[23] = { -- Stun Chance
[24] = { -- Mana Shield
[25] = { -- Sword Skill
[26] = { -- Skill Axe
[27] = { -- Skill Club
[28] = { -- Skill Melee
[29] = { -- Skill Distance
[30] = { -- Skill Shielding
[31] = { -- Magic Level
[32] = { -- Max Health i.e +100
[33] = { -- Max Mana i.e +100
[34] = { -- Max Health % i.e +10%
[35] = { -- Max Mana % i.e +10%
[36] = { -- Life Leech Chance (Currently Unused)
[37] = { -- Life Leech Amount
[38] = { -- Mana Leech Chance (Currently Unused)
[39] = { -- Mana Leech Amount


Cw1kJDN.png


Some of these are completely custom attributes, like elemental damage:

56C8xHU.gif


This requires the following updates/features:

1) Loot drop handled via Lua
2) Add the new health/mana gain coloured text messages
3) onInventoryUpdate()
4) onSpawn()


Installation:
📁 rollAttributes.zip
paste in /data

lib/core/core.lua
add below:
Lua:
-- Rolls & Custom Item Attributes
dofile('data/lib/core/attributes.lua')

talkactions.xml
add below:
XML:
<talkaction words="/roll" separator=" " script="roll.lua" />

creaturescripts.xml
add below:
XML:
<!-- Roll & Attribute Damage -->
<event type="healthchange" name="rollHealth" script="attributes.lua"/>
<event type="manachange" name="rollMana" script="attributes.lua"/>

creaturescripts/scripts/login.lua
add below:
Lua:
-- Activate Custom Item Attributes
for i = 1,10 do -- CONST_SLOT_FIRST,CONST_SLOT_LAST
    local item = player:getSlotItem(i)
    if item then
        itemAttributes(player, item, i, true)
    end
end
-- If player logged with more 'current health' than their db 'max health' due to an item attribute
local query = db.storeQuery("SELECT `health`,`mana` FROM players where `id`="..player:getGuid())
if query then
    local health = tonumber(result.getDataString(query, 'health'))
    local mana = tonumber(result.getDataString(query, 'mana'))
    local playerHealth = player:getHealth()
    local playerMana = player:getMana()
    if playerHealth < health then
        player:addHealth(health - playerHealth)
    end
    if playerMana < mana then
        player:addMana(mana - playerMana)
    end
    result.free(query)
end

add below:
Lua:
player:registerEvent("rollHealth")
player:registerEvent("rollMana")

events/scripts/player.lua
add to the bottom:
Lua:
function Player:onInventoryUpdate(item, slot, equip)
    itemAttributes(self, item, slot, equip)
end

events/scripts/monster.lua
add to the top of the file:
Lua:
-- Rarity Animations
local rare_popup = true
local rare_effect = true
local rare_effect_id = CONST_ME_STUN
add between:
Lua:
-- Apply rarity chance to corpse contents and apply animation
if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation
        if rare_popup then
            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)
            for i = 1, #spectators do
                spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())
            end
        end
    if rare_effect then
        corpse:getPosition():sendMagicEffect(rare_effect_id)
    end
end
add at the end:
Lua:
function Monster:onSpawn(position, startup, artificial)
    self:registerEvent("rollHealth")
    self:registerEvent("rollMana")
   return true
end


The core scripts are attached because they are to big to embed in post, so they're attached as rollAttributes.zip
Don't forget to paste the core scripts into your /data dir.

Extras
  • 'Stun Target' is disabled by default, add the condition from here and uncomment the lines in creaturescripts/scripts/attributes.lua
  • primaryDamage and primaryType are swapped with secondaryDamage and secondaryType on elemental damage (better, consistent visuals)
  • Use the included /roll <rarity> talkaction for testing i.e /roll legendary
  • Mana Leech and Life Leech apply 5ms after damage is done, this may feel different to vanilla Tibia.
  • Multi shot ignores creature armor/shielding - its quite primitive.
  • If you want to re-roll an item you should item:remove() it and re-create it (so it has stock base stats).
  • Custom resistances apply after natural resistances and are additive.
  • A unique weapon & shield using this systems on-hit mechanics can be found in extras.xml
    Overwrite their information in items.xml and uncomment their code in attributes.lua for cool points.

Hi Leo32, first of all, excellent system.

Im trying to get it with an upgrade system compatible, that rolling on a legendary or whatever rarity the upgrade system takes consideration the first stats, on items.xml and not on the custom from rarityRoll.

There is a function that take care about the stats added to the item , that can be used on the upgrade system, to check if is a rarityRoll item, then try to upgrade from there, or if is not possible just return false without upgrading ?

Also, any item looted, for example, demon armor instead of 16 armor it gives 20 armor for example, when equiped it gives correctly the Armor to player, but if is a stat custom like [Armor +4] It doesn't sum this Armor to the player.
Elemental damages on weapons, are working, but very special method: rats, dogs, can take element damage, but using Ice enhancement on a dragon doesn't do any ice damage ?

Im using TFS 1.3 old Otservbr

Btwn, amazing system.
 
Last edited:
Hi Leo32, first of all, excellent system.

Im trying to get it with an upgrade system compatible, that rolling on a legendary or whatever rarity the upgrade system takes consideration the first stats, on items.xml and not on the custom from rarityRoll.

There is a function that take care about the stats added to the item , that can be used on the upgrade system, to check if is a rarityRoll item, then try to upgrade from there, or if is not possible just return false without upgrading ?

Also, any item looted, for example, demon armor instead of 16 armor it gives 20 armor for example, when equiped it gives correctly the Armor to player, but if is a stat custom like [Armor +4] It doesn't sum this Armor to the player.
Elemental damages on weapons, are working, but very special method: rats, dogs, can take element damage, but using Ice enhancement on a dragon doesn't do any ice damage ?

Im using TFS 1.3 old Otservbr

Btwn, amazing system.
This is possible if you edit the original code. I did that and armor/atk and defense changes on an rolled item + the «original» rolls Just isolate those attributes, and edit the code to roll those everytime.
 
Here are the 10.94+ files for the latest version of TFS.
It uses the native Crit and Leech system.

Here is a branch you can simply merge:
Comparison can be found here.


Alternatively, follow the instructions below if you want to install it manually:

You need these commits/changes:
1) Leech fix (If you don't have 👇 your leech amounts will be all messed up)
2) onInventoryUpdate()
3) onSpawn()
@Mateus Robeerto
Post automatically merged:

Here are the 10.94+ files for the latest version of TFS.
It uses the native Crit and Leech system.

Here is a branch you can simply merge:
Comparison can be found here.


Alternatively, follow the instructions below if you want to install it manually:

You need these commits/changes:
1) Leech fix (If you don't have 👇 your leech amounts will be all messed up)
2) onInventoryUpdate()
3) onSpawn()
English: Could you explain to me how I can increase the chance of monsters dropping rare, epic or legendary items? I've already killed several demons and it doesn't drop any rare or epic items... thanks in advance for your help

PTBR: Poderia me explicar como faço para aumentar a chance dos monstros droparem os itens raros, épicos ou lendários ? ja matei varios demons e não dropa nenhum item raro ou épico... desde já agradeço pela ajuda
 
Last edited:
aww getting this error when i try and run it :(

8.6 nekiro 1.5 tfs downgrade


chrome_02CsB7xdOR.png
 
O my you are a godsend!
I went to check Nekiro's original script and noticed that it is quite different from yours... So try using this one, it should work for you

I adapted for you:
Lua:
-- Rarity Animations
local rare_popup = true
local rare_effect = true
local rare_effect_id = CONST_ME_STUN

function Monster:onDropLoot(corpse)
    if hasEventCallback(EVENT_CALLBACK_ONDROPLOOT) then
        EventCallback(EVENT_CALLBACK_ONDROPLOOT, self, corpse)
    end

    -- Apply rarity chance to corpse contents and apply animation
    if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation
        if rare_popup then
            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)
            for i = 1, #spectators do
               spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())
            end
        end
        if rare_effect then
            corpse:getPosition():sendMagicEffect(rare_effect_id)
        end
    end
end

function Monster:onSpawn(position, startup, artificial)
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        self:registerEvent("rollHealth")
        self:registerEvent("rollMana")
        return true
    end
end
 
I went to check Nekiro's original script and noticed that it is quite different from yours... So try using this one, it should work for you

I adapted for you:
Lua:
-- Rarity Animations
local rare_popup = true
local rare_effect = true
local rare_effect_id = CONST_ME_STUN

function Monster:onDropLoot(corpse)
    if hasEventCallback(EVENT_CALLBACK_ONDROPLOOT) then
        EventCallback(EVENT_CALLBACK_ONDROPLOOT, self, corpse)
    end

    -- Apply rarity chance to corpse contents and apply animation
    if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation
        if rare_popup then
            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)
            for i = 1, #spectators do
               spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())
            end
        end
        if rare_effect then
            corpse:getPosition():sendMagicEffect(rare_effect_id)
        end
    end
end

function Monster:onSpawn(position, startup, artificial)
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        self:registerEvent("rollHealth")
        self:registerEvent("rollMana")
        return true
    end
end
This works!! thanks bud.

the only issue is now i get error regarding the loot xD haha


But i fixed this tho :D
 

Attachments

  • WindowsTerminal_v4lNCQkOPR.png
    WindowsTerminal_v4lNCQkOPR.png
    63.8 KB · Views: 23 · VirusTotal
i have this error
Lua:
Lua Script Error: [Event Interface]
data/events/scripts/monster.lua
data/lib/core/attributes.lua:894: attempt to index local 'it_u' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/lib/core/attributes.lua:894: in function 'rollRarity'
        data/events/scripts/monster.lua:7: in main chunk
[Warning - Events::load] Can not load script: monster.lua
I have the same error, were you able to fix it friend?
 
I have the same error, were you able to fix it friend?
Yes this post

 
unfortunately it didn't work, the error disappeared but it doesn't work without using /roll

Is there a way to increase the roll chance?, for testing
 
unfortunately it didn't work, the error disappeared but it doesn't work without using /roll

Is there a way to increase the roll chance?, for testing

In the tiers table you increase the chance, first array is the roll chance, the second is the chance of rolling a second attribute and so on.
Chances is 0 - 10000 based on what you set the local roll value to.

Inside the onDropLoot you have to roll the corpse (which is a container) :
Lua:
for i = 1, #monsterLoot do
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
            rollRarity(corpse)
        end
 
Can anyone tell me where I can find information on how to increase attributes? For example, legendaries come with 4 attributes and epics with 3 attributes... rares with 2 attributes, and so on. I've searched everywhere and can't find it. If you can help me, I'd be grateful, as it saves me time. Thanks.
 
Can anyone tell me where I can find information on how to increase attributes? For example, legendaries come with 4 attributes and epics with 3 attributes... rares with 2 attributes, and so on. I've searched everywhere and can't find it. If you can help me, I'd be grateful, as it saves me time. Thanks.

In the tiers table....
Lua:
    [2] = {
        prefix = 'rare',
        chance = {
            [1] = 1000, -- 1% chance to roll rarity, first colum is used to defined chance of dropping rarity
            [2] = 10000 -- 100% chance for second stat
            [3] = 10000 -- 100% chance for a third stat
        }
    },

You also have to make sure there is enought attributes under ex shield:
Code:
if wp == WEAPON_SHIELD then
                    table.insert(available_stats, stats[2]) -- Defense
                    table.insert(available_stats, stats[30]) -- Skill Shield
 
In the tiers table....
Lua:
    [2] = {
        prefix = 'rare',
        chance = {
            [1] = 1000, -- 1% chance to roll rarity, first colum is used to defined chance of dropping rarity
            [2] = 10000 -- 100% chance for second stat
            [3] = 10000 -- 100% chance for a third stat
        }
    },

You also have to make sure there is enought attributes under ex shield:
Code:
if wp == WEAPON_SHIELD then
                    table.insert(available_stats, stats[2]) -- Defense
                    table.insert(available_stats, stats[30]) -- Skill Shield
Let me understand: if I delete this line:
[1] = 1000, -- 1% chance to roll rarity, first colum is used to defined chance of dropping rarity
[2] = 10000 -- 100% chance for second stat
keeping that line:
[3] = 10000 -- 100% chance for a third stat
And about the shield table you mentioned, I get it. But, will this entry [3] always provide attributes directly? For example, when dropping an item, will it bring 1 attribute, when dropping another, will it bring 2, or will it always be 3 attributes directly? I don't want it to vary; I want it to always be 3 direct attributes.
 
Last edited:
Let me understand: if I delete this line:

keeping that line:

And about the shield table you mentioned, I get it. But, will this entry [3] always provide attributes directly? For example, when dropping an item, will it bring 1 attribute, when dropping another, will it bring 2, or will it always be 3 attributes directly? I don't want it to vary; I want it to always be 3 direct attributes.
If you allways want it to be 3 attributes, then you set the chance to 100% for [2],[3],[4] ( not 100 % sure if this possibly will give 4 attributes or not, you gotta test).
However, to always have 3 attributes, you will need to provide 3 attributes as well. What i explained above is kind of Attribute slots, and they are assigned with an attribute later in the code, which i showed u an example of previous post
 
This part only determines the items that creatures will drop, including the chance of rares and epics, legendary.
[1] = 1000, -- 1% chance to roll rarity, first colum is used to defined chance of dropping rarity
Another part is that, when forging, enchanting and performing other types of improvements, you will use stones to improve these items, you know?
[2] = 10000 -- 100% chance for second stat
When you mentioned that you needed to put [3], I did that and there were a lot of huge errors in the console. It took me about an hour to understand that only [1] and [2] were needed, as I mentioned earlier. 😄
[3] = 10000 -- 100% chance for a third stat

It was just a change in this line, where rare items will come with 2 attributes, epic items with 3, and legendary items with 4, and so on. The problem was already solved.
Lua:
   -- For legendary items, add two extra attributes if less than 4 have already been chosen
    if tier == 3 and #stats_used < 4 then
        for i = #stats_used + 1, 4 do
            if #available_stats > 0 then
                local selected_stat = math.random(1, #available_stats)
                table.insert(stats_used, available_stats[selected_stat])
                table.remove(available_stats, selected_stat)
            end
        end
    end

watch the video

:)
 
Last edited:
This part only determines the items that creatures will drop, including the chance of rares and epics, legendary.

Another part is that, when forging, enchanting and performing other types of improvements, you will use stones to improve these items, you know?

When you mentioned that you needed to put [3], I did that and there were a lot of huge errors in the console. It took me about an hour to understand that only [1] and [2] were needed, as I mentioned earlier. 😄


It was just a change in this line, where rare items will come with 2 attributes, epic items with 3, and legendary items with 4, and so on. The problem was already solved.
Lua:
   -- For legendary items, add two extra attributes if less than 4 have already been chosen
    if tier == 3 and #stats_used < 4 then
        for i = #stats_used + 1, 4 do
            if #available_stats > 0 then
                local selected_stat = math.random(1, #available_stats)
                table.insert(stats_used, available_stats[selected_stat])
                table.remove(available_stats, selected_stat)
            end
        end
    end

watch the video

:)

Then your code is less flexible and there is something else wrong with your code, because when i add new arrays with 100% drop rate, 4 attributes are rolled. I did no other changes than adding arrays on the tier.

You see a rare sword (Atk:17, Atk Spd:1.96s, Def:13 +1).
It weighs 35.00 oz.
(Crit Chance: +4%)
(Attack speed: -40ms)
(Sword fighting: +1)
(Life Leech: +2%)
 
Back
Top