PDA

View Full Version : Number of Dice



Fenloh
October 6th, 2008, 08:52
First of all, thanks for the Foundation Mod.

I am using it as a basis for the Mod i am working on. Right now i am working on the Character Sheet. The Stats page is now done and i want to roll dice on a doubleclick on the "Check" fields.

I do have the following "problems":

1. The action for the doubleclick on the "check" fields, which I have found in another greatly mastered Mod, works so far. When I doubleklick the check field one Dice rolls and adds up the bonus, stating what Check it is. What i need though is a number of Dice equal to the number in the Checkfield an no bonus. The Modifierstack sould be added / subtracted from the Number of dice rather then applying a bonus, but only to the doubleclick or dragdrop rolls from that kind of fields. (Stats and later on skills)

2. How can i sort the Dice roll on the Chattable?

3. If the doubleclickdiceroll works (and or Dragdrop) i would like to have thes specific tests to cound successes and possible countersuccesses.

4. Also i want to add up 2 fields in the third one, but i am having problems with the addsource, somehow a lot of errors are coming up, maybe someone has an example where i can look it up.

All i need would be some codestrings where i can look it up.

Anyway, sorry for my bad english and thanks in advance for some help. Once the mod is at least a usable basis, then i am willing to share the mod on a private Basis.

Fenloh

Foen
October 7th, 2008, 06:35
Hi Fenloh

Much of what you are doing will need you to look at the chat_chat.lua script and the onDiceLanded event handler. This is probably one of the more complicated areas of ruleset modification, so I'm afraid there are not many easy answers.

To roll dice manually, or create a handful of dice to drag and drop, you would typically use code like this (in your "check" control script):



function rollDice()
local mod = 1; --[[ the modifier added to the result ]]
ChatManager.getControl().throwDice("dice",{"d100","d10"},mod,"My description");
end

function dragDice(button, x, y, dragData)
local diceList = {"d100","d10"};
local mod = 1;
dragData.setType("dice");
dragData.setSlot(1);
dragData.setDieList(diceList);
dragData.setNumberData(mod);
dragData.setDescription("My description");
return true;
end


Clearly you won't be using a d10 and a d100, but you can build the table of dice in code.

Dice sorting and adding up successes and failures needs to happen in onDiceLanded (chat_chat.lua), where you can examine the rolled outcome. I'm not sure you can re-order or change the dice though.

Add source isn't a standard feature, but is an add-on implemented for linkednumberfields. If you are using standard fields (such as numberfield and numbercontrol) it won't be available, so you'll have to switch to the linkednumberfield template.

Please give us a shout if this sounds a bit vague!

Stuart

Fenloh
October 7th, 2008, 08:10
Thanks for the reply.

I feel that i am getting old and it seems i am loosing my edge.. kind of. I did geht the 4th point solved, which i shouldnt have asked (darn rtfm).

Also i must admit, that i do not understand everything. I didnt use english for a long time an i am kind of rusty.

As far as i understand your Code, you set a modifier Value to 1, which would be the actual Number in my Check field. That i would receive through the "getvalue()" command.
then you refere to a getcontrol command from the chatmanager.lua. Is that from the regular d20 ruleset? cause in my version it is not defined.

I understand the dragdata part, you actually drag the checkfield and a d100 and a d10 would be roled added up with the modifier (1 in ur case) and the description "My Description" which i can point out when the dice drop on the chatwindow. (ondrop in the chat_chat.lua)
Is that about right?

I need though a number of dice being roled. If the Checkfield has a value of 5 i need 5 dice to be roled not a specific number of dice with a modifier added up.

well probably i didnt understand anything right anyway, but thanks for trying to help me.

Moon Wizard
October 7th, 2008, 08:34
My approach would be to handle this in the onDoubleClick event handler for those fields.

Essentially, you would get the value of the field, insert that number of dice into the throwDice call and you're done.



function onDoubleClick(x,y)
local desc = "My Dice Roll";
local dice = {};
local value = getValue();
for i = 1, value do
table.insert(dice, "d6");
end
ChatManager.getControl().throwDice("dice", dice, 0, desc);
end


You could also enabled dragging from the field like this:



function onDrag(button, x, y, draginfo)
local desc = "My Dice Roll";
local dice = {};
local value = getValue();
for i = 1, value do
table.insert(dice, "d6");
end

