Lua Function [TFS 1.3] Item abilities via Lua

Togu

Active Member
Joined
Jun 22, 2018
Messages
141
Best answers
0
Likes
29
Location
Brazil
#21
Thanks for the explaining. Gonna wait you solve the house issue.

Don't know why but the automatic quest system (where you just put item id in unique id of the normal chest) stopped working. And when looking on item it is missing a ")".
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#22
Update: Save & load house items with abilities with tile_store
SQL Query:
SQL:
ALTER TABLE `tile_store` ADD `abilities` BLOB NOT NULL;
thanks to @QuaS for pointing this out

Thanks for the explaining. Gonna wait you solve the house issue.

Don't know why but the automatic quest system (where you just put item id in unique id of the normal chest) stopped working. And when looking on item it is missing a ")".
can you tell me what item(s) are in the chest so i can try to reproduce on my end and confirm that it's a bug with this system?
can you also show the full description of the item with the missing )?
 

Togu

Active Member
Joined
Jun 22, 2018
Messages
141
Best answers
0
Likes
29
Location
Brazil
#26
did you actually test or confirm? or are you just guessing


abilities are loaded primarily through items.xml, but if you already set an ability on an item through lua it will prioritize that instead of the loaded ability from items.xml
here's a full example for adding critical chance permanently to a weapon using a flawless ice crystal as an upgrader
XML:
<action itemid="8300" script="crit.lua" />
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isItem() then
        return false
    end
    local position = (toPosition.x ~= 65535 and toPosition or player:getPostion())
    target:setAbility(ITEM_ABILITY_CRITICALCHANCE, math.random(1, 100))
    target:setAbility(ITEM_ABILITY_CRITICALDAMAGE, math.random(1, 100))
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    item:remove()
    return true
end
Flawless ice crystal used on a sword and on a magic sword, the effect appears but in the OTClient the Critical Chance and Critical Damage doesn't change, no errors in terminal. And the item still with the same look:

19:59 You see a sword (Atk:14, Def:12 +1).
It weighs 35.00 oz.

20:00 You see a magic sword (Atk:48, Def:35 +3).
It can only be wielded properly by players of level 80 or higher.
It weighs 42.00 oz.
It's the Sword of Valor.
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#27
Flawless ice crystal used on a sword and on a magic sword, the effect appears but in the OTClient the Critical Chance and Critical Damage doesn't change, no errors in terminal. And the item still with the same look:

19:59 You see a sword (Atk:14, Def:12 +1).
It weighs 35.00 oz.

20:00 You see a magic sword (Atk:48, Def:35 +3).
It can only be wielded properly by players of level 80 or higher.
It weighs 42.00 oz.
It's the Sword of Valor.
  • Items that are not loaded through movements.xml will not register abilities
  • Weapons that are loaded through weapons.xml will not register abilities
 

Togu

Active Member
Joined
Jun 22, 2018
Messages
141
Best answers
0
Likes
29
Location
Brazil
#28
can you tell me what item(s) are in the chest so i can try to reproduce on my end and confirm that it's a bug with this system?
can you also show the full description of the item with the missing )?
20:08 You see a magic sword (Atk:48, Def:35 +3).
It can only be wielded properly by players of level 80 or higher.
It weighs 42.00 oz.
It's the Sword of Valor.
Item ID: 2400
Position: 32975, 31284, 6

