PDA

View Full Version : Looking for piece of code that is fired when an effect is deleted



alloowishus
November 4th, 2024, 03:18
62521

I tried "removeEffect" in manager_effect.lua script and that is not it.

Trenloe
November 4th, 2024, 03:27
This is handled in CoreRPG scripts\manager_combat.lua.

onDeleteCombatantEffectEvent will be called, and this will run any custom delete combat effects functions that have been registered with setCustomDeleteCombatantEffectHandler in the same script. For an example, look at how this is used in scripts\manager_actor_display.lua where a function is registered with CombatManager.setCustomDeleteCombatantEffectHandle r.

alloowishus
November 4th, 2024, 04:00
Thank you!

alloowishus
November 4th, 2024, 04:09
BTW, what is "nodEffectList"? is it a string?
I tried this and got an error
function onDeleteCombatantEffectEvent(nodeEffectList)
local nodeCT = DB.getChild(nodeEffectList, "..");
for _,nodeEffect in ipairs(nodeEffectList) do
....

alloowishus
November 4th, 2024, 04:38
I tried using a Debug.chat("effect list " .. tostring(nodeEffectList)) and got this

s'effect list userdata: 000001E473665388'

What do I do with that? I am just trying to get the name of the effect being deleted.

Trenloe
November 4th, 2024, 14:30
Sorry, I didn't fully look at the example I provided as I was in a rush. That is for deleting effects when an actor is removed from the combat tracker. Sorry about the false lead.

With a brief search, I can't find an individual effect delete handler in CoreRPG. If you're coding on top of another ruleset, there may be one already in that ruleset. Otherwise, you can setup a DB handler to process the on delete events, for example, the following code will run a custom "onCTEffectDelete" function when any effect is deleted from any actor in the combat tracker:


DB.addHandler("combattracker.list.*.effects.*"), "onDelete", onCTEffectDelete);

Refer to the DB.addHandler function here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB

alloowishus
November 4th, 2024, 17:44
Sorry, I didn't fully look at the example I provided as I was in a rush. That is for deleting effects when an actor is removed from the combat tracker. Sorry about the false lead.

With a brief search, I can't find an individual effect delete handler in CoreRPG. If you're coding on top of another ruleset, there may be one already in that ruleset. Otherwise, you can setup a DB handler to process the on delete events, for example, the following code will run a custom "onCTEffectDelete" function when any effect is deleted from any actor in the combat tracker:


DB.addHandler("combattracker.list.*.effects.*"), "onDelete", onCTEffectDelete);

Refer to the DB.addHandler function here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB

Actually I think you were on the right track, I added a little "Hello" debug statement in that function when the effect is deleted and it fired. I just need to find out how to process the nodeEffectList user data.

Trenloe
November 4th, 2024, 18:08
Actually I think you were on the right track, I added a little "Hello" debug statement in that function when the effect is deleted and it fired. I just need to find out how to process the nodeEffectList user data.
In this process you will just get the node that was being deleted. It's a FG databasenode object: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644722/databasenode Hence why you get user data if you try to convert it to a string, as you can't convert an object to a string. Just output the object as part of the debug output but use a comma after the text string and FG will provide appropriate information relating to the object:


function onCTEffectDelete(nodeEffect)
Debug.chat("Node being deleted = ", nodeEffect))
end

alloowishus
November 4th, 2024, 19:53
Ok it looks like it is just the list of effects, not the actual effect that is being deleted

s'effect list ' | databasenode = { combattracker.list.id-00006.effects }


...

Trenloe
November 4th, 2024, 20:13
Ok it looks like it is just the list of effects, not the actual effect that is being deleted

s'effect list ' | databasenode = { combattracker.list.id-00006.effects }


...
Please provide the exact code you're using to setup the handler (DB.addHandler) and the handler function code.

alloowishus
November 5th, 2024, 18:51
So this is what I can up with, found this in the ct_host_entry_section.xml file

<windowclass name="ct_effect">
<margins control="0,0,0,2" />
<script file="ct/scripts/ct_effect.lua" />
<sheetdata>
<base_ct_effect name="base" />

<anchor_ct_effect_left name="leftanchor" />
<button_ct_effect_isactive name="isactive" />
<button_ct_effect_isgmonly name="isgmonly" />

<anchor_ct_effect_right name="rightanchor" />
<button_ct_effect_idelete name="idelete">
<script>
function onButtonPress()
if getValue() == 0 then
if window.delete then
window.delete();
else
effectNode = window.getDatabaseNode();
sEffectName = DB.getValue(effectNode,"label","");

--DB.deleteNode(window.getDatabaseNode());
end
end
end

</script>
</button_ct_effect_idelete>
<button_ct_effect_targetadd name="targeting_add_button" />
<number_ct_effect_init name="init" />
<number_ct_effect_duration name="duration" />

<string_ct_effect name="label" />

<hs_ct_effect_source name="source_name" />
<string_ct_effect_source name="source" />
<string_ct_effect_targets name="target_summary" />
</sheetdata>
</windowclass>

Trenloe
November 5th, 2024, 19:00
So, are you saying you're now going to do your customizations within that FG XML based code? If all you want to do is run code when an effect is deleted through the FG GUI delete button then that will work - but effects could also be deleted via the right-click menu, effects get deleted when they expire and possibly other events; coding here wouldn't run for anything other than using the delete button in the CT.

alloowishus
November 9th, 2024, 00:44
So, are you saying you're now going to do your customizations within that FG XML based code? If all you want to do is run code when an effect is deleted through the FG GUI delete button then that will work - but effects could also be deleted via the right-click menu, effects get deleted when they expire and possibly other events; coding here wouldn't run for anything other than using the delete button in the CT.

I already found the code for the expiration, which for some reason is different than when it is deleted. I never right click to delete so I think I should be ok.