PDA

View Full Version : Creating a dice rolling callback script like manager_action_heal.lua



lokiare
June 18th, 2014, 15:40
I'm attempting to make my own custom script that works in a similar way to the various dice callback scripts. I am getting no errors, and FG is rolling the dice I send in and calling the ModHandler function, but it never gets calls the ResultHandler. I've added my script to Base.xml and am calling it in Manager_char.lua. Did I miss a step or something? Its weird because I see it roll the dice and then I echo when it reaches my Mod function to the chat panel so I know its hitting that, but it doesn't hit my result handler.

My custom lua file is below:

function onInit()
ActionsManager.registerModHandler("pcchar", modRecharge);
ActionsManager.registerResultHandler("pcchar", onRecharge);
end

function modRecharge(rSource, rTarget, rRoll)
local aAddDice, nAddMod, nEffectCount = EffectManager.getEffectsBonus(rSource, {"ABIL"}, false, {""});
if nEffectCount > 0 then
for _,vDie in ipairs(aAddDice) do
table.insert(rRoll.aDice, "p" .. string.sub(vDie, 2));
end
rRoll.nMod = rRoll.nMod + nAddMod;

local sEffects = "";
local sMod = StringManager.convertDiceToString(aAddDice, nAddMod, true);
if sMod ~= "" then
sEffects = "[" .. Interface.getString("effects_tag") .. " " .. sMod .. "]";
else
sEffects = "[" .. Interface.getString("effects_tag") .. "]";
end
rRoll.sDesc = rRoll.sDesc .. " " .. sEffects;
end
local msg = {sender = "13th Age", font = "emotefont", icon = "turn_flag"};
msg.text = "Manager_char->modRecharge()";
Comm.deliverChatMessage(msg);

end

function onRecharge(rSource, rTarget, rRoll)
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
if rRoll.nTarget then
local nTotal = ActionsManager.total(rRoll);
local nTargetDC = tonumber(rRoll.nTarget) or 0;

rMessage.text = rMessage.text .. " (vs. DC " .. nTargetDC .. ")";
if nTotal >= nTargetDC then
DB.setValue(rRoll.nodePower, "used", "number", 0);
rMessage.text = rMessage.text .. " [SUCCESS]";
else
-- Failed to recharge
rMessage.text = rMessage.text .. " [FAILURE]";
end
end
local msg = {sender = "13th Age", font = "emotefont", icon = "turn_flag"};
msg.text = "Manager_char->onRecharge() ";
Comm.deliverChatMessage(msg);

Comm.deliverChatMessage(rMessage);
end

function getRechargeRoll(rActor, rAction)
local rRoll = {};
rRoll.sType = "pcchar";
rRoll.aDice = {};
rRoll.nMod = 0;
--rRoll.DC = rAction.DC;
--rRoll.bSecret = false;
--rRoll.rActor = rActor;

rRoll.sDesc = "[Power Recharge " .. DB.getValue(rAction.nodePower, "name", "{No Name}") .. "]";
for k, v in pairs(rAction.clauses) do
local aClauseDice, nClauseMod = StringManager.convertStringToDice(v.dicestr);
for _, vDie in pairs(aClauseDice) do
table.insert(rRoll.aDice, vDie);
end
rRoll.nMod = rRoll.nMod + nClauseMod;
end
rRoll.bSelfTarget = true;
rRoll.nodePower = rAction.nodePower;

local msg = {sender = "13th Age", font = "emotefont", icon = "turn_flag"};
msg.text = "GetRechargeRoll() ";
if rRoll.nodePower == nil then
msg.text = msg.text .. "rRoll.nodePower == nil; ";
else
msg.text = msg.text .. "rRoll.nodePower ~= nil; ";
end
msg.text = msg.text .. rRoll.sDesc;
--Comm.deliverChatMessage(msg);

rRoll.nTarget = rAction.DC

return rRoll;
end

function performRoll(draginfo, rActor, rAction, rFocus)
local rRoll = getRechargeRoll(rActor, rAction, rFocus);

ActionsManager.performAction(draginfo, rActor, rRoll);
end


I call it with:


local rAction = {};
rAction.name = "pcchar";
rAction.type = "pcchar";
rAction.sTargeting = "self";
rAction.clauses = {};
rAction.nodePower = nodePower;
rAction.DC = 10;

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

PowerRechargeManager.performRoll(nil, rActor, rAction);


I've been wrestling with this for several hours now and I know its something simple and obvious, but I can't seem to figure it out.

Moon Wizard
June 19th, 2014, 01:59
Make sure that you add the roll type to the GameSystem script (actions variable) in the scripts/manager_gamesystem.lua file. Currently, that entry is required for the final result handler to be called.

I'll see if I can remove that dependency in the long term.

Regards,
JPG

lokiare
June 19th, 2014, 03:05
Make sure that you add the roll type to the GameSystem script (actions variable) in the scripts/manager_gamesystem.lua file. Currently, that entry is required for the final result handler to be called.

I'll see if I can remove that dependency in the long term.

Regards,
JPG

That fixed it. Thanks again.