|
Senior Member
Join Date: Nov 2017
Location: Trafford, PA, USA
Posts: 226
|
Im writing an eval script that grants a 5 bonus to base speed. This ability scales with level. The first 5 bonus is granted at 1st level, and then again at every 4 class levels (i.e. 4th, 8th, 12th, etc.)
The script I first came up with was: field[abValue].value += round(field[xTotalLev].value / 4, 0, -1) + 5 It worked for 1st level (changed 30 speed to 35 speed), but at 4th level the speed became 36. So I changed the script to: field[abValue].value += round(field[xTotalLev].value / 4, 0, -1) * 5 This worked at all levels except 1st. Then I thought What if I round up instead of down?: field[abValue].value += round(field[xTotalLev].value / 4, 0, 1) + 5 This resulted in a +6 movement speed at 1st level. field[abValue].value += round(field[xTotalLev].value / 4, 0, 1) * 5 This resulted in a 5 increase at 1st level, but no increase at 4th. What is the magic formula to make this work? Thanks^7 |
#1 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,213
|
At 1st level, level/4 = 0, but you want to add +5 at 1st level, so you want to add 1 to the total you're calculating, and then multiply it.
Code:
field[abValue].value += (round(field[xTotalLev].value / 4, 0, -1) + 1) * 5 |
#2 |
Senior Member
Join Date: Nov 2017
Location: Trafford, PA, USA
Posts: 226
|
Yes! That made it work. You guys must work on this a lot
|
#3 |
Senior Member
Join Date: Nov 2017
Location: Trafford, PA, USA
Posts: 226
|
Another Round function challenge for you all: Ability that grants +1 to perception skill at 3rd level, and gains an additional +1 at 7th, 11th, 15th and 19th levels.
field[abValue].value += round(field[xTotalLev].value-2 / 4, 0, -1) + 1 ~Apply bonus to Perception skill hero.child[skPercep].field[Bonus].value += field[abValue].value Somehow, the bonus at 3rd level delivers a result of +3. I am baffled as to how it arrived at that result. Any ideas? |
#4 |
Senior Member
Join Date: May 2013
Posts: 1,458
|
Quote:
Code:
var bonus as number var roundbonus as number bonus = field[xTotalLev].value-2 roundbonus = round(bonus/4,0,-1) + 1 field[abValue].value += roundbonus ~Apply bonus to Perception skill hero.child[skPercep].field[Bonus].value += field[abValue].value |
|
#5 |
Senior Member
Join Date: Mar 2013
Location: Greater London, UK
Posts: 2,623
|
Well, I suspect it is doing 3 - 2 / 4; so that becomes 3 - 0.
You need the field...value - 2 in parentheses so that the minus gets done before the divide. BODMAS Farling Author of the Realm Works Import tool, Realm Works Output tool and Realm Works to Foundry module Donations gratefully received via Patreon, Ko-Fi or Paypal |
#6 |
|
|