• 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!

C++ tfs 1.3 item description

emil92b

Intermediate OT User
Joined
Aug 21, 2013
Messages
335
Solutions
13
Reaction score
135
Location
Sweden
im trying to make it so items with an armor value of 0 or greater will show up in description and aswell show other attributes such as absorbPercentFire even if the armor value is 0, without the need of setting 'showattributes' to true.

C++:
 else if (it.armor != 0 || (item && item->getArmor() != 0) || it.showAttributes) {
        bool begin = true;

        int32_t armor = (item ? item->getArmor() : it.armor);
        if (armor != 0) {
            s << " (Arm:" << armor;
            begin = false;
        }


example:
Lua:
<item id="1000" name="test item">
    <attribute key="armor" value="0"/>
    <attribute key="absorbPercentFire" value="20"/>
</item>

how it currently output:
You see test item.

how it should output:
You see test item (Arm: 0, protection fire +20%).


tfs 1.3 *
 
Last edited:
Solution
think you misunderstood, i want to have armor: 0 displayed for items, just not on items that doesn't t even have that attribute for example rope

so on items that has 0 or greater, should be displayed
Lua:
<attribute key="armor" value="0"/>

Okay, I see. Clearly misunderstood then. Well, if that's the case then I don't think you can easily achieve that, if you track down Item::getArmor() method, you will see it returns either attribute or ItemType::armor value, which is 0 by default. So whether you specify armor with value 0 in items.xml or just leave this one out, in TFS, it's going to be 0. You could initialize it to -1 in ItemType class declaration (items.h), but then you also need to track all code fragments that use it and...
So remove || (item && item->getArmor() != 0) as well
C++:
else if (it.armor != 0 || it.showAttributes) {
        bool begin = true;

        int32_t armor = (item ? item->getArmor() : it.armor);
        s << " (Arm:" << armor;
        begin = false;

still same output
 
Well you can't let it check if armor is not 0 anywhere if you want it to work.
What distro are you using? You have failed to write it in the thread like many others.
 
Not really sure if this work. Would be easier if the initial value on armor would be -1, then you could check for that instead. Now Armor might show everywhere!

C++:
else if (it.showAttributes) {
    bool begin = true;

    s << " (Arm:" << armor;
    begin = false;
 
i kept it like this else armor would be undefined
C++:
else if (it.showAttributes) {
        bool begin = true;

        int32_t armor = (item ? item->getArmor() : it.armor);
        s << " (Arm:" << armor;
        begin = false;

same output, only difference i noticed was that items doesn't display armor or attributes values at all now

if i do something like
C++:
else if (item->getArmor() >= 0 || it.showAttributes) {

it works as i want,however it shows arm: 0 on items that doesn't even have an armor attribute
 
Last edited:
i kept it like this else armor would be undefined
C++:
else if (it.showAttributes) {
        bool begin = true;

        int32_t armor = (item ? item->getArmor() : it.armor);
        s << " (Arm:" << armor;
        begin = false;

same output, only difference i noticed was that items doesn't display armor or attributes values at all now
C++:
 else {
        bool begin = false;

        int32_t armor = (item ? item->getArmor() : it.armor);
        s << " (Arm:" << armor;
you need to not use it.showAttributes because you said you weren't going to use showattributes in the xml
also no point in having begin be assigned to true then set to false right after
 
if i move it down to the else statement, other items such i said before gets an armor value of 0 without having the attribute itself

Lua:
You see test item (Arm: 0, protection fire +20%).

You see a rope (Arm:0).
It weighs 18.00 oz.

you need to not use it.showAttributes because you said you weren't going to use showattributes in the xml
thats true, but i might wanna use it for other items that doesn't use armor
 
Last edited:
C++:
 else if (it.armor != 0 || (item && item->getArmor() != 0)) {
        bool begin = true;
        int32_t armor = (item ? item->getArmor() : it.armor);
        if (armor != 0) {
            s << " (Arm:" << armor;
            begin = false;
        }

This will only work for armor (so any item with armor that is not 0 will have armor attribute displayed). The rest of them (absorbPercent, etc.) may have other conditions, but basically you need to look for code fragments that checks for given attribute and remove it.showAttributes from there like I just did for armor.
 
C++:
 else if (it.armor != 0 || (item && item->getArmor() != 0)) {
        bool begin = true;
        int32_t armor = (item ? item->getArmor() : it.armor);
        if (armor != 0) {
            s << " (Arm:" << armor;
            begin = false;
        }

This will only work for armor (so any item with armor that is not 0 will have armor attribute displayed). The rest of them (absorbPercent, etc.) may have other conditions, but basically you need to look for code fragments that checks for given attribute and remove it.showAttributes from there like I just did for armor.
think you misunderstood, i want to have armor: 0 displayed for items, just not on items that doesn't t even have that attribute for example rope

so on items that has 0 or greater, should be displayed
Lua:
<attribute key="armor" value="0"/>
 
Last edited:
think you misunderstood, i want to have armor: 0 displayed for items, just not on items that doesn't t even have that attribute for example rope

so on items that has 0 or greater, should be displayed
Lua:
<attribute key="armor" value="0"/>

Okay, I see. Clearly misunderstood then. Well, if that's the case then I don't think you can easily achieve that, if you track down Item::getArmor() method, you will see it returns either attribute or ItemType::armor value, which is 0 by default. So whether you specify armor with value 0 in items.xml or just leave this one out, in TFS, it's going to be 0. You could initialize it to -1 in ItemType class declaration (items.h), but then you also need to track all code fragments that use it and modify them accordingly, e.g. your method for item description would have to check if it's higher than -1, instead of unequal to 0.
 
Solution
Back
Top