PDA

View Full Version : [Need Help] Trying to create a custom rollable field, like Initiative



sciencephile
July 5th, 2014, 15:23
Hi, I'm finally breaking down and asking for help. I know I am close to the finish line but just cannot get over this last hurdle for I know I must be missing a small detail but cannot seem to think of it.

I'm modifying a Core-based set. I am trying to create a rollable field for a custom attribute called "Inspiration Check", which totals a character's Wisdom bonus and their character level. Below is the code for the field itself (xml):

From template_char.xml:


<template name="number_inspirationtotal">
<number_linked>
<frame name="fieldlight" offset="7,5,7,5" />
<displaysign />
<rollable />
<source><name>abilities.wisdom.bonus</name><op>+</op></source>
<source><name>inspiration.level</name><op>+</op></source>
<script>
function action(draginfo)
local nodeWin = window.getDatabaseNode();
if nodeWin then
local rActor = ActorManager.getActor("pc", nodeWin.getChild("..."));
ActionInspiration.performRoll(draginfo, rActor, nodeWin);
end

return true;
end

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

function onDoubleClick(x,y)
return action();
end
</script>
</number_linked>
</template>


Here is the lua script code I have (in a lua file called "manager_action_inspiration.lua" - I used "manager_action_init.lua" as a starting point):



function onInit()
ActionsManager.registerModHandler("inspiration", modRoll);
ActionsManager.registerResultHandler("inspiration", onResolve);
end

function getRoll(rActor, bSecretRoll)
local rRoll = {};
rRoll.sType = "dice";
rRoll.aDice = { "d20" };
rRoll.nMod = 0;

rRoll.sDesc = "[Inspiration Check]";

rRoll.bSecret = bSecretRoll;

local sAbility = nil;
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);

rRoll.nMod = DB.getValue(nodeActor, "inspiration.total", 0);
sAbility = DB.getValue(nodeActor, "abilities.wisdom.bonus", "");

return rRoll;
end

function performRoll(draginfo, rActor, bSecretRoll)
local rRoll = getRoll(rActor, bSecretRoll);

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

function modRoll(rSource, rTarget, rRoll)
if rSource then
local bEffects = false;
sActionStat = "wisdom";

-- GET STAT MODIFIERS
local nBonusStat, nBonusEffects = ActorManager2.getAbilityEffectsBonus(rSource, sActionStat);
if nBonusEffects > 0 then
bEffects = true;
rRoll.nMod = rRoll.nMod + nBonusStat;
end

end
end

function onResolve(rSource, rTarget, rRoll)
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
Comm.deliverChatMessage(rMessage);
end


This rolls fine with the exception that it does not add the modifier onto the roll. I suspect that there may be an issue with the nodeActor area of the code or in the sType. If I put a static number for rRoll.nMod, it works fine. If I change the rRoll.sType = "init", it works fine but also changes the combat tracker so I cannot cheat and use that. There is something in the way the sType works that I just cannot seem to pinpoint.

A proper nudge in the right direction by someone out there that knows better would be greatly appreciated.

Thank you.

Trenloe
July 5th, 2014, 16:07
The problem is indeed with your sType variable.

ActionsManager.registerModHandler("inspiration", modRoll) and ActionsManager.registerResultHandler("inspiration", onResolve) are using an Action Type of "inspiration", you dice roll code is using an Action Type of "dice" so modRoll and onResolve will never be called.

Additionally, you need to define "inspiration" as a valid action type in the "actions" table defined in scripts\manager_gamesystem.lua. See post #2 of this thread for details on how to add entries to tables such as these - the example is for DataCommon.conditions, but it equally applies to GameSystem.actions.

If you don't define "inspiration" as a valid action type then the above two handlers won't be called.

sciencephile
July 5th, 2014, 17:02
Thanks. I knew I was missing some script somewhere to add a value, I just couldn't pinpoint it.

I did add the "inspiration" type in the gamesystem file but it still doesn't work. I actually see that the mod doesn't work even if I put it to "init".

I think it seems to be centered around the nodeActor (possibily being null or empty). If I put a static number for the rRoll.nMod, it works fine, even with the newly created "inspiration" type.

For instance,

rRoll.nMod = DB.getValue(nodeActor, "inspiration.total", 0); <-- no mod is applied
rRoll.nMod = 5; <-- mod is applied

Also, you mentioned "see post #2 of this thread for details...". Your post is #2 (there is no other post in this thread).

For testing reasons in the meantime, I just copied over the entire manager_gamesystem.lua to the extension for now.