20:08 You see a blacksteel sword (Atk:42, Def:22.
It can only be wielded properly by players of level 35 or higher.
It weighs 59.00 oz.
This sword is only granted to a greenhorn of the Svargrond arena.
Item ID: 7406
Position: 32975, 31284, 6

20:08 You see a studded shield (Def:15.
It weighs 58.00 oz.
Item ID: 2526
Position: 32975, 31284, 6

Magic Sword is working cause I've put
Code:
s << "Def:" << defense;
                   if (extraDefense != 0) {
                       s << ' ' << std::showpos << extraDefense << ")" << std::noshowpos;
                   }
Gonna fix it here in my code.
 

Togu

Active Member
Joined
Jun 22, 2018
Messages
141
Best answers
0
Likes
29
Location
Brazil
#29
  • Items that are not loaded through movements.xml will not register abilities
  • Weapons that are loaded through weapons.xml will not register abilities
movements.xml
XML:
<!-- leather boots -->
<movevent event="Equip" itemid="2643" slot="feet" function="onEquipItem"/>
<movevent event="DeEquip" itemid="2643" slot="feet" function="onDeEquipItem" />
actions.xml
XML:
<action itemid="8300" script="crit.lua" />
actions/scripts/crit.lua
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
Lua:
    if not target:isItem() then
        return false
    end
    local position = (toPosition.x ~= 65535 and toPosition or player:getPosition())
    target:setAbility(ITEM_ABILITY_CRITICALCHANCE, math.random(1, 100))
    target:setAbility(ITEM_ABILITY_CRITICALDAMAGE, math.random(1, 100))
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    item:remove()
    return true
end
look:
Code:
20:26 You see leather boots (Arm:1).
It weighs 9.00 oz.
Nothing happens after red magic effect. No errors on terminal.
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#30
movements.xml
XML:
<!-- leather boots -->
<movevent event="Equip" itemid="2643" slot="feet" function="onEquipItem"/>
<movevent event="DeEquip" itemid="2643" slot="feet" function="onDeEquipItem" />
actions.xml
XML:
<action itemid="8300" script="crit.lua" />
actions/scripts/crit.lua
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
Lua:
    if not target:isItem() then
        return false
    end
    local position = (toPosition.x ~= 65535 and toPosition or player:getPosition())
    target:setAbility(ITEM_ABILITY_CRITICALCHANCE, math.random(1, 100))
    target:setAbility(ITEM_ABILITY_CRITICALDAMAGE, math.random(1, 100))
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    item:remove()
    return true
end
look:
Code:
20:26 You see leather boots (Arm:1).
It weighs 9.00 oz.
Nothing happens after red magic effect. No errors on terminal.
it technically does work i just completely forgot to add the description to Item::getDescription in item.cpp
working on a fix (fixing defense missing a ')') too

wait i didn't forget, i just used the wrong enums for setAbility
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isItem() then
        return false
    end
    local position = (toPosition.x ~= 65535 and toPosition or player:getPosition())
    target:setAbility(ITEM_ABILITY_CRITICALHITCHANCE, math.random(1, 100))
    target:setAbility(ITEM_ABILITY_CRITICALHITDAMAGE, math.random(1, 100))
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    item:remove()
    return true
end
 
Last edited by a moderator:

Togu

Active Member
Joined
Jun 22, 2018
Messages
141
Best answers
0
Likes
29
Location
Brazil
#32
Leather Boots with random critical chance and random critical damage after using flawless ice crystal on it

add in movements/movements.xml (the item has to be in this file or it won't work)
XML:
<!-- leather boots -->
<movevent event="Equip" itemid="2643" slot="feet" function="onEquipItem"/>
<movevent event="DeEquip" itemid="2643" slot="feet" function="onDeEquipItem" />
add in actions/actions.xml
XML:
<!-- flawless ice crystal inserting critical -->
<action itemid="8300" script="crit.lua" />
add in actions/scripts/crit.lua
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isItem() then
        return false
    end
    local position = (toPosition.x ~= 65535 and toPosition or player:getPosition())
    target:setAbility(ITEM_ABILITY_CRITICALHITCHANCE, math.random(1, 100))
    target:setAbility(ITEM_ABILITY_CRITICALHITDAMAGE, math.random(1, 100))
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    item:remove()
    return true
end
 

_M4G0_

Active Member
Joined
Feb 6, 2016
Messages
384
Best answers
12
Likes
64
#33
Update: Save & load house items with abilities with tile_store
SQL Query:
SQL:
ALTER TABLE `tile_store` ADD `abilities` BLOB NOT NULL;
thanks to @QuaS for pointing this out


can you tell me what item(s) are in the chest so i can try to reproduce on my end and confirm that it's a bug with this system?
can you also show the full description of the item with the missing )?
replace it ?
Update: Save & load house items with abilities with tile_store · Vulcanx/[email protected]
 

Togu

Active Member
Joined
Jun 22, 2018
Messages
141
Best answers
0
Likes
29
Location
Brazil
#35
Leather boots with mana leech chance 100 and mana leech amount 1000 working (but the client limit shows value 100);
Leather boots with mana health chance 100 and health leech amount 1000 working (but the client limit shows value 100);
Leather boots with critical hit chance 100 and critical hit amount 1000 not working? Look at this formula:
PHP:
chance = attackerPlayer->getSpecialSkill(SPECIALSKILL_CRITICALHITCHANCE);
           if (chance != 0 && uniform_random(1, 100) <= chance) {
               healthChange += std::round(healthChange * (attackerPlayer->getSpecialSkill(SPECIALSKILL_CRITICALHITAMOUNT) / 100.));
               g_game.addMagicEffect(target->getPosition(), CONST_ME_CRITICAL_DAMAGE);
           }
So, if the critical hit amount is 100 (like the client shows), the healthChange will be multipied by 1?
Im getting critical hit every attack (cause the chance is 100), but the damage values looks like normal values, I did a critical hit of 2, 4 and 6 damage in sequence with skill 21 and magic sword in an Orc Warrior.

Bug found: if I remove ability with an equiped item the special skills aren't removed.
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#36
Leather boots with mana leech chance 100 and mana leech amount 1000 working (but the client limit shows value 100);
Leather boots with mana health chance 100 and health leech amount 1000 working (but the client limit shows value 100);
Leather boots with critical hit chance 100 and critical hit amount 1000 not working? Look at this formula:
PHP:
chance = attackerPlayer->getSpecialSkill(SPECIALSKILL_CRITICALHITCHANCE);
           if (chance != 0 && uniform_random(1, 100) <= chance) {
               healthChange += std::round(healthChange * (attackerPlayer->getSpecialSkill(SPECIALSKILL_CRITICALHITAMOUNT) / 100.));
               g_game.addMagicEffect(target->getPosition(), CONST_ME_CRITICAL_DAMAGE);
           }
So, if the critical hit amount is 100 (like the client shows), the healthChange will be multipied by 1?
Im getting critical hit every attack (cause the chance is 100), but the damage values looks like normal values, I did a critical hit of 2, 4 and 6 damage in sequence with skill 21 and magic sword in an Orc Warrior.

Bug found: if I remove ability with an equiped item the special skills aren't removed.
Update: Fix critical hits not working
 

_M4G0_

Active Member
Joined
Feb 6, 2016
Messages
384
Best answers
12
Likes
64
#37
someone can post compiled source for test absorb %, in my source dont work and i have errors on compiling original source
 
Top