• 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++ Show ammunition attack value on look

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,521
Solutions
27
Reaction score
870
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi guys! I use TFS 1.5 downgrades 8.6 and I wonder how can I make to show the attack of every ammunition (bolts, arrows, etc). I was looking here

But couldn't find the similitude with my sources here
Greed-TFS-1.5-Downgrades/src/item.cpp at 8.60 · ralke23/Greed-TFS-1.5-Downgrades (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/blob/8.60/src/item.cpp#L942)

Which part I must change to achieve what I need, and exactly which code must be the replacement?
Thanks in advance, regards!
 
I'm not sure it will work, but I'm interested in adding this functionality to my own codebase. I hope to find someone capable of making these modifications.
I haven't tried it yet as I'm at work. As soon as I get home I will test it to see if it works properly.

C++:
} else if (it.weaponType != WEAPON_NONE) {
    bool begin = true;
    if (it.weaponType == WEAPON_DISTANCE) {
        int32_t attack, defense;
        int8_t hitChance;
        if (item) {
            attack = item->getAttack();
            defense = item->getDefense();
            hitChance = item->getHitChance();
        } else {
            attack = it.attack;
            defense = it.defense;
            hitChance = it.hitChance;
        }

        if (it.ammoType != AMMO_NONE) {
            s << " (Range:" << static_cast<uint16_t>(item ? item->getShootRange() : it.shootRange);

            if (attack != 0) {
                s << ", Atk" << std::showpos << attack << std::noshowpos;
            }

            if (hitChance != 0) {
                s << ", Hit%" << std::showpos << static_cast<int16_t>(hitChance) << std::noshowpos;
            }

            // Display ammo attack and defense
            if (item) {
                int32_t ammoAttack = item->getAmmoAttack();
                int32_t ammoDefense = item->getAmmoDefense();
                s << ", Ammo Atk:" << std::showpos << ammoAttack << std::noshowpos;
                s << ", Ammo Def:" << std::showpos << ammoDefense << std::noshowpos;
            }
        } else {
            s << " (Atk:" << attack << ", Def:" << defense;
        }

        begin = false;
    }
 
// Display ammo attack and defense if (item) { int32_t ammoAttack = item->getAmmoAttack(); int32_t ammoDefense = item->getAmmoDefense(); s << ", Ammo Atk:" << std::showpos << ammoAttack << std::noshowpos; s << ", Ammo Def:" << std::showpos << ammoDefense << std::noshowpos; }
Tried but didn't work, the ammunition remain with the same description. I wonder if this can be achieved on .lua too since is 1.5 downgrades. Would be very nice is hitChance can be added to description too!

Regards :)
 
Last edited:
I haven't tried, but in the onLook event you can probably add something like:
Lua:
local attack = thing:getAttribute(ITEM_ATTRIBUTE_ATTACK)
if attack > 0 then
  description = string.format("%s, Attack: %d", description, attack)
end
If that works, the same approach should work for other attributes like ITEM_ATTRIBUTE_HITCHANCE

You might need to check if the item isAmmo() before doing this to avoid unintended consequences though!
 
Its the same in both cases

Lua

C++

Just replace that statement with a simple else and obviously dont add any other attribute than attack nor maxHitChance on ammunition
Otherwise the attributes will be displayed but wont work anyway
 
I haven't tried, but in the onLook event you can probably add something like:
Lua:
local attack = thing:getAttribute(ITEM_ATTRIBUTE_ATTACK)
if attack > 0 then
  description = string.format("%s, Attack: %d", description, attack)
end
If that works, the same approach should work for other attributes like ITEM_ATTRIBUTE_HITCHANCE

You might need to check if the item isAmmo() before doing this to avoid unintended consequences though!
Thanks a lot!! I'll try, @Roddet answer seems more direct so i'm giving a try to it first

Its the same in both cases

Lua

C++

Just replace that statement with a simple else and obviously dont add any other attribute than attack nor maxHitChance on ammunition
Otherwise the attributes will be displayed but wont work anyway
I still can't get it how it is supposed to be written, sorry for not catching it, I literally replaced
Lua:
} else if (it.weaponType != WEAPON_AMMO) {
for an else, but it didn't worked. Tested on .lua lib/core/item.lua

Haven't tried on C++ yet, is the same right? Replace
C++:
        } else if (it.weaponType != WEAPON_AMMO) {
for a simple else?

Regards and thanks a lot for the help!
Post automatically merged:

Edit// Worked well! Replaced
C++:
} else if (it.weaponType != WEAPON_AMMO) {

for } else {, thanks @Roddet
Post automatically merged:

The only thing that doesn't work is getHitChance, if i'm not wrong, to show the ammunition hitchance you must create a new method for getMaxHitChance instead of getHitChance, since HitChance is related to bows, xbows, and stuff that increases the base HitChance. Thanks a lot and regards!
 
Last edited:
Back
Top