Thank you.

Trenloe
July 5th, 2014, 18:09
I actually see that the mod doesn't work even if I put it to "init".
"init" isn't a recognised action type in the CoreRPG ruleset. These are the valid actions from manager_gamesystem.lua:

-- Ruleset action types
actions = {
["dice"] = { bUseModStack = "true" },
["table"] = { },
["effect"] = { sIcon = "action_effect", sTargeting = "all" },
};

Trenloe
July 5th, 2014, 18:12
Also, you mentioned "see post #2 of this thread for details...". Your post is #2 (there is no other post in this thread).
Sorry, I forgot to include the link to the thread I was referring to: https://www.fantasygrounds.com/forums/showthread.php?20505-Alignment-Condition-extension&p=168814&viewfull=1#post168814

Trenloe
July 5th, 2014, 18:53
OK, looking at this a bit more - which ruleset are you using? I assume the 3.5E ruleset? I'd originally assumed you were using CoreRPG as you said "Core based" in your OP.

The code for modRoll above will only add ability effects to the roll modifier - nothing else. Your main roll modifier is based off DB.getValue(nodeActor, "inspiration.total", 0).

I suggest you use some Debug.console commands to print variable values to the console - open the console by typing /console in the chat window. Put some Debug.console code at the beginning of each function so you know which functions are being called.

What value is DB.getValue(nodeActor, "inspiration.total", 0) returning? If inspiration.total is not in the character root of the charsheet.id-0000X database entry then this command will return 0. Open your campaign db.xml file and see exactly where inspiration.total is stored for each character.

sciencephile
July 5th, 2014, 18:53
"init" isn't a recognised action type in the CoreRPG ruleset.

Sorry, I guess I wasn't completely thorough in the explanation. I am working on a ruleset extension that is based off of 3.5E, which is based off the Core ruleset. In 3.5E, "init" is a recognized action type.

It seems that no matter what type I use, the nMod doesn't work when getting the value through nodeActor. It works fine if I put a static number on it. I'm sure I will figure it out - I know it is likely a small issue.

Thanks.

sciencephile
July 5th, 2014, 18:54
Sorry, I forgot to include the link to the thread I was referring to: https://www.fantasygrounds.com/forums/showthread.php?20505-Alignment-Condition-extension&p=168814&viewfull=1#post168814

Thank you very much! I will use this, rather than extending the entire script file.

sciencephile
July 5th, 2014, 19:05
I solved the issue. When I copied the action(draginfo) script for the char_template code, I copied one type. That must have been specific for the functionality I copied if from.

I changed it it:


function action(draginfo)

local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
ActionInspiration.performRoll(draginfo, rActor, nodeWin);

return true;

end


It is now working correctly for the "inspiration" type.

Part of learning how to develop in a new system is practice and troubleshooting.

Trenloe, thank you for:


Attempting to help me
Providing information on how to add values to the tables
Giving me a mechanism to talk the process out. Talking it out with someone else does cause revelations for problem situations. This is exactly why eXtreme Programming is so effective (not that I have ever seen it in practice much).

Trenloe
July 5th, 2014, 19:21
Glad you got it sorted in the end.

I frequently find that checking the exact database location of a DB node variable is a good idea - as very often you aren't actually at the db node you thought you were at! Use databasenode.getNodeName() to return the full database location (dot separated) of the db node: https://www.fantasygrounds.com/refdoc/databasenode.xcp#getNodeName

For the above code, use: Debug.console("nodeActor nodename = " .. nodeActor.getNodeName()); Using this immediately before the rRoll.nMod = DB.getValue(nodeActor, "inspiration.total", 0); line would have indicated that the nodeActor database node object was looking at the wrong part of the campaign database.

leozelig
May 6th, 2015, 12:17
I was just learning a little more about this same thing, and I have a question... When creating a custom action manager for a dice roll, does it require a unique type (like "inspiration") or is it ok to use one of the basic types like "dice" (or should it be "number")?

Trenloe
May 6th, 2015, 13:42
When creating a custom action manager for a dice roll, does it require a unique type (like "inspiration") or is it ok to use one of the basic types like "dice" (or should it be "number")?
If you want to do custom handling of the roll (especially the result) then you should create a new action type. Some info to look at here: https://www.fantasygrounds.com/forums/showthread.php?22530-Adding-in-new-dice-mechanics-to-the-CoreRPG-foundation&p=191573&viewfull=1#post191573

leozelig
May 6th, 2015, 17:38
Got it, thanks! This post (and a few others) was very helpful. Thanks for your help!!