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.
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.