Thread: n00b ruleset question
-
March 11th, 2008, 00:32 #1
- Join Date
- Mar 2008
- Posts
- 8
n00b ruleset question
The n00b, in this instance, would be me.
I'm trying to hack together a somewhat functional character sheet for classic (Moldvay-boxed sets) D&D, using the D20 ruleset as a foundation. I've got the ability modifiers working right, thanks to another post in this forum, but I need a way to alter the initiative modifier to match the rules. Basically, it's equal to Dex bonus - 1 if the Dex bonus is greater than 1. Thus, if the character has a Dex bonus of +1 or +2, then his Initiative modifier would be +1. If he has a Dex Bonus of +3, then his Initiative modifier would be +2. Hopefully, that makes sense.
The problem is, I have no idea how to accomplish this modification. The relevant section of charsheet_main.xml seems to get the value for that field here:
Code:<source> <name>initiative.misc</name> <op>+</op> </source>
(I told you I was a n00b!)
-
March 11th, 2008, 22:32 #2
Yes, you'll need to insert a <script> element. You'll need to grab the value of your dex bonus and then you'll need to do a little math like so. Since someone showed this to me, it's only fair to pass it along.
In this example I'm assuming that your node with your dex modifier is has something like:
<abilityscore name="dexmod" source="abilities.dexterity.modifier">
Code:<script> function myfunc() if mydexmod.getValue() > 2 then setValue( mydexmod.getValue() - 1 ); else setValue(1); end end function onInit() mydexmod = window.getDatabaseNode().getChild("abilities.dexterity.modifier"); mydexmod.onUpdate = myfunc; myfunc(); end </script>
-
March 12th, 2008, 01:06 #3
- Join Date
- Mar 2008
- Posts
- 8
Sloejack, you are a lifesaver--thanks! I actually needed to change two things; it needed to apply the -1 modifier if the base Dex bonus was greater than 1 (instead of greater than 2), and the "else setValue(1);" statement needed to be changed to "setValue( mydexmod.getValue() );" (otherwise, the script locks the Initiative bonus at 1 for all Dex bonuses of 1 and below; so someone with no Dex bonus at all still ends up with a +1 Initiative modifier.
I also needed to add a statement to handle the bottom end of the scale, which works the same way (Dex mod of less than -1 gets +1 added to calculate Initiative modifier). So, the final script looks like this:
Code:<script> function myfunc() if mydexmod.getValue() > 1 then setValue( mydexmod.getValue() - 1 ); else if mydexmod.getValue() < -1 then setValue( mydexmod.getValue() + 1 ); else setValue( mydexmod.getValue() ); end end end function onInit() mydexmod = window.getDatabaseNode().getChild("abilities.dexterity.bonus"); mydexmod.onUpdate = myfunc; myfunc(); end </script>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks