PDA

View Full Version : Adding Critical Confirmation Roll to 5E Rule Set Help/Guidance Needed



Nilram the Grey
August 11th, 2016, 03:31
I'm making very slow progress on this. I am new to Lua, so I'm partially trying to get used to the syntax and partially trying to hunt through all the overlaid rulesets to figure out how this works. I wanted to ask some questions to see if I'm even remotely on the right path.

1) It seems that the base.xml file in CoreRPG has a line that defines the contents of the file "scripts/manager_actions.lua" to be what Lua believes to be a table with a number of functions called ActionsManager.<function name>. This is Lua's pseudo attempt at real object oriented code, but is really just a table/array where functions are treated the same as all other data types. I think Lua considers this to be first class values. Am I getting this correct?

2) I can't seem to find any documentation that really covers how the Lua scripts are called by the main application. Basically I can't figure out what triggers what. For example I need to generate an additional dice roll to confirm the potential critical indicated by the initial attack roll. How do I do this. See the code snippet below where I modified a small segment of the manager_action_attack.lua file to attempt to add the critical confirmation logic. I'm not sure how to generate an additional die roll. I can see in the same file there is a function called performRoll that makes a call the ActionsManager.performAction function. Do I just need to make this call again where I have the comment in my code snippet? I'm guessing not because it appears to require that I drag the appropriate attack die to the target, when it would just be much better to have the code automatically roll the attack again. Can I just force a second roll with the same modifiers as the original potential critical roll? All I really need is that information to compare to nDefenseVal in order to complete the logic. I guess it might be nice to output more information chat window.

[MODIFIED CODE SNIPPET]

if rAction.nFirstDie >= nCritThreshold then
-- Confirm Critical if option is set
if OptionsManager.isOption(“ConfrmCrit”, "on") then
-- Generate a second attack die roll somehow with original die roll modifiers
-- Test if second die roll adjusted total exceeds the defense value
if rActionConfirmDieRoll.nTotal >= nDefenseVal then
-- The potential critical is confirmed!
rAction.bSpecial = true;
rAction.sResult = "crit";
table.insert(rAction.aMessages, "[CRITICAL HIT]");
else
-- The potential critical is just a normal hit.
rAction.sResult = "hit";
table.insert(rAction.aMessages, "[HIT]");
end
-- Don’t confirm critical otherwise (Default behavior)
else
rAction.bSpecial = true;
rAction.sResult = "crit";
table.insert(rAction.aMessages, "[CRITICAL HIT]");
end
elseif rAction.nFirstDie == 1 then
rAction.sResult = "fumble";
table.insert(rAction.aMessages, "[AUTOMATIC MISS]");
elseif nDefenseVal then
if rAction.nTotal >= nDefenseVal then
rAction.sResult = "hit";
table.insert(rAction.aMessages, "[HIT]");
else
rAction.sResult = "miss";
table.insert(rAction.aMessages, "[MISS]");
end
end


3) If I make an extension out of this, it seems I'll over to overwrite all the contents of the manager_action_attack.lua file when all I really need is to override this small portion of the code. This makes maintenance much harder as the rule set updates over time. Am I missing something? Since I also want to change the damage on confirmed critical to max damage for the standard damage die plus the normal damage die roll I guess I'll have to completely overwrite all the contents of the manager_action_damage.lua file as well.

4) How do I add an option to the settings for a campaign, so this extension could be turned on or off based on user preference? I can see how to query the value/existence of options by OptionsManager.isOption, but not how to control setting the values in the associated table.


I'm sorry if this is all novice stuff. I tried digging through the documentation, but I'm not finding the answers I need in there.

damned
August 11th, 2016, 03:50
Hi Nilram the Grey

Going thru your code as a quick preview by someone is often pretty ineffective unless they are quite familiar with the code in question already.

To answer some of your other questions -
Extensions often do need maintaining - this can be a bit of a chore - some updates will require you to update your code. Moon Wizard now posts all the files he made changes in when posting up new Versions for testing. You do want to change as small a section as possible to minimise the number of times you have to update your extension. Extensions that modify Combat or the Combat Tracker are often the most complex... especially in rulesets like 5e where there is a lot of complexity already.
If you have a look at the MoreCore extension or a Decal Extension (or the Decal Tutorial on www.fg-con.com/free-downloads) you will see how to create a new option.

Keep working away at it!

Trenloe
August 11th, 2016, 19:41
Sorry, don't have time to do through all of your code.

Have a look at the 3.5e ruleset scripts\manager_action_attack.lua file. There is a "critconfirm" action coded within that script. This will also need to be added to the "actions" and "targetactions" tables in scripts\manager_gamesystem.lua so that FG knows critconfirm is an action.

Nilram the Grey
August 12th, 2016, 01:36
Thanks guys.

damned,

I assume the extension you pointed me to will show me how to "register" new options in the settings?

Trenloe,

I did look at the confirm critical in the 3.5e and in 4e ruleset and they made little sense to me. You supplied me with a pointer to the information I think I was missing. I have to separate out the confirm crit action from the attack action. I suspect that is why those rules sets looked so convoluted to me. I'll re-read them with this fresh bit of knowledge and see what I can do.

I really shouldn't be starting with something this complicated, but honestly most everything else I need is already in place. :D

damned
August 12th, 2016, 01:53
In MoreCore you will find a file data_options_morecore.lua
And yes - this is going to be complicated. The actual code may end up being complicated or simple but getting your head around the existing and complicated code will take some effort.
Using notepad++ and its find in files feature will help you too.
If Trenloe gives you advice... its usually spot on!

Nilram the Grey
August 12th, 2016, 02:39
Damned,

Yeah I read about Notepad++ on these forums, but it isn't available on a Mac. I did find a alternative for macs call Textastic. This has find in files capability and is XML and Lua friendly. Hopefully that tidbit will help other Mac users.

You are dead on. The modification isn't going to be all that hard. It is wrapping my head around how things work that will be the challenge. I'll get there and I'll try to minimize bugging you guys on my journey. Thanks.

Nylanfs
August 12th, 2016, 13:15
I use jEdit for my PCGen and code work.

Nilram the Grey
August 14th, 2016, 04:15
Minor milestone, but I managed to add the confirm critical option to the settings for 5E as an extension. Now I'm back to figuring out the actual code. Baby steps.

damned
August 14th, 2016, 04:44
Minor milestone, but I managed to add the confirm critical option to the settings for 5E as an extension. Now I'm back to figuring out the actual code. Baby steps.

Woot! One step at a time. Add lots of Debug.console statements so that you know what code is getting called and when and what the output is at that stage...