PDA

View Full Version : Convert 4E healing surge value into a dice roll



lokiare
June 13th, 2014, 14:24
I've delved into the code of both the coreRPG ruleset and the 4E rulset, which I'm using as a base for another ruleset.

My problem is I want to change the static healing surge value into a dice roll. I've swapped out on the character sheet the static box for a dice box that you can drag dice onto. I've manage to get all the data inside the right function so when you hit the use a healing surge button it actually gets called and I echoed the data I needed to the console so I know that's working.

My question is what kind of code do I actually need to make FG roll and return a result to me? Can someone explain the process in detail or point me to a way to get a die roll and result?

lokiare
June 13th, 2014, 23:27
for example I use this and it seems to work fine but I get no return value from it:


nSurges = Comm.throwDice("dice", dice, conMod, "recovery");

Trenloe
June 13th, 2014, 23:46
You might want to have a look at the 4E \scripts\manager_action_heal.lua file that deals with heal actions.

And have a look for "ActionHeal.performRoll" within manager_char.lua for an example of how the heal action is started.

lokiare
June 14th, 2014, 01:59
You might want to have a look at the 4E \scripts\manager_action_heal.lua file that deals with heal actions.

And have a look for "ActionHeal.performRoll" within manager_char.lua for an example of how the heal action is started.

I've looked at all that. I can't find the definition of the various tables I'm supposed to pass into it, and it doesn't really tell me how to get a return value. The idea is that I'm altering the "useHealingSurge" function to roll dice so that anywhere that a healing surge is used it will roll dice.

Moon Wizard
June 14th, 2014, 06:12
The individual data structures for each ruleset are very specific to that ruleset, so least likely to be documented vs. documenting CoreRPG functionality.

I'm not familiar with 13th Age, but it sounds like a healing surge just becomes a standard self-healing roll at that point.

The chain of calls I followed to reconstruct the data structure: -> CharManager.onPowerAbilityAction(draginfo, nodeAbility, subtype) -> rActor, rAction = CharManager.getAdvancedRollStructures("heal", nodeAbility) -> ActionHeal.performRoll(draginfo, rActor, rAction)

Try something like:
(Note: This example rolls "2d6+5". To customize for your stuff, you'll need to build a dice string using StringManager.convertDiceToString.)



function useHealingSurge(nodeChar)
local rActor = ActorManager.getActor("pc", nodeChar);

-- Get the character's current wounds value
local nWounds = DB.getValue(nodeChar, "hp.wounds", 0);

-- If the character is not wounded, then let the user know and exit
if nWounds <= 0 then
ChatManager.Message(Interface.getString("message_charhsnotwounded"), false, rActor);
return;
end

-- Determine whether the character has any healing surges remaining
local nSurgesUsed = DB.getValue(nodeChar, "hp.surgesused", 0);
local nSurgesMax = DB.getValue(nodeChar, "hp.surgesmax", 0);
if nSurgesUsed >= nSurgesMax then
ChatManager.Message(Interface.getString("message_charhsempty"), false, ActorManager.getActor("pc", nodeChar));
return;
end

local rAction = {};
rAction.name = "Healing Surge";
rAction.sTargeting = "self";
rAction.clauses = {};

local rActionClause = {};
rActionClause.dicestr = "2d6+5";
rActionClause.stat = {};
rActionClause.cost = 1;
rActionClause.basemult = 0;
table.insert(rAction.clauses, rActionClause);

ActionHeal.performRoll(nil, rActor, rAction);
end


Regards,
JPG

lokiare
June 14th, 2014, 06:45
How do you create a dragdata object without there being a drag? Its required for the function that does rolls
ActionsManager.performAction(draginfo, rActor, rRoll);

draginfo is a dragdata object and the throwdice function that I was using before creates one somehow without any drags on the screen. If there was some documentation about how the 4E rule set worked this would be vastly easier. Instead I'm having to track through miles of code from table to table to try to figure out how to do the simplest things.

Moon Wizard
June 14th, 2014, 07:33
You'll see in the example that I'm passing nil as the draginfo object when calling ActionHeal, since useHealingSurge does not get a draginfo parameter. It assumes you just want to auto-roll. This is consistent with healing surges in 4E, since they do not have a rolling component.

If you wanted to make the healing surge roll draggable: you could also pass draginfo from an onDragStart event to useHealingSurge, add that parameter to the useHealingSurge function and provide that parameter to ActionHeal.performRoll.

By passing nil for draginfo parameter, all the ActionX and ActionManager scripts assume you are double click rolling or button rolling.

Regards,
JPG

lokiare
June 14th, 2014, 08:21
You'll see in the example that I'm passing nil as the draginfo object when calling ActionHeal, since useHealingSurge does not get a draginfo parameter. It assumes you just want to auto-roll. This is consistent with healing surges in 4E, since they do not have a rolling component.

If you wanted to make the healing surge roll draggable: you could also pass draginfo from an onDragStart event to useHealingSurge, add that parameter to the useHealingSurge function and provide that parameter to ActionHeal.performRoll.

By passing nil for draginfo parameter, all the ActionX and ActionManager scripts assume you are double click rolling or button rolling.

Regards,
JPG

Sorry, I didn't refresh my browser and somehow missed your example post. Yeah, actually 13th age uses level * dietype + con mod. However I have the dice in a string from the dice box I put in, so all I needed to know was how to get the roll part working and you explained it perfectly. I can probably figure it out from here. Thank you for your help.

lokiare
June 14th, 2014, 08:25
One question though, what is "rActionClause.stat = {};" expecting to be filled with? is it a string like "abilities.constitution.bonus" or something else?

lokiare
June 14th, 2014, 08:32
Just a follow up, it works flawlessly now.

Moon Wizard
June 14th, 2014, 08:45
Great to hear.
JPG

damned
August 18th, 2014, 16:50
Just a follow up, it works flawlessly now.

@lokiare1 could you please post your complete solution? I would like to see what you did here :)