draginfo.setType("dice");
draginfo.setDescription(desc);
draginfo.setDieList(dice);

return true;
end


Hope this helps.

Cheers,
JPG
Hope this helps

Fenloh
October 7th, 2008, 10:51
The Drag works wonderfully.

The doubleklick does not work though, it gives me an error, but that is something to worry later about. The Drag is absolutly enough for now.

Two more Questions to that.

1. How do i add the global Modyfierstack to the number of dice instead of being a bonus.
2. The local description shoUld be the description Text of the checkfield which is code like
<description>
<text>My Dice Roll</text>
</description>

I know it is a newbie question.

Thanks again for the help already

Valarian
October 7th, 2008, 12:20
You can roll multiple dice using a variation of the double-click rolling in this thread (https://www.fantasygrounds.com/forums/showthread.php?t=6015).


An enhancement for the chatmanager.lua to add functionality to roll multiple dice. Add it under the d20Check function.


function diceCheck(number, type, bonus, name)
if control then
local dice = {};
for i = 1, number, 1 do
table.insert(dice, type);
end
control.throwDice("dice", dice, bonus, name);
end
end


This can be called as follows in the script sections.


<script>
function onDoubleClick(x,y)
ChatManager.diceCheck(2, "d6", getValue(), window.influence.getValue());
return true;
end
</script>

joshuha
October 7th, 2008, 13:21
Are you coding for a pool system like World of Darkness or Shadowrun?

ShadoWWW
October 7th, 2008, 15:17
We play an RPG, where is 2d6+ system. It means: Roll 2d6.
Example: You rolled "3" and "7", total rolled is 10.
A) If the total rolled is 12, then roll 1d6 as many times as you roll 4-6. Modify the total +1 for every 4-6.
Example: You rolled "6" and "6", then "4" then "2", total rolled is 13.
B) If the total rolled is 2, then roll 1d6 as many times as you roll 1-3. Modify the total -1 for every 1-3.
Example: You rolled "1" and "1", then "1" then "3" then "3" again then "6". Total rolled is -1.
The question is, how the 2d6+ system put as Roll Dice in FG?

Fenloh
October 7th, 2008, 15:36
@ Valerian Thanks for the helpful Codelines.

@Shadowww I hope someone can help you with that question. I can assure you it is possible to code, but how is still a very big clue for me, which will hopefully be solved someday in the future.

@joshua - It is not a WoD-ruleset. I have seen the greatly done Charsheets in one of the postings. I would never be able to do something equal to that. Really fancy.

Fenloh

Valarian
October 7th, 2008, 17:04
The question is, how the 2d6+ system put as Roll Dice in FG?
The code I gave above should allow the rolling of 2d6, you'll just need to change the description (it's an Influence roll from Babylon 5 currently).


We play an RPG, where is 2d6+ system. It means: Roll 2d6.
Example: You rolled "3" and "7", total rolled is 10.
A) If the total rolled is 12, then roll 1d6 as many times as you roll 4-6. Modify the total +1 for every 4-6.
Example: You rolled "6" and "6", then "4" then "2", total rolled is 13.
B) If the total rolled is 2, then roll 1d6 as many times as you roll 1-3. Modify the total -1 for every 1-3.
Example: You rolled "1" and "1", then "1" then "3" then "3" again then "6". Total rolled is -1.
The exploding dice will need a handler within the onDiceLanded function in the chat_chat.lua script. I've done something similar for the Unisystem based on rolling d10s.

Foen
October 7th, 2008, 22:22
you refere to a getControl command from the chatmanager.lua. Is that from the regular d20 ruleset? cause in my version it is not defined.


*blushes*

Err, you're right: the sample code was taken from the Rolemaster ruleset and not the foundation one.

The foundation ruleset didn't expose that functionality, but the following lines should help:



Add to chatmanager.lua
-- Dice rolling
function throwDice(...)
if control then
control.throwDice(...);
end
end


You can then invoke rolls using ChatManager.throwDice(...) rather than ChatManager.getControl().throwDice(...).

Cheers

Foen

Moon Wizard
October 8th, 2008, 07:51
Fenloh,

