• 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++ attack speed attribute on crossbows and bows

dragon1155

Member
Joined
Mar 5, 2010
Messages
136
Reaction score
8
Hey guys, I'm having trouble getting the attack speed attribute to work with crossbows and bows. I tried a workaround I found in another discussion, but strangely, it only works when the attack speed attribute is applied to the ammunition, completely ignoring the attribute applied to the distance weapon.
player.cpp:
C++:
void Player::doAttacking(uint32_t)
{
    Item* item = getWeapon(false);
    uint32_t attackSpeed = (item && item->getAttackSpeed() != 0) ? item->getAttackSpeed() : getAttackSpeed();


    if(!lastAttack)
        lastAttack = OTSYS_TIME() - attackSpeed - 1;
    else if((OTSYS_TIME() - lastAttack) < attackSpeed)
        return;


    if(hasCondition(CONDITION_PACIFIED) && !hasCustomFlag(PlayerCustomFlag_IgnorePacification))
    {
        lastAttack = OTSYS_TIME();
        return;
    }


    if(const Weapon* _weapon = g_weapons->getWeapon(item))
    {
so, I think this line is for regular weapons (not including distance weapons that use ammunition):
player.cpp:
C++:
uint32_t Player::getAttackSpeed() const
{
    return ((weapon && weapon->getAttackSpeed() != 0) ? weapon->getAttackSpeed() : (vocation->getAttackSpeed() / std::max((size_t)1, getWeapons().size())));
}
interestingly, the attack speed value set for vocation in vocations.xml works well with all weapon types. Im not familiar with C++ at all, so i would really appreciate any suggestions and tips on what to do. TFS 0.4
 
Are you having issues with attack speed attribute while shooting with a bow or crossbow while running? Or when using runes or potions and the attack speed attribute stops working properly? I believe you might need to make some changes in the player.cpp file to fix this.

Search for: Player.cpp
C++:
if((!_weapon->hasExhaustion() || !hasCondition(CONDITION_EXHAUST, EXHAUST_COMBAT)) && _weapon->useWeapon(this, item, attackedCreature))
Change by:
C++:
if(!_weapon->hasExhaustion() && _weapon->useWeapon(this, item, attackedCreature))

Use rune while running.

In player.cpp, remove this line.
C++:
setNextAction(OTSYS_TIME() + getStepDuration(dir));

In the weapons.xml, for the item you want to allow the simultaneous use of a rune while running and shooting with increased attack speed, please include the following changes.

example:

swing="true"

XML:
<distance id="7368" level="80" event="function" value="default"/> <!-- Assassin Star -->

for
XML:
<distance id="7368" level="80" swing="true" event="function" value="default"/> <!-- Assassin Star -->
I believe these changes should work, but I'm not sure. You'll have to test them to find out. I know that it should allow you to use runes and potions while running and attacking with a bow or crossbow at the same time. As for the attack speed attribute, I'm not certain. It's important to make the changes and test them to see the results.
thanks for looking into this, but Ive already dealt with it a while ago. the issue is that all ranged weapons (only those that use ammunition) ignore the attack speed attribute; it doesn't change how the weapon functions. unless I create a script for such a weapon in /weapons, then it works as it should. other types of weapons works fine ;p
@edit:
another exception is when the ammunition has the attack speed attribute, then it also works as it should
 
Back
Top