PDA

View Full Version : Linked Die Function



Tokuriku
October 1st, 2007, 10:27
I am in need of a linkeddie fieldin xml/lua.
The function would take the dies from a number of other fields and merge them into one big die pool.
I know what I need but I don't know how to program it.
There is a "linkednumber" field that already exist.
I need something similar but for dice...

Can anybody lay a hand?

Foen
October 1st, 2007, 18:04
I have created something similar for a BRP-based ruleset, which takes a damage modifier from the STR attribute (-1D6, -1D4, 0, +1D4 or +1D6) and adds it to the weapon damage, but this is done as part of the onDrag event handler rather than being directly linked. Would that be of any help?

Cheers

Stuart

Tokuriku
October 2nd, 2007, 09:38
Sure :)

If it helps me visualize how it's done trough LUA, then I should figure (scavenge) something out for the function I need :D

Foen
October 2nd, 2007, 10:30
Here goes, I'll try to explain the various bits :)

The first bit holds the source of the die modifier (-1D6, -1D4, nil, +1D4 or +1D6)



placeholder for the calculated size+strength
<linkednumber name="dbdummy" source="abilities.dbdummy">
<readonly />
<invisible />
<source>
<name>abilities.size</name>
<op>+</op>
</source>
<source>
<name>abilities.strength</name>
<op>+</op>
</source>
<script>
function onSourceUpdate()
local tot = calculateSources();
setValue(tot);
depending on value, set a description and die field
if tot &lt; 13 then
window.dbdesc.setValue("-1d6");
window.damagedice.setDice({"m6"});
elseif tot &lt; 17 then
window.dbdesc.setValue("-1d4");
window.damagedice.setDice({"m4"});
elseif tot &lt; 25 then
window.dbdesc.setValue("na");
window.damagedice.setDice({"0"});
elseif tot &lt; 33 then
window.dbdesc.setValue("+1d4");
window.damagedice.setDice({"d4"});
else
window.dbdesc.setValue("+1d6");
window.damagedice.setDice({"d6"});
end
end
</script>
</linkednumber>
visible fields for the derived damage modifier
<stringcontrol name="dbdesc">
<static />
</stringcontrol>
<diefield name="damagedice" source="abilities.damagedice">
</diefield>


The next bit happens whenever a weapon damage field is dragged (for example to the chat window).



the damage dice for this weapon
<diefield name="damagedice">
<script>
function onDrag(button, x, y, draginfo)
create a dielist holding the base damage dice
local dielist = getDice();
look at the weapon type
local datanode = window.getDatabaseNode().createChild("weapontype", "number");
draginfo.setType("dice");
weapon type 1 doesn't have a damage modifier
if datanode.getValue()~=1 then
if window.dbflag.getState() then
fetch the damage modifier
local dmgdice = window.windowlist.window.damagedice.getDice();
insert it in the dielist
table.insert(dielist, dmgdice[1]);
end
end
set the drag data dice = our dielist
draginfo.setDieList(dielist);
get any additional bonus (eg +2)
draginfo.setNumberData(window.damagebonus.getValue ());
give the drag data a description (eg Sword damage)
draginfo.setDescription(window.name.getValue() .. " damage");
done
return true;
end
</script>
</diefield>
Hope that helps,

Stuart