• 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+ Attackspeed change milliseconds to percent

Allan Silva

Member
Joined
May 30, 2018
Messages
39
Solutions
1
Reaction score
7
-TFS 1.3

Hi

I added the attackspeed system on the server following this reference

The script only run when I put this cod

Player.h
Lua:
uint32_t getAttackSpeed() const {
            Item* weapon = getWeapon(false);

            if (weapon && weapon->getAttackSpeed() > 0)
                return weapon->getAttackSpeed();
            return vocation->getAttackSpeed();
        }

1616949989935.png

Now script are working, but attackspeed attribute is based on milliseconds and I would like to change it to a percentage. Any ideas what can be changed to do this?
Thanks!
 
Last edited:
Solution
You cod is nice now
C++:
return vocation->getAttackSpeed() * (1 - (weapon->getAttackSpeed() / 100));

The question, why dont work?

I will test it soon & reply
Post automatically merged:

@Allan Silva

Just tested and noticed that division is converted to int.
so try this
C++:
return vocation->getAttackSpeed() * (1 - (weapon->getAttackSpeed() / 100.0));
The following line should give you +%
C++:
(weapon->getAttackSpeed() * 100) / vocation->getAttackSpeed()

e.g:
Code:
player atk speed = 2000
weapon atk speed = 1000

(weaponAtkSpeed * 100) / playerAtkSpeed = 50(%)
 
The following line should give you +%
C++:
(weapon->getAttackSpeed() * 100) / vocation->getAttackSpeed()

e.g:
Code:
player atk speed = 2000
weapon atk speed = 1000

(weaponAtkSpeed * 100) / playerAtkSpeed = 50(%)
I put your code like this

Lua:
uint32_t getAttackSpeed() const {
      Item* weapon = getWeapon(false);

      if (weapon && weapon->getAttackSpeed() > 0)
        return (weapon->getAttackSpeed() * 100) / vocation->getAttackSpeed();
      return vocation->getAttackSpeed();
        }


Independent of the value, the attack was very fast.
 
I put your code like this

Lua:
uint32_t getAttackSpeed() const {
      Item* weapon = getWeapon(false);

      if (weapon && weapon->getAttackSpeed() > 0)
        return (weapon->getAttackSpeed() * 100) / vocation->getAttackSpeed();
      return vocation->getAttackSpeed();
        }


Independent of the value, the attack was very fast.
I probably misunderstood you.

Is your goal to, inside the description, display the extra percentage added to the player atk speed ?
In that case, you could write the amount of % directly in the xml attribute & change description part to;
s << "AtkSpd: +" << attackSpeed << "%";

And modify getAttackSpeed() like this
C++:
uint32_t getAttackSpeed() const {
    Item* weapon = getWeapon(false);

    if (weapon && weapon->getAttackSpeed() > 0) {
        return (1 + (weapon->getAttackSpeed() / 100)) * vocation->getAttackSpeed();
    }

    return vocation->getAttackSpeed();
}
 
Last edited:
If you have 2000 base speed
and add 100% (+2000) you will end up with 4000 speed.


1% might not be enough to notice. 🤔
Code:
(1+(1 / 100)) * 2000 = 2020 ATK Speed
Lower attack speed to be fast (1000 milisecond = 1 second to do attack basic) and higher to be slow (4000 milisecond = 4 second to do attack basic). This show how attacks you do in miliseconds, I believe you got confused.
 
Edited. Try new one
The formula now appears to be correct. but attackspeed does not appear to follow the item's value. I changed values from 1 to 99% and nothing has changed (attackspeed normal). When I set the value to 100%, the attack worked very fast (very very fast)
Post automatically merged:

The formula now appears to be correct. but attackspeed does not appear to follow the item's value. I changed values from 1 to 99% and nothing has changed (attackspeed normal). When I set the value to 100%, the attack worked very fast (very very fast).


What you think about this cod, I found researching the solution to the problem, but I couldn't compile it

Lua:
uint32_t getAttackSpeed() const {
            int64_t bonusPercent = getEffectiveAbility(ITEM_ABILITY_ATTACKSPEED);
            int64_t as = (attackSpeed > 0) ? attackSpeed : vocation->getAttackSpeed();
            as -= as * (bonusPercent / 100.);
            return as;
        }
 
attackspeed does not appear to follow the item's value. I changed values from 1 to 99% and nothing has changed (attackspeed normal).
🤔 That sounds odd.
Code:
>>> 2000 * (1 - (1/100))
1980.0

>>> 2000 * (1 - (2/100))
1960.0

>>> 2000 * (1 - (4/100))
1920.0

>>> 2000 * (1 - (99/100))
20.0

>>> 2000 * (1 - (100/100))
0.0

but I couldn't compile it
your method getAttackSpeed has uint32_t as return type.
That code is trying to return int64_t value
 
You cod is nice now
C++:
return vocation->getAttackSpeed() * (1 - (weapon->getAttackSpeed() / 100));

The question, why dont work?

I will test it soon & reply
Post automatically merged:

@Allan Silva

Just tested and noticed that division is converted to int.
so try this
C++:
return vocation->getAttackSpeed() * (1 - (weapon->getAttackSpeed() / 100.0));
 
Last edited:
Solution
Back
Top