• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua doItemSetAttribute (Attribute not seting)

gabriel28

Active Member
Joined
Mar 16, 2012
Messages
200
Solutions
6
Reaction score
25
I has trying to make a script (action) that adds elemental defence in one item, but the script doesn't work. Someone that have knowlege and can help me with it, I'll be very thankful.
That's my trying:

local config = {
FdefBonus = 2, --Fire defense in %.
failChance = 30, --Fail chance in percent.
types = {"armor", "legs", "helmet", "boots", "shield"},
noFdef = {1, 2, 3, 9, 10} --Kind of items blocked
}
function onUse(cid, item, fromPos, itemEx, toPos)
if itemEx.itemid < 100 then
return doPlayerSendCancel(cid, "Use this in valid itens.")
elseif isInArray(config.noFdef, getItemWeaponType(itemEx.uid)) then
return doPlayerSendCancel(cid, "Use this in valid itens.")
elseif getItemAttribute(itemEx.uid, "absorbPercentFire") then
return doPlayerSendCancel(cid, "This item has already a fire defense bonus.")
elseif math.random(1, 100) > config.failChance then
return doPlayerSendTextMessage(cid, 27, "Sorry, your item didn't get a fire defense bonus. Good luck at the next try!"), doRemoveItem(item.uid, 1)
end
local checkItemName
for i = 1, #config.types do
if getItemNameById(itemEx.itemid):find(config.types) then
checkItemName = true
break
end
end
if not checkItemName then
return doPlayerSendCancel(cid, "Use this in valid itens.")
end
doPlayerSendTextMessage(cid, 27, "Congratulations, now your item has a sire defense bonus of "..config.FdefBonus.."%!")
doItemSetAttribute(itemEx.uid, "absorbPercentFire", config.FdefBonus)
doItemSetAttribute(itemEx.uid, "name", getItemName(itemEx.uid).." ref "..config.FdefBonus.."%")
doRemoveItem(item.uid, 1)
return true
end
 
From what I can see in sources of TFS 0.3/0.4 "absorbPercentFire" is not a valid key for attribute.

Here is list of valid, integer (number) attributes:
Code:
Line 383:     const int32_t* v = getIntegerAttribute("attack");
    Line 392:     const int32_t* v = getIntegerAttribute("extraattack");
    Line 401:     const int32_t* v = getIntegerAttribute("defense");
    Line 410:     const int32_t* v = getIntegerAttribute("extradefense");
    Line 419:     const int32_t* v = getIntegerAttribute("armor");
    Line 428:     const int32_t* v = getIntegerAttribute("attackspeed");
    Line 437:     const int32_t* v = getIntegerAttribute("hitchance");
    Line 446:     const int32_t* v = getIntegerAttribute("shootrange");
    Line 464:     const int32_t* v = getIntegerAttribute("duration");
    Line 471:     const int32_t* v = getIntegerAttribute("duration");
    Line 498:     const int32_t* v = getIntegerAttribute("date");
    Line 516:     const int32_t* v = getIntegerAttribute("aid");
    Line 525:     const int32_t* v = getIntegerAttribute("uid");
    Line 534:     const int32_t* v = getIntegerAttribute("charges");
    Line 543:     const int32_t* v = getIntegerAttribute("fluidtype");
    Line 552:     const int32_t* v = getIntegerAttribute("owner");
    Line 561:     const int32_t* v = getIntegerAttribute("corpseowner");
    Line 570:     const int32_t* v = getIntegerAttribute("decaying");

I also found that absorb percent you can configure in vocations.xml file.

Usage:
Code:
<absorb percentAll="x" percentElements="x" percentEnergy="x">

So maybe new vocation with specified absorb percent would be a solution?
 
But the attributes that can be set in items.xml is not valid to put in a script aside?
So I need to make a C++ function to do that?
 
But the attributes that can be set in items.xml is not valid to put in a script aside?
So I need to make a C++ function to do that?

Yeah, not all of them all supported. Just some basic ones like name, description, attackspeed etc.

You need to add new attribute support in sources, yes.

Shouldn't be hard. Here's example for attackspeed:
Code:
inline int32_t Item::getAttackSpeed() const
{
    const int32_t* v = getIntegerAttribute("attackspeed");
    if(v)
        return *v;

    return items[id].attackSpeed;
}

You would need to add function like this and then use it in correct place, where absorb percent are used.

Most likely you will need to modify this part:
Code:
        if(it.abilities.absorb[combatType])
        {
            blocked += (int32_t)std::ceil((double)(damage * it.abilities.absorb[combatType]) / 100.);
            if(item->hasCharges())
                g_game.transformItem(item, item->getID(), std::max((int32_t)0, (int32_t)item->getCharges() - 1));
        }

To use your new absorb functions.
 
abilities don't work the same way attributes do, there's much more to change if you want it to work like an attribute
 
i made it myself, it's not changing from ability to attribute, it's just its own attribute
plus i made it for 1.2, no clue how it would be for 0.4
 
i made it myself, it's not changing from ability to attribute, it's just its own attribute
plus i made it for 1.2, no clue how it would be for 0.4

If I do that, I'll need to make for every elemente I want, right?

From what I can see in sources of TFS 0.3/0.4 "absorbPercentFire" is not a valid key for attribute.

Here is list of valid, integer (number) attributes:
Code:
Line 383:     const int32_t* v = getIntegerAttribute("attack"); (..........)
I also found that absorb percent you can configure in vocations.xml file.
Usage:
Code:
<absorb percentAll="x" percentElements="x" percentEnergy="x">
So maybe new vocation with specified absorb percent would be a solution?

What file do I find this in? (The list of attibutes)
I know about that in vocations.xml, but is not a solution, because I wanna made a stone that put absorb percent in an item, so player can try to make a set with full element resistence.
 
Back
Top