• 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 Function [TFS 1.3] Item abilities via Lua

hello, it's me again, I discovered the error/bug, the Holy, Death and Ice absorption attributes are not correctly added to the item that were loaded only by xml, I compiled your code(from github repo), the only thing I changed was the item(otb and xml) in data folder
funny fact -
absorbpercentelements give
Code:
08:14 You see a rainbow shield (Def:30) (protection energy +8%, earth +8%, fire +8%).
absorbpercentmagic give
Code:
08:15 You see a golden helmet (Arm:12, protection energy +5%, earth +5%, fire +5%).
the most interesting is that the absorbpercentall works correctly
Code:
08:16 You see a magic armor arm (Arm: 17, physical protection + 6%, energy + 6%, earth + 6%, fire + 6%, drown + 6%, ice + 6%, holy + 6%, death + 6%).

data from xml file
Code:
    <item id="8905" article="a" name="rainbow shield">
    <attribute key="description" value="Strange elemental magic flows over this shield." />
    <attribute key="weight" value="6900" />
    <attribute key="defense" value="30" />
    <attribute key="weaponType" value="shield" />
    <attribute key="absorbpercentelements" value="8" />
    </item>

Code:
<item id="2471" article="a" name="golden helmet">
    <attribute key="description" value="It's the famous Helmet of the Stars." />
    <attribute key="weight" value="3200" />
    <attribute key="armor" value="12" />
    <attribute key="slotType" value="head" />
    <attribute key="absorbpercentmagic" value="5" />
    </item>

Code:
    <item id="2472" article="a" name="magic plate armor">
    <attribute key="weight" value="8500" />
    <attribute key="armor" value="17" />
    <attribute key="slotType" value="body" />
    <attribute key="absorbpercentall" value="6" />
    </item>
 
Last edited:
Item abilities is probably the best idea I've ever seen in this website, thanks for it!

Just an update - in order to compile with the current TFS, you will need to replace:
Code:
SPECIALSKILL_HITPOINTSLEECHCHANCE
SPECIALSKILL_HITPOINTSLEECHAMOUNT
SPECIALSKILL_MANAPOINTSLEECHCHANCE
SPECIALSKILL_MANAPOINTSLEECHAMOUNT
for
Code:
SPECIALSKILL_LIFELEECHCHANCE
SPECIALSKILL_LIFELEECHAMOUNT
SPECIALSKILL_MANALEECHCHANCE
SPECIALSKILL_MANALEECHAMOUNT

in combat.cpp, item.cpp and tools.cpp
 
Item abilities is probably the best idea I've ever seen in this website, thanks for it!

Just an update - in order to compile with the current TFS, you will need to replace:
Code:
SPECIALSKILL_HITPOINTSLEECHCHANCE
SPECIALSKILL_HITPOINTSLEECHAMOUNT
SPECIALSKILL_MANAPOINTSLEECHCHANCE
SPECIALSKILL_MANAPOINTSLEECHAMOUNT
for
Code:
SPECIALSKILL_LIFELEECHCHANCE
SPECIALSKILL_LIFELEECHAMOUNT
SPECIALSKILL_MANALEECHCHANCE
SPECIALSKILL_MANALEECHAMOUNT

in combat.cpp, item.cpp and tools.cpp


Iam sorry for being the biggest noobie on here, but where can I find combat.cpp, item.cpp and tools.cpp?
Using TFS 1.3 and Tibia client 10.98.

Appreciate any reply.. well not any, please be gentle XD
 
Iam sorry for being the biggest noobie on here, but where can I find combat.cpp, item.cpp and tools.cpp?
Using TFS 1.3 and Tibia client 10.98.

Appreciate any reply.. well not any, please be gentle XD
thats source related, if you go to tfs github you will see some folders and one of then is called src in reference to sources, there you can find what you looking for.
 
since weapons have special abilities attribute with this modification, is possible to manullay ive this attributes to any item in the item.xml? like giving a magic sword the ability of healt regeneration? o just apply with lua functions to access this attributess?
 
since weapons have special abilities attribute with this modification, is possible to manullay ive this attributes to any item in the item.xml? like giving a magic sword the ability of healt regeneration? o just apply with lua functions to access this attributess?
You can do both, I retained the ability to register them in items.xml, and you can use the item:setAbility function in Lua to set it dynamically to create a unique item, the exact same way it works for attributes (example: armor, defense, attack, etc).
 