To add the things you asked about, I would change the code as follows. The only drawback is that the modifier stack will be used and cleared even if you don't drop the dice in the chat box. If you captured in the chat_chat.lua file in the onDiceLanded function, you could throw the modifier stack dice separately.



function onDoubleClick(x,y)
local desc = self.description[1].text[1];
local value = getValue();

if not ModifierStack.isEmpty() then
desc = desc .. " (" .. ModifierStack.getDescription(true) .. ")";
value = value + ModifierStack.getSum();
ModifierStack.reset();
end

local dice = {};
for i = 1, value do
table.insert(dice, "d6");
end

ChatManager.control.throwDice("dice", dice, 0, desc);
end

function onDrag(button, x, y, draginfo)
local desc = self.description[1].text[1];
local value = getValue();

if not ModifierStack.isEmpty() then
desc = desc .. " (" .. ModifierStack.getDescription(true) .. ")";
value = value + ModifierStack.getSum();
ModifierStack.reset();
end

local dice = {};
for i = 1, value do
table.insert(dice, "d6");
end

draginfo.setType("dice");
draginfo.setDescription(desc);
draginfo.setDieList(dice);

return true;
end


Cheers,
JPG

Fenloh
October 8th, 2008, 10:06
I can only bow to you and thank all of you.

Some things are starting to make sense... slowly but surely.



function onDrag(button, x, y, draginfo)

local value = getValue();
local valuedice = getValue();
local desc = self.description[1].text[1];
desc = desc .. " (" .. valuedice .. ")";
if not ModifierStack.isEmpty() then
value = value + ModifierStack.getSum();
valuemod = ModifierStack.getSum();
desc = desc .. " + (" .. valuemod .. ")";
end


local dice = {};
for i = 1, value do
table.insert(dice, "d6");
end


draginfo.setType("dice");
draginfo.setDescription(desc);
draginfo.setDieList(dice);

return true;
end


The good thing is, it almost works the way i want it. It rolls the number of Dice in the checkfield adds up the modifier and the text is also how i want it. There are 2 things though.

1. I know what this does, but i dont know where it is defined: self.description[1].text[1];.
2. If the modifier stack has a number the text displays like this:
"Check (4) + (2)" then the Dice but then again the modifier "+2" I just cant find the definition of that in the foundations mod.

Foen
October 8th, 2008, 21:54
Hi Fenloh, hopefully we are helping more than hindering!


1. I know what this does, but i dont know where it is defined: self.description[1].text[1];.

I'm not sure where this code snippet comes from (I don't think it is in the foundation ruleset) but this style of reference is usually used to access values in the xml.

If your xml (for the ruleset layout controls, for example) looks like:


<stringcontrol name='mystring'>
<anchored>...etc...</anchored>
<mynodes>
<item>hello</item>
<item>world</item>
</mynodes>
</stringcontrol>


You can check if "mynodes" exists by testing for self.mynodes, you can reference the first (and only ) occurence of "mynodes" with self.mynodes[1], you can check if "item" exists with self.mynodes[1].item and you can reference the first "item" with self.mynodes[1].item[1]. In this last case you can also reference the second "item" with self.mynodes[1].item[2].

So you might use the following:


if self.mynodes and self.mynodes[1] and self.mynodes[1].item then
local first,second;
if self.mynodes[1].item[1] then
first = self.mynodes[1].item[1];
end
if self.mynodes[1].item[2] then
second = self.mynodes[1].item[2];
end
end

Often the code will be less verbose and more direct, especially if it assumes its own XML is properly laid out (in which case it may not check each step).

2. If the modifier stack has a number the text displays like this:
"Check (4) + (2)" then the Dice but then again the modifier "+2" I just cant find the definition of that in the foundations mod.

I think you will find that code in applyModifierStackToRoll in chat_chat.lua.

Hope that helps

Stuart

Moon Wizard
October 9th, 2008, 02:41
You have to reset the modifier stack to prevent it from adding the modifier as a number after the dice land, which is the default behavior. In my example, you can see that I reset the ModifierStack after looking at the values.

Cheers,
JPG

Fenloh
October 9th, 2008, 04:28
Ah, the chat_chat.lua was the trick. There the local Variable (desc) is filled with dicetext and the modifier text. Now it works fine, thanks.

Thanks to, jpg.