• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Rounding question

Lawful_g

Well-known member
Is it possible to round to the nearest increment of 5? One exotic armor halves your speed (rather than dropping it 1/3), which normally is not a problem, since speeds are almost always in increments of 10. However, there could be exceptions, like if a character has the Dash feat.
 
Also, the tSpeedMod field is acting wierd... I can't seem to set it = to something, or divide/multiply it, only add or subtract....

For example, say we are a human wearing Boots of Striding and Springing, giving us a a tSpeed value of 30, and a tSpeedMod of 40... What I want to do is make the modified speed 1/2 of it's current value. I would make this script....

hero.child[Speed].field[tSpeedMod].value = hero.child[Speed].field[tSpeedMod].value / 2

I have tried the script at various phases, but there is no change at all. So then I tried a "var whatever as number" and tried to set tSpeedMod's value equal to that, but again no change. tSpeedMod stayed at 40.

Next I tried to set it like this, making tSpeedMod equal to one half of tSpeed...

hero.child[Speed].field[tSpeedMod].value = hero.child[Speed].field[tSpeed].value / 2

In this case, tSpeedMod actually went up by half of the Speed, and then the enhancement bonus from the boots was added on. tSpeedMod became 55... weird.

So then I tried subtracting... like so.
hero.child[Speed].field[tSpeedMod].value -= hero.child[Speed].field[tSpeed].value / 2

Which did subtract 15, then added the +10 enhancement bonus from the boots, giving a tSpeedMod of 25...

So I guess I am having trouble getting the tSpeedMod.value and then halving it....

Can anybody give me a hand?
 
Here's how to round to the nearest multiple of 5:

Code:
var bonus as number
bonus = something (however you're calculating it)
 
~divide by 5, then round down
bonus = round(bonus/5,0,-1)
 
~and multiply by 5
bonus *= 5

BTW, in the round() code, the last number is the direction to round. -1 is down, 0 is nearest, 1 is up. Since this is the SRD, and rounding down is the default, I used -1 in my example.
 
tSpeedMod is calculated at Final/10000.

Since there are some things that make use of it, for example, setting the character's fly speed equal to their land speed, you'll want to make modifications to tSpeedMod very close to the original. Final/10500, perhaps.

hero.child[Speed].field[tSpeedMod].value /= 2 (your first try, making use of /= rather than retyping hero.child[Speed].field[tSpeedMod].value) should be correct, if it's done at the right time.
 
I see, so since tSpeedMod hadn't been calculated yet, all divisions resulted in 0 and no change, but subtraction sent it into negatives, so that worked.

Thanks for the help as always.
 
Back
Top