PDA

View Full Version : Throwing an extra die mid roll...



Blackfoot
February 6th, 2014, 22:24
I have a couple of places in my Champions ruleset where I need to throw a 'd6' and make use of the result as a modifier .. the die isn't adding directly to another roll.. but is altering the final result... something like the wild die does in Savage Worlds. I am thinking there is some way for me to ID this die as special an include it in my roll.. or perhaps I should just roll it separately and use the results immediately..
I think I'm going about this wrong and perhaps it is because I don't really understand what it is doing. This is what I've tried thus far:

if bKilling then
local rStunModRoll = {};
rStunModRoll.sType = "damage";
rStunModRoll.nMod = -1;
rStunModRoll.aDice = { "d6" };
rStunModRoll.sDesc = "[STUN MOD]";
ActionsManager.roll(nil, nil, rStunModRoll);
for i, d in ipairs(rRoll.aDice) do
rRoll.aDice[i].body = rRoll.aDice[i].result;
rRoll.aDice[i].result = d.result * ActionsManager.total(rStunModRoll);
end
end
It performs the STUN MOD roll just fine... clearly there is a result when the die rolls.
My info for rRoll is all good... but ActionsManager.total(rStunModRoll) is coming back as nil.

Trenloe
February 6th, 2014, 22:49
I could be wrong here, but I don't see anywhere in CoreRPG ActionsManager.roll where it sets the result values - it just builds the throw info (rThrow) and calls Comm.throwDie(rThrow) there is not any code to populate any result in the rStunModRoll.aDice table. Have you checked that there are actually any .result values in rStunModRoll.aDice? If there aren't, then that is the reason why ActionsManage.total(rStunModRoll) might be returning nil - or is it returning 0?

Trenloe
February 6th, 2014, 23:36
As more info - the way throw results are handled is asynchronous - there are various ActionsManager.registerResultHandler commands that are set to execute a function when a specific roll type is completed.

e.g. in your code above you set sType = "damage" - this means that if you want to process the result of this roll you will need ActionsManager.registerResultHandler("damage", myDamageResultFunction);

If you are basing your code off the 3.5e ruleset, there is already a damage result handler in \scripts\manager_action_damage.lua - "ActionsManager.registerResultHandler("damage", onDamage);" - this will run the onDamage function when a roll result of type "damage" is received.

So, you'll need to code for your result in the onDamage function in \scripts\manager_action_damage.lua or change the roll type to something specific to your ruleset, write a registerResultHandler for that new roll type and write your result code in the handler function.

Hope that makes sense?

Blackfoot
February 7th, 2014, 02:52
Hrm.. I tried adding a new handler but it doesn't recognize it.

ActionsManager.registerResultHandler("stunmod", onStunMod);
function onStunMod(rSource, rTarget, rStunModRoll)
Debug.chat(rStunModRoll);
endThe debug never reports anything when the roll is made... even though an earlier debug reports that it is getting the right roll type for the handler.

Moon Wizard
February 7th, 2014, 03:17
I think you have to add it to the GameSystem manager script as well, as a valid roll type.

Regards,
JPG

Blackfoot
February 7th, 2014, 03:25
That did the trick... hopefully I can sort it out now.

Blackfoot
February 7th, 2014, 03:31
Cept for one thing... result is there... so umm. I'm back to my original question.

Moon Wizard
February 7th, 2014, 04:02
Are you looking to make exploding dice, or just have the d6 added to your roll at the same time?

The former is more complex. Only RM and SW rulesets have done this, and I haven't worked on those.

The latter can be done by adding a variable to your "roll variable", like rRoll.bStunMod = true and adding the d6 to the end of the dice array. This would need to happen before the dice are rolled, not after they have landed. Then, you can look for the bStunMod tag in the roll result handler function, and modify the result value and icon for the stun die. (I use purple dice in the 3.5E and 4E ruleset to denote dice added by effects.)

Regards,
JPG

Blackfoot
February 7th, 2014, 05:31
There's no real reason that it couldn't be thrown at the same time.. but it has to be separate so that I can multiply the result times the result of the other.
Hmm... so you're suggesting just rolling an extra die... and pulling the last die as the stun mod... that does seem simple enough... actually.. the first die seems like it might be even easier because then I'd always know it was die 1 no matter how many dice were rolled. Hmm... I'll try this approach.
Thanks.

Moon Wizard
February 7th, 2014, 07:43
There's two approaches I can think of off the top of my head:

* Use the new onDiceTotal event to perform the correct calculation on the roll with the stun die included in the roll
* Publish the original roll to the window, skip any roll application code, then trigger a second stun mod roll that does the calculation and applies the roll.

Regards,
JPG

Blackfoot
February 7th, 2014, 08:01
Where can I find more information about 'onDiceTotal' and how it works?

Moon Wizard
February 7th, 2014, 18:22
Here is the documentation I've written so far. It's an event just like chatwindow.onDiceLanded or chatwindow.onReceiveMessage.
https://www.fantasygrounds.com/refdoc/chatwindow.xcp#onDiceTotal

Regards,
JPG

Blackfoot
February 8th, 2014, 00:22
I have this working now.
I ended up doing it as one throw and then pulling the last die out and sending it to the chatwindow separately... I did the whole thing a lot more elaborately than I had originally intended... got a few more things fixed on the Actions Tab in the process... looking pretty cool.

Thanks again for your help guys.