Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

Macro to restrict the maximum modifier per level!

1380136522

Edited 1380137453
Hello I am needing to create a macro to cast spells. Example Cure Light Wounds (D&D), it is 1d8 +1/level a maximum of +5. I created the attribute "Level" and the macro: # CuraLeve /r 1d8 + @{Level} If the character is at level 6 or more, will add +6 I was wondering if anyone knows how I can restrict the maximum +5? Excuse the spelling, I'm using Google Translator, I'm Brazilian. Thank you all! ;)
1380138602

Edited 1380144003
Gauss
Forum Champion
Here you go: /r 1d8+ Level-(Level-Maxlevel)*[[(floor(1/(floor(Level/Maxlevel)+1))-1)*(floor(1/(floor(Level/Maxlevel)+1))-1)]] Note: Danilo came up with this in this thread: <a href="https://app.roll20.net/forum/post/328661/shocking-grasp#post-332640" rel="nofollow">https://app.roll20.net/forum/post/328661/shocking-grasp#post-332640</a> - Gauss Edit: I did not want to put attribute values in everywhere so I just used the words. Level should be an Attribute while Maxlevel can be just a number or an attribute (your choice, I suggest number).
Thanks for the help ! Did not understand the function implemented but solved my problem . :) know where I can learn about this function ?
1380143938

Edited 1380177157
Gauss
Forum Champion
It is not a Roll20 function so much as a mathematics function with one Roll20 function. Here are some examples to show you what it does (for the purposes of this I am removing the inline brackets since they are for Roll20 and not math). I will bold the terms that are being simplified.: Example 1: Level is 9 and Maxlevel is 5 9-( 9-5 )*(floor(1/( floor(9/5) +1))-1)*(floor(1/ (floor(9/5) +1))-1) = 9-(4)*(floor(1/( 1+1 ))-1)*(floor(1/( 1+1 ))-1) = 9-(4)*( floor(1/(2) )-1)*( floor(1/(2) )-1) = 9-(4)*( 0-1 )*( 0-1 ) = 9-(4)* (-1)*(-1) = 9- (4)*1 = 9-(4) = 5 As you can see, the terms with floor (round down) came out to -1. When -1*-1 the result is 1. This will happen every time Level is greater than Maxlevel. When 1 is multiplied with (Level-Maxlevel) it allows (Level-Maxlevel) to stay intact (no change). Then (Level-Maxlevel) subtracts from Level to bring it down to the maximum value. Example 2: Level is 6 and Maxlevel is 10 6-( 6-10 )*(floor(1/( floor(6/10) +1))-1)*(floor(1/( floor(6/10) +1))-1) = 6-(-4)*(floor(1/( 0+1 ))-1)*(floor(1/( 0+1 ))-1) = 6-(-4)*( floor(1/(1)) -1)*( floor(1/(1)) -1) = 6-(-4)*( 1-1 )*( 1-1 ) = 6- (-4)*(0)*(0) = 6-0 = 6 As you can see, the terms with floor (round down) came out to 0. This will happen every time Level is less than Maxlevel. When 0 is multiplied against (Level-Maxlevel) the result is zero which takes it out of the equation leaving just the first "Level". Summary: The two terms with Floor in them are a 0 or 1 switch. If 0 they remove the (Level-Maxlevel) term. If 1 they allow the (Level-Maxlevel) term to stay intact. If that term stays intact it will be subtracted from "Level" which will bring "Level" down to the maximum value. I hope that explains how it works. :) - Gauss
that is devilishly fiendish. I like it
Noting that the purpose of the two identical "floor" terms is just to change a -1 into a +1 through multiplication, the statement can be simplified as follows: /r 1d8+ Level + (Level-Maxlevel)*[[(floor(1/(floor(Level/Maxlevel)+1))-1)]] Or, alternatively: /r 1d8+ Level-( Maxlevel-Level )*[[(floor(1/(floor(Level/Maxlevel)+1))-1)]] Both of these will save a miniscule bit of processing time, but more importantly, they're shorter, so there's less chance of making a typo :) -David
1380225743
Gauss
Forum Champion
David, I felt there was a simpler method, thank you for demonstrating it. :) I will let Danilo (he wrote the original method) know about the simpler method. - Gauss
That's great David =D thanks for this =D