PDA

View Full Version : n00b ruleset question



Felderin
March 11th, 2008, 00:32
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:


<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!)

sloejack
March 11th, 2008, 22:32
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">



<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.

Felderin
March 12th, 2008, 01:06
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:



<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! :)