• 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+ How to set attack speed for rings and amulets in TFS 1.4.2?

lukio132

New Member
Joined
Jul 14, 2025
Messages
2
Reaction score
1
Hi everyone,

I’m using TFS 1.4.2 and I’m trying to add attackSpeed to rings and amulets.
For example, I want the wedding ring to give the player an attackSpeed value of 100.
It works fine when added to weapons using
LUA:
<attribute key="attackspeed" value="100" />
, but this doesn’t seem to affect rings or amulets.
I’ve tried modifying player.cpp and checking item slots like SLOT_RING and SLOT_AMULET, but so far nothing works.
Does anyone know how to properly implement attackSpeed for rings or amulets
Post automatically merged:

Hi everyone,

I’m using TFS 1.4.2 and I’m trying to add attackSpeed to rings and amulets.
For example, I want the wedding ring to give the player an attackSpeed value of 100.
It works fine when added to weapons using
LUA:
<attribute key="attackspeed" value="100" />
, but this doesn’t seem to affect rings or amulets.
I’ve tried modifying player.cpp and checking item slots like SLOT_RING and SLOT_AMULET, but so far nothing works.
Does anyone know how to properly implement attackSpeed for rings or amulets
Or how to make a rune that will add an attribute to a weapon? Maybe that would be easier?
 
Last edited:
Attack speed code in player.cpp only checks weapon attack speed, other items attack speed is ignored:
C++:
uint32_t Player::getAttackSpeed() const
{
    const Item* weapon = getWeapon(true);
    if (!weapon || weapon->getAttackSpeed() == 0) {
        return vocation->getAttackSpeed();
    }

    return weapon->getAttackSpeed();
}
It's also 'attackspeed' as value (interval between attacks), not boost to current player attack speed. It replaces vocations.xml speed value with weapon attack speed, not reduces vocations.xml speed by weapon attack speed.

To make it reduce attack interval by attackspeed attribute of any equipped item use:
C++:
uint32_t Player::getAttackSpeed() const
{
    uint32_t attackSpeed = vocation->getAttackSpeed();

    const Item* item;
    for (int i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) {
        item = inventory[i];
        // check if an item has attack speed modification
        if (item && item->getAttackSpeed() > 0) {
            // check if it's not higher than the current speed (would go to 0 or through 0 to max uint32_t value)
            if (attackSpeed > item->getAttackSpeed()) {
                attackSpeed -= item->getAttackSpeed();
            }
        }
    }

    return attackSpeed;
}
It works [EDIT: not tested tested on current TFS master and it works, on 1.4 it should also work].
It's not a perfect solution, as it reads all items every time player attacks - waste CPU. Not a big problem, unless you have 200+ online running with 0.1 second attack speed.
Player attackSpeed value should be stored in some variable in player.h and recalculated for player, when inventory item or vocation changes.

EDIT:
Fixed wrong IF in code.
Also, to make fast attack work, you have to enable classicAttackSpeed = true in config.lua
WHICH on TFS 1.4 may in some situations make CPU go 100%. You have to apply this PR fix:
 
Last edited:

Similar threads

Back
Top