lokiare
August 25th, 2014, 05:18
@lokiare1 could you please post your complete solution? I would like to see what you did here :)

If you had asked that shortly after I did it, I would be able to show my work, but it might take me awhile to round up the code.

damned
August 25th, 2014, 05:22
go on lokiare1! you can do it!

lokiare
August 26th, 2014, 10:39
The Lua code in manger_char.lua:

function useHealingSurge(nodeChar)
local rActor = ActorManager.getActor("pc", nodeChar);
local level = DB.getValue(nodeChar, "level", 0);
local recoveryDie = DB.getValue(nodeChar, "hp.surge", 0);
local conMod = DB.getValue(nodeChar, "abilities.constitution.bonus", 0);


-- Get the character's current wounds value
local nWounds = DB.getValue(nodeChar, "hp.wounds", 0);

-- If the character is not wounded, then let the user know and exit
if nWounds <= 0 then
ChatManager.Message(Interface.getString("message_charhsnotwounded"), false, rActor);
return;
end

-- Determine whether the character has any healing surges remaining
local nSurgesUsed = DB.getValue(nodeChar, "hp.surgesused", 0);
local nSurgesMax = DB.getValue(nodeChar, "hp.surgesmax", 0);
if nSurgesUsed >= nSurgesMax then
ChatManager.Message(Interface.getString("message_charhsempty"), false, ActorManager.getActor("pc", nodeChar));
return;
end

local rAction = {};
rAction.name = "Healing Surge";
rAction.sTargeting = "self";
rAction.clauses = {};

local rActionClause = {};
rActionClause.dicestr = "" .. level .. recoveryDie[1] .. "+" .. conMod;--"2d6+5";
rActionClause.stat = {};
rActionClause.cost = 1;
rActionClause.basemult = 0;
table.insert(rAction.clauses, rActionClause);

ActionHeal.performRoll(nil, rActor, rAction);
end


In the record_char_main.xml I removed the number box for the healing surge and replaced it with:


<dice_charheal name="healsurge" source="hp.surge">
<anchored to="healsurgesused" position="right" offset="82,0" width="46" />
<modifiersize>mini</modifiersize>
<modifierfield>hp.surgemodifier</modifierfield>
<script file="campaign/scripts/char_recoveryroll.lua" />
</dice_charheal>


In template_char.xml I added:

<template name="dice_charheal">
<basicdice>
<script file="campaign/scripts/char_recoveryroll.lua" />
</basicdice>
</template>

Then I created "campaign/scripts/char_recoveryroll.lua":


function action(draginfo)
local rActor, rAction, rFocus, nodeAbility
rActor, rAction, rFocus = CharManager.getAdvancedRollStructures("heal", window.getDatabaseNode());

ActionHeal.performRoll(draginfo, rActor, rAction, rFocus);
return true;
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end



I had to change quite a few things that were expecting a flat number in various other parts of the rule set.