DICE PACKS BUNDLE
  1. #1

    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 assume that I need to replace this with a script or something, but other than that, I'm lost. Any help would be appreciated!

    (I told you I was a n00b!)

  2. #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>
    This grabs the dexterity modifier value, if it's greater than 2 it subtracts 1 from the modifier and sets the initiative modifier. If it's 1 or less, then it sets it to 1 as a default. If that's not the behavior you want for the default or the less than one, you need to adjust the if then logic to suit your needs.

  3. #3
    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() 	&lt; -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>
    Pardon the messiness; I'm terrible at scripting (and I'm not sure that I ever would have figured this out without your help). But I tested it, and it works. It generates the proper initiative modifiers based on the classic D&D rules. So, hooray!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in