View Full Version : How to get target data?
jkeller
October 16th, 2025, 21:55
I'm working on an extension to detect and log PC "achievements".
I've found that calling ActionsManager.registerPostRollHandler allows me to get much of the info I need, without affecting current functionality.
But I'm currently having trouble getting the target data (e.g. for when a attack or heal happens).
I can use ActionsManager.registerTargetingHandler("heal", onTargeting), but that seems to interfere with the action. I tried returning false, and keeping a reference to ActionAttack.onTargeting that I could call from my handler, but neither of those approaches worked.
Anyone know how I can can safely get access to the target data?
Thanks!
superteddy57
October 16th, 2025, 21:58
If you are using the action managers, the rTarget is the metadata for the current target that is being processed.
jkeller
October 16th, 2025, 22:08
Right, if I registered a result-handler, I would get the rTarget. I did try that it, but it also interferes with the action. The post-roll-handler seems much safer, but doesn't pass the target.
Trenloe
October 16th, 2025, 22:23
Right, if I registered a result-handler, I would get the rTarget. I did try that it, but it also interferes with the action.
Something you should be aware of - for most of these event handlers there is only a single LUA function ran. If you register your own handler, this would overwrite an existing handler (if one has already been registered_ - so, unless you also call the original handler code in your new handler, you will probably break existing code - which is what you're probably seeing. So, check in the layered ruleset code to find if there is an existing handler registered and also call that handler in your code, or you could extend the existing handler LUA function to also call your code.
Trenloe
October 16th, 2025, 22:38
Following on from my last post. For example, if you want to run your code in the D&D 5E ruleset, running at the end of the onAttack result handler, use the following code in your extension running in a 5E campaign:
function onInit()
-- This overrides the base ActionAttack.onAttack LUA function that is assigned to the result handler for the "attack" action.
ActionsManager.registerResultHandler("attack", my_onAttack);
end
function my_onAttack(rSource, rTarget, rRoll)
if ActionAttack.onAttack then
-- Call the base ActionAttack.onAttack LUA function if it exists.
ActionAttack.onAttack(rSource, rTarget, rRoll);
end
-- Put your custom code here.
end
(Note, I haven't tested this code, but it should be pretty accurate)
jkeller
October 16th, 2025, 23:52
Thanks.
I tried that approach first, and it doesn't work - in that the damage (or heal) isn't applied as it is if I don't register my handler. I tried various combinations of calling the original handler, and returning false. No luck so far. Maybe I did something wrong, but I think I did exactly what you suggested. I'll try again.
EDIT: Clarification - that does work for attack/damage. But I can't get the healing to work the same way (that's what I've mostly been testing with). This is with the registerPostRollHandler and registerTargetingHandler approach:
ActionsManager.registerTargetingHandler("attack", onTargeting);
ActionsManager.registerTargetingHandler("heal", onTargeting);
This code (in my onTargeting) gets the attack/damage to apply.
if ActionAttack.onTargeting then
ActionAttack.onTargeting(rSource, tTargetGroups, rRolls)
end
So hopefully I just need to figure out what to do for healing.
Trenloe
October 17th, 2025, 04:54
What ruleset are you basing this on? If your using the 5E ruleset, check the scripts\manager_action_heal.lua script - there isn't an onTargeting handler via ActionsManager.registerTargetingHandler. So, if you're using an onTargeting handler for an action which doesn't have one normally, you'll need to return aTargeting at the end (refer to onTargeting in scripts\manager_action_attack.lua for an example).
Trenloe
October 17th, 2025, 05:06
As an aside - I'm curious regarding the use of ActionsManager.registerTargetingHandler for getting PC achievement data? What happens if you have multiple targets for the action? I would have thought it would be more accurate (and maybe easier) to use the ActionsManager.registerResultHandler code as this will be called one time for each target. But, I'm not sure exactly what you're trying to do, so this comment may be moot.
jkeller
October 17th, 2025, 14:14
Yes, this is for 5E - though I suppose it could be adapted for other rulesets.
I'll try returning aTargeting, thanks for the suggestions!
I haven't handled multiple targets yet (currently I just get the first element of the first target group), but my approach would be to iterate over the list and process the relevant data (though I'm not sure what that is yet). I assume it would include things like healing-done, and healing-received. I'm updating a list of stats (on a new tab on the character sheet). When these stats meet some criteria (e.g. 1000 points healed), I'll add an achievement.
I did try using registerResultHandler as my first approach (it does have the data), but I must not have been correctly overriding it, because it kept messing up the current behavior. I tried calling the original, and returning false, etc. I don't want to affect any behavior; I just want to scan the data and update some stats. When I found the postRollHandler, that seemed like exactly what I needed.
I think I'm making pretty good progress, but it's going to take a while I'm sure. Each achievement might be very different from other achievements. I assume it will be an evolving project for a while, probably months as I figure out what I want to (and am able to) track.
It's still very rudimentary, but I think it has potential.
65654
Trenloe
October 17th, 2025, 14:41
Looks very cool!
jkeller
October 17th, 2025, 15:21
Thanks! I think it will be a fun extension.
you'll need to return aTargeting
That fixed healing, thanks again!
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.