is this the correct way to use the abillities? because im using this and is not throwing any error but it doesnt work, i unequip and then equip again object but still not working :(

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2494 then
        local position = player:getPosition()
        target:setAbility(ITEM_ABILITY_REGENERATION, 1)
        target:setAbility(ITEM_ABILITY_HEALTHGAIN, 500)
        target:setAbility(ITEM_ABILITY_HEALTHTICKS, 1)
        player:sendCancelMessage("Health upgrade! 500 hp per second")
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        return true
    end
    return true
end
 
Health ticks use milliseconds, not seconds.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2494 then
        local position = player:getPosition()
        target:setAbility(ITEM_ABILITY_REGENERATION, 1)
        target:setAbility(ITEM_ABILITY_HEALTHGAIN, 500)
        target:setAbility(ITEM_ABILITY_HEALTHTICKS, 1000)
        player:sendCancelMessage("Health upgrade! 500 hp per second")
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
    return true
end
Register 2494 in movements.xml as well.
 
Health ticks use milliseconds, not seconds.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2494 then
        local position = player:getPosition()
        target:setAbility(ITEM_ABILITY_REGENERATION, 1)
        target:setAbility(ITEM_ABILITY_HEALTHGAIN, 500)
        target:setAbility(ITEM_ABILITY_HEALTHTICKS, 1000)
        player:sendCancelMessage("Health upgrade! 500 hp per second")
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
    return true
end
Register 2494 in movements.xml as well.
wow this works awesome !!!!!!!!
 
Is anyone experiencing something weird with the mana/life leech or is it just me? they are damaging the player instead of healing it, after the changes from this topic (also applied the reflection bonus)
 
hi, i was trying to add a new ability to work just like ITEM_ABILITY_REGENERATION (as a flag), so following what indicates Here
i edited enums.h, item.cpp, item.h, items.cpp, items.h, luascript.cpp.
just added my new abilities in all files where this was involved
ITEM_ABILITY_
ABILITY_
ITEM_PARSE_

it compiled with no errors but the getAbility() lua function returns nil when i try to get the value i just readed again all i edited and all seems to be ok so maybe i forget to do something? or there is something else that is not in that repo that im missing in my code too?
thanks if anyone can help me! :)
 
You need to update the bitmask located in item.h inside isAbility.
Lua: demo (http://www.lua.org/cgi-bin/demo)
Lua:
local newAbility = 1 << 46
print(string.format('0x%x', 0x3fffffffffff | newAbility))
This will print the new bitmask, replace it and recompile.
ok going to try thank you a lot! just a question that << 46 its the number of the last ability registered in enums.h? if i decide to add more abilities? or its always the same to get the new bitmask?
 
ok going to try thank you a lot! just a question that << 46 its the number of the last ability registered in enums.h? if i decide to add more abilities? or its always the same to get the new bitmask?
You have to update the bitmask for each new ability you add, if you add a new one in enums.h you'll use 1 << 47, then you'll have to add that to the bitmask and re-update. The bitmask is the result of all bit shifts, meaning that what I just posted there was done 45 times before, each for 1 << N where x is the number of bits to shift left. These act like flags in binary, you're pushing the binary value of 1 N places to the left, which is a unique flag. Each new ability you add you must update the bitmask to include the Nth flag, otherwise you'll be comparing that flag to the bitmask which doesn't have it set.
 
is there something else to do with new abilities added? because i added 3 new abilities actually working but they just disappear when i log out if the item is equiped or inside the backpack, if i leave there in the floor they keep the ability(pz and no pz floor).
thanks in advice
 
is there something else to do with new abilities added? because i added 3 new abilities actually working but they just disappear when i log out if the item is equiped or inside the backpack, if i leave there in the floor they keep the ability(pz and no pz floor).
thanks in advice

replacing ABILITY_END = ABILITY_BONUSHEALING in items.cpp, for the last new ability added above fixed the issue.

C++:
ABILITY_DAMAGEMITIGATION = 47,
ABILITY_BONUSREGEN = 48,
ABILITY_MAGICDAMAGE = 49,
ABILITY_SUPPORTHEALING = 50,
ABILITY_ATTACKSPEED = 51,
ABILITY_FLEXSKILL = 52,
ABILITY_BONUSHEALING = 53,
ABILITY_NEWABILITY = 54,
ABILITY_START = ABILITY_HEALTHGAIN,
ABILITY_END = ABILITY_REGENERATION

ABILITY_END = ABILITY_NEWABILITY
 
Back
Top