1. ## Ruleset modification question.

I'm attempting to learn the ruleset creation by screwing around with the .xml & LUA.

A simple change I'd like to make the D20 ruleset is to change the ability score modifiers but I can seem to find out where to change the value of the modifiers based on the stat value.

Can some kind soul point me in the right direction?

Thank you

2. ## Found it

Ok... I stumbled upon it in the charsheet_templates.xml.

I've changed the constant (e.g. from /2 to /3) to see how it works.

It would appear that if you want a different scaling to the modifers other than by a factor of 2, the coding would become complicated (e.g. currently the ability score of 12~13 = +1 mod, 14~15 = +2 etc..)

What I would like to see is an example of code that would allow the following ability score modifers:

ability 1~3 = -3
ability 4~5 = -2
ability 6~8 = -1
ability 9~12 = +0
ability 13~15 = +1
ability 16~17 = +2
ability 18 = +3

Guidance from anyone would be appreciated.

3. One way would be to define a table that has the "answer" values in it, and use the ability score as the key (or index) into that table to look up the answer.

Code:
function abilitytomodifier(ability)
local abilitymodtable = { [18] = 3, [16] = 2, [13] = 1, [9] = 0, [6] = -1, [4] = -2, [1] = -3};

for k,v in pairs(abilitymodtable) do
if ability >= k then
return v;
end
end
end
Thus, changing the boundaries becomes a matter of changing the abilitymodtable. You put them in descending order, using as the keys the smallest integer that corresponds to a particular value.

4. ... aight.

This is EXACTLY what I need.
I'd kiss ya if I knew wether or not ya wanted it.

5. Absolutly brilliant Dachannien ....

However my tiny mind is clueless as to where to paste your code example into the charsheet_templates.xml

Could you please pick-up a baseball bat and pound it into my skull?

6. Here is the code I want to modify with your example. I've tried a few different ways with no success.

Code:
<template name="abilitybonus">
<modifiernumber>
<anchored>
<position>right</position>
<offset>9,0</offset>
<size>
<width>36</width>
</size>
</anchored>
<frame>
<name>bonus</name>
<offset>3,5,3,5</offset>
</frame>
<font>sheetnumber</font>
<hideonvalue value="0" />
<displaysign />
<script>
function onSourceUpdate()
setValue(math.floor((sources[scorefield[1]].getValue() - sources[damagefield[1]].getValue() - 10) / 2) + getModifier());
end

function onInit()

super.onInit();
end
</script>
</modifiernumber>
</template>

7. You would add the abilitytomodifier() function in the script block, and then replace everything in the setValue() call in onSourceUpdate() with a call to the abilitytomodifier() function, plus the result from getModifier(). The value you pass to that function should be the total of the things that go in to make the ability total.

Code:
setValue( 	abilitytomodifier(sources[scorefield[1]].getValue()
- sources[damagefield[1]].getValue())
+ getModifier() );

8. I'm still doing something wrong. The only two modifiers I'm getting is a "-3" for an ability score between 1~15 and "+2" for 16 and above.

Code:
<script>
function abilitytomodifier(ability)
local abilitymodtable = { [18] = 3, [16] = 2, [13] = 1, [9] = 0, [6] = -1, [4] = -2, [1] = -3};

for k,v in pairs(abilitymodtable) do
if ability >= k then
return v;
end
end
end

function onSourceUpdate()
setValue( 	abilitytomodifier(sources[scorefield[1]].getValue()
- sources[damagefield[1]].getValue())
+ getModifier() );
end

function onInit()

super.onInit();
end
</script>

9. Oh, crap, I just realized something: when using numeric keys, Lua will stick the keys into their numeric order, which makes the list incorrect.

Try replacing the left and right brackets in the number list with quotes, and a couple lines down where it says "if ability >= k then", replace the "k" with "tonumber(k)".

I'm getting kind of sloppy, I know

10. Thanks Dachannien, I'll give it a try very shorty

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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•