PDA

View Full Version : Script question (getting info about target)...



TheoGeek
November 14th, 2019, 20:34
I don't know if this is possible, but I've tried a lot of the APIs to get info about PCs and NPCs, but I can't figure out how to get information about the current actor's target. I'd like to try a couple of things for my "Improved Critical" extension, specifically related to if the target is immune to critical damage.

Thanks!

Trenloe
November 14th, 2019, 20:44
Is this as part of an action (dice roll) or outside of the action process?

If part of an action process then the targets should be available individually in rTarget as each action is evaluated, and maybe in the LUA table if there is a targeting handler registered with the ActionsManager.

If you want the targets outside of an action, look at the CoreRPG TargetingManager file \scripts\manager_targeting.lua for some helper functions - like getFullTargets

Kelrugem
November 14th, 2019, 20:55
Trenloe is right :) But, when you're in the second described situation (so when you need getFullTargets) then be aware of that you do not get the target coming from drag&drop, only the ones saved in the CT :) I had a similar question once, too, and MoonWizard described where to look at for such Drag&Drop targets (just in case when you need it, depends on your situation): https://www.fantasygrounds.com/forums/showthread.php?51417-Getting-targets-of-an-actor
(https://www.fantasygrounds.com/forums/showthread.php?51417-Getting-targets-of-an-actor)

TheoGeek
November 14th, 2019, 21:08
It's in my extension that executes instead of ActionDamage.onDamageRoll

Trenloe
November 14th, 2019, 21:28
It's in my extension that executes instead of ActionDamage.onDamageRoll
OK, so by default that function only has rSource and the rRoll LUA tables as this function (ran from an event) is designed to only modify the base damage roll independent of targets. The next step in the action process, onDamage, is used to apply the damage to each target.

What is it you're trying to do? Could you do this before or after this function in the action order?

EDIT: removed comment about sCreatureNode that wouldn't work.

Moon Wizard
November 14th, 2019, 22:36
The callback registered via registerPostRollHandler is used for modifying a roll made by an action which can affect multiple targets, thus targeting does not make sense in this function.

You want to use the callback registered via registerResultHandler to make any target specific roll modifications, as the final roll is applied to each target.

In 5E, a single damage roll can be applied to more than one target.

Regards,
JPG

TheoGeek
November 14th, 2019, 22:44
Yeah, I'm trying to address the issue of the target having adamantine armor (or any other crit immune effect). Currently, this extension maxxes either the damage roll, the critical roll, or both. Adamantine armor ignores critical damage, so it *should* ignore the max damage from a critical hit as well, and just take the original damage roll. Probably.

Anyway, it can be worked around by selecting the crit dice to be maxxed, but you wouldn't want to keep it maxxing the crit dice all the time because this would be pretty OP'd.

This is largely a coding exercise for me because an argument can be made that it does ignore the critical damage (but allows the maximum normal damage from the critical hit). I still want to keep this isolated like it is, so if this isn't possible, I'd rather keep it isolated than add functionality that would require me to modify more files.

Sorry if that was confusing. :)

Thanks for the help!

Trenloe
November 14th, 2019, 23:47
I still want to keep this isolated like it is, so if this isn't possible, I'd rather keep it isolated than add functionality that would require me to modify more files.
MW is suggesting modifying the registerResultHandler function in the same file - so you'd just be switching code from onDamageRoll to onDamage in the same file.

TheoGeek
November 14th, 2019, 23:52
Ahh..got it! I'll check that out. Thanks!

Trenloe
November 15th, 2019, 00:07
To expand on what's going on here - when FG kicks off the damage dice roll this is done asynchronously. That is, the dice are rolled and the original FG code that started the process ends, the code doesn't pause execution.

Then there are two events that kick off ActionDamage code, these are registered at the top of the manager_action_damage.lua file:

ActionsManager.registerPostRollHandler("damage", onDamageRoll);
ActionsManager.registerResultHandler("damage", onDamage);

The first is, as MW mentions, a generic handler that runs immediately after the roll has finished - hence why it's a PostRollHandler - all this can do is modify the base roll, with reference to the roller (rSource) with no targets being taken into account.

Then, after the PostRollHandler (the onDamageRoll function in this case) has executed, the next event is raised - to handle the result of the actual roll - the ResultHandler, in this case the onDamage function). This handler is executed for each target, hence the rTarget record is available in the function:
function onDamage(rSource, rTarget, rRoll)

So, as Moon Wizard suggests, this is a place to make changes to target specific parameters that modify the result. I'd recommend doing it in the applyDamage function - as this is ran as part of the OOB Messaging in onDamage - basically passing the control from the player side to the GM so that they can make any changes to any PC and NPC records as needed. applyDamage is where resistances, vulnerabilities, etc. are all taken into account so this seems like the best place to do things like this, as part of the getDamageAdjust function that gets called within applyDamage.

Trenloe
November 15th, 2019, 00:10
Yeah, I'm trying to address the issue of the target having adamantine armor (or any other crit immune effect).
You can do this without do any coding.

Use the effect IMMUNE: critical on the creature wearing adamantine armour and they won't take any critical damage. See the following example, the critical damage (green dice) is ignored because the target had the IMMUNE: critical effect:

https://www.fantasygrounds.com/forums/attachment.php?attachmentid=30244

Trenloe
November 15th, 2019, 00:16
The immune code is ran in getDamageAdjust which, as I previously mentioned, is ran in the applyDamage function - which is basically the last process to run in the application of damage - running via OOB messaging on the GM instance for each target of the damage action.

Here you see the IMMUNE effect being checked:


function getDamageAdjust(rSource, rTarget, nDamage, rDamageOutput)
local nDamageAdjust = 0;
local bVulnerable = false;
local bResist = false;

-- Get damage adjustment effects
local aImmune = getReductionType(rSource, rTarget, "IMMUNE");
local aVuln = getReductionType(rSource, rTarget, "VULN");
local aResist = getReductionType(rSource, rTarget, "RESIST");


This is largely a coding exercise for me ...
Yeah, you picked probably the most complex process in FG for your exercise!

TheoGeek
November 15th, 2019, 03:11
Yeah, you picked probably the most complex process in FG for your exercise!

HA! Figures.

So, the issue with how my extension currently works is that when a target has the "IMMUNE:critical" effect, and my extension is set to max damage dice and roll critical dice, the critical dice are ignored as expected, but the damage dice is stilll maxxed. I don't have a problem with this result, but some might want to ignore everything about the critical hit and roll damage normally, essentially ignoring the effects of my extension.

I may look into that method - if a critical hit is rolled, and the target is immune to critical hits, then use the normal damage handler, else use mine.

Thanks for all the help with this!