• 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+ [tfs 1.3] getAttribute(ITEM_ATTRIBUTE_ARMOR) returns ever 0

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
HI!
Im trying to use this script upgrading for 1.3, but it gives error. I cant upgrade any items (helmet, armor, legs, boots, etc.... i can upgrade only weapons).
Because this part, at line 47, every time return 0 (when i try to use in armor, legs, boots, etc).
Code:
itemEx.uid:getAttribute(ITEM_ATTRIBUTE_ARMOR) > 0)
 
Solution
add this in your global.lua and use these auxiliary functions
Lua:
function getItemAttribute(uid, key)
    local i = ItemType(Item(uid):getId())
    local string_attributes = {
    [ITEM_ATTRIBUTE_NAME] = i:getName(),
    [ITEM_ATTRIBUTE_ARTICLE] = i:getArticle(),
    [ITEM_ATTRIBUTE_PLURALNAME] = i:getPluralName(),
    ["name"] = i:getName(),
    ["article"] = i:getArticle(),
    ["pluralname"] = i:getPluralName() }

    local numeric_attributes = {
    [ITEM_ATTRIBUTE_WEIGHT] = i:getWeight(),
    [ITEM_ATTRIBUTE_ATTACK] = i:getAttack(),
    [ITEM_ATTRIBUTE_DEFENSE] = i:getDefense(),
    [ITEM_ATTRIBUTE_EXTRADEFENSE] = i:getExtraDefense(),
    [ITEM_ATTRIBUTE_ARMOR] = i:getArmor(),
    [ITEM_ATTRIBUTE_HITCHANCE] = i:getHitChance(),
    [ITEM_ATTRIBUTE_SHOOTRANGE] = i:getShootRange(),
    ["weight"] = i:getWeight(),
    ["attack"] = i:getAttack(),
    ["defense"] = i:getDefense(),
    ["extradefense"] = i:getExtraDefense(),
    ["armor"] =...
That's not being executed on an item userdata, it's being executed on a number. Remove the .uid portion of that line.
 
Lua:
print(itemEx:getAttribute(ITEM_ATTRIBUTE_ARMOR))
returning 0 too, in armor,legs,boots, etc..
The item probably doesn't have a custom attribute already set, so getAttribute will return 0 if it has no attribute set to it before. If you're looking to get the default armor of the item use itemType:getArmor().
Lua:
local armor = itemEx:getAttribute(ITEM_ATTRIBUTE_ARMOR)
armor = armor > 0 and armor or itemEx:getType():getArmor()
print(armor)
 
The item probably doesn't have a custom attribute already set, so getAttribute will return 0 if it has no attribute set to it before. If you're looking to get the default armor of the item use itemType:getArmor().
Lua:
local armor = itemEx:getAttribute(ITEM_ATTRIBUTE_ARMOR)
armor = armor > 0 and armor or itemEx:getType():getArmor()
print(armor)
i want to check if its a item that can be upgraded by a stone, in your opinion i need to check all atributes?
check if is armor,legs,boots, shield, etc?
 
need to be a item with armor or attack or defense.
for exemple, i cant upgrade a torch, a bag, a rope, and etc (because its not a equipament)
If you want that kind of customization you should just go look for a new upgrade script, or learn how to do it yourself. If you'd like to do it yourself, create a table with item ids as the keys and define all attributes that can be upgraded linked to that id, and when you attempt to upgrade check that table for the target itemid, handle it.
 
If you want that kind of customization you should just go look for a new upgrade script, or learn how to do it yourself. If you'd like to do it yourself, create a table with item ids as the keys and define all attributes that can be upgraded linked to that id, and when you attempt to upgrade check that table for the target itemid, handle it.
so this system is bugged?
because only the weapons can be upgraded
 
so this system is bugged?
because only the weapons can be upgraded
I couldn't tell you if it's bugged or not, I'm not the one using it. What I can say is that it's missing a lot of things you're probably looking for such as explicitly defining items and attributes. The script you're using currently just handles items in general and just tries to buff their stats as a blanket instead of treating them individually.
 
add this in your global.lua and use these auxiliary functions
Lua:
function getItemAttribute(uid, key)
    local i = ItemType(Item(uid):getId())
    local string_attributes = {
    [ITEM_ATTRIBUTE_NAME] = i:getName(),
    [ITEM_ATTRIBUTE_ARTICLE] = i:getArticle(),
    [ITEM_ATTRIBUTE_PLURALNAME] = i:getPluralName(),
    ["name"] = i:getName(),
    ["article"] = i:getArticle(),
    ["pluralname"] = i:getPluralName() }

    local numeric_attributes = {
    [ITEM_ATTRIBUTE_WEIGHT] = i:getWeight(),
    [ITEM_ATTRIBUTE_ATTACK] = i:getAttack(),
    [ITEM_ATTRIBUTE_DEFENSE] = i:getDefense(),
    [ITEM_ATTRIBUTE_EXTRADEFENSE] = i:getExtraDefense(),
    [ITEM_ATTRIBUTE_ARMOR] = i:getArmor(),
    [ITEM_ATTRIBUTE_HITCHANCE] = i:getHitChance(),
    [ITEM_ATTRIBUTE_SHOOTRANGE] = i:getShootRange(),
    ["weight"] = i:getWeight(),
    ["attack"] = i:getAttack(),
    ["defense"] = i:getDefense(),
    ["extradefense"] = i:getExtraDefense(),
    ["armor"] = i:getArmor(),
    ["hitchance"] = i:getHitChance(),
    ["shootrange"] = i:getShootRange() }

    local attr = Item(uid):getAttribute(key)
    if tonumber(attr) then
        if numeric_attributes[key] then
            return attr ~= 0 and attr or numeric_attributes[key]
        end
    else
        if string_attributes[key] then
            if attr == "" then
                return string_attributes[key]
            end
        end
    end
    return attr
end

function doItemSetAttribute(uid, key, value)
    return Item(uid):setAttribute(key, value)
end

function doItemEraseAttribute(uid, key)
    return Item(uid):removeAttribute(key)
end

examples:
Lua:
doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR, 100)
print(getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR))
 
Solution
how can i check if target is a item?
if i use this item in a monster,npc or player get error in console, because he try do getAttributee..
Lua:
    local armor = itemEx:getAttribute(ITEM_ATTRIBUTE_ARMOR)
    armor = armor > 0 and armor or itemEx:getType():getArmor()

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:onUse
data/actions/scripts/upgrading.lua:53: attempt to call method 'getAttribute' (a nil value)
stack traceback:
        [C]: in function 'getAttribute'
        data/actions/scripts/upgrading.lua:53: in function <data/actions/scripts/upgrading.lua:49>
 
Back
Top