• 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

Follow installation perfectly. I went ahead and used the newest TFS build and did everything manually one step at a time using the comparison tool from github. No issues on my end everything is working flawlessly :D
 
Follow installation perfectly. I went ahead and used the newest TFS build and did everything manually one step at a time using the comparison tool from github. No issues on my end everything is working flawlessly :D

Im using otx because tfs dont support tibia 12.15
 
the script was working fine until, so recently i was checking pvp and i realized paladins are doing 0 damage to players on the oppsite they are healing them, so i thought it's a problem with spells, and i rechecked everything is fine, then i look at console everytime paladin attacks with normal weapon with spell on another player this error comes:
Lua:
data/creaturescripts/scripts/attributes.lua:onHealthChange
data/creaturescripts/scripts/attributes.lua:585: attempt to index a nil value stack traceback:
[c] in function '_index'
data/creaturescripts/scripts/attributes.lua:585: in function 'stat change'

data/creaturescripts/scripts/attributes.lua:683: in function <data/creaturescripts/scripts/attributes.lua:680>

[C]: at 0x013f93e040
any help please, thank you! using TFS 1.3x downgraded by neeko 8.6

couldn't post attributes because of word limit

Line 585 :
Lua:
if resistances[primaryType].Custom ~= 0 then
Line 683:
Code:
primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
 
Last edited:
the script was working fine until, so recently i was checking pvp and i realized paladins are doing 0 damage to players on the oppsite they are healing them, so i thought it's a problem with spells, and i rechecked everything is fine, then i look at console everytime paladin attacks with normal weapon with spell on another player this error comes:
Lua:
data/creaturescripts/scripts/attributes.lua:onHealthChange
data/creaturescripts/scripts/attributes.lua:585: attempt to index a nil value stack traceback:
[c] in function '_index'
data/creaturescripts/scripts/attributes.lua:585: in function 'stat change'

data/creaturescripts/scripts/attributes.lua:683: in function <data/creaturescripts/scripts/attributes.lua:680>

[C]: at 0x013f93e040
any help please, thank you! using TFS 1.3x downgraded by neeko 8.6

couldn't post attributes because of word limit

Line 585 :
Lua:
if resistances[primaryType].Custom ~= 0 then
Line 683:
Code:
primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula

replace:
Lua:
--if primaryType ~= 0 then
    if resistances[primaryType].Custom ~= 0 then
        local resistancePercent = (100 - resistances[primaryType].Custom)
        primaryDamage = (resistancePercent / 100) * primaryDamage
    end
--end

with:
Lua:
if resistances[primaryType] then
    if resistances[primaryType].Custom ~= 0 then
        local resistancePercent = (100 - resistances[primaryType].Custom)
        primaryDamage = (resistancePercent / 100) * primaryDamage
    end
end

I'll fix this in main post.
 
replace:
Lua:
--if primaryType ~= 0 then
    if resistances[primaryType].Custom ~= 0 then
        local resistancePercent = (100 - resistances[primaryType].Custom)
        primaryDamage = (resistancePercent / 100) * primaryDamage
    end
--end

with:
Lua:
if resistances[primaryType] then
    if resistances[primaryType].Custom ~= 0 then
        local resistancePercent = (100 - resistances[primaryType].Custom)
        primaryDamage = (resistancePercent / 100) * primaryDamage
    end
end

I'll fix this in main post.
works perfectly now!,
Thank you!
 
I am use Otx 10.99 and not work for me, when start server get this message:
Lua:
Lua Script Error: [Event Interface]
data/events/scripts/creature.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/creature.lua:48: in main chunk
[Warning - Events::load] Can not load script: creature.lua

>> Loading monsters

And when I say "/roll" get this message:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/roll.lua:onSay
data/lib/core/tables.lua:17: bad argument #1 to 'pairs' (table expected, got number)
stack traceback:
        [C]: at 0x7ff71f543700
        [C]: in function 'pairs'
        data/lib/core/tables.lua:17: in function 'contains'
        data/lib/core/attributes.lua:987: in function 'rollRarity'
        data/talkactions/scripts/roll.lua:30: in function <data/talkactions/scripts/roll.lua:1>

where is the problem?

thanks god job
 
hello @Leo32 wanted to know why the status of mana, life, rextra and critical damage is not showing. i'm using otbr.
1593629845382.png
 
hello @Leo32 wanted to know why the status of mana, life, rextra and critical damage is not showing. i'm using otbr.
View attachment 47068

Replace
Code:
CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT 
CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE 
CONDITION_PARAM_SPECIALSKILL_LIFELEECHCHANCE 
CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT 
CONDITION_PARAM_SPECIALSKILL_MANALEECHCHANCE 
CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT
with
Code:
CONDITION_PARAM_SKILL_CRITICAL_HIT_DAMAGE
CONDITION_PARAM_SKILL_CRITICAL_HIT_CHANCE
CONDITION_PARAM_SKILL_LIFE_LEECH_CHANCE
CONDITION_PARAM_SKILL_LIFE_LEECH_AMOUNT
CONDITION_PARAM_SKILL_MANA_LEECH_CHANCE
CONDITION_PARAM_SKILL_MANA_LEECH_AMOUNT
 
como colocar chance de roll quando dropar os itens nos monstros raro=20% epic= 10% lendary=5%
and how to add a 3rd slot?
 
how i can remove double loot?
 
Last edited:
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
 
< 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.
Multishot dont work with Quiver system do you can help?
Dont shot more target and dont remove arrows. Read no arrows maybe something with scan quiver?
 
Multishot dont work with Quiver system do you can help?
Dont shot more target and dont remove arrows. Read no arrows maybe something with scan quiver?

Need to change these lines:

to scan for quiver and get ammo
and return different ammoSlot in the line below:

Lua:
local ammoSlot = XXXXXXX
 
Amazing work, thank you very much. I wonder if this lags with 50-200 playerbase server? I might consider porting (someof) these changes to CPP in order to gain memory optimization space.

EDIT: Maybe also the option to increase level requirement per rarity tier, similar to zbizu's system?
 
Can anyone put this system to the new version 12.60 of the OTBR server?
I tried to implement some more things are different in soucer
 
Hi leo32, This script is amazing.. I'm doing a lot of tests on TFS 1.3 (12.60+) and got erro with some attributes (without erros in cmd).
  • All Resistence attributes
  • All Enhanced Damage
  • Spell Damage

The attributes mentioned above don't work.
I tried to modify the script but I didn't find the solution, do you have any suggestions?
 
The otbr 12.60 its more diferent, and need a lot of work....
I'm trying to adapt to otbr 12.64
But it is difficult, can someone progress on something? Or have some similar script

A variant of this system would be interesting, without changing the source and using everything possible for this situation.

FLP
 
Last edited:
Back
Top