death-save / combat-utility-belt

Combat Utility Belt module for Foundry Virtual Tabletop
https://deathsave.dev
GNU General Public License v3.0
53 stars 58 forks source link

Players unable to execute script macros when applying conditions #692

Open sealtrowitz opened 2 years ago

sealtrowitz commented 2 years ago

Describe the bug Players are unable to execute script macro via applying a condition with Enhanced Conditions despite having the proper permissions to execute script macros in the world. The macro execution works fine for the GM.

To Reproduce Steps to reproduce the behavior:

  1. Create any script macro, such as a console.log (actor, token) macro, and set it in the Condition Lab to be executed alongside a certain condition.
  2. When logged in as GM, apply the condition to a token. It should function fine. Remove the condition again.
  3. When logged in as a player, apply the same condition to a token that you own. It does not execute the macro.

Expected behavior Players should be able to execute script macros via applying conditions when those conditions are set up to do so in the Condition Lab.

Screenshots n/a (though I can get some if that would help? just tell me what of!)

Environment Info (please complete the following information):

Additional context Specifically, the macros I am trying to get to work are macros that apply/remove TokenMagicFX visual effects. I also tried giving all players ownership permission of the applicable macros within the macro directory, since I thought that might be what was causing them to not execute, but that did not fix it.

eclarke12 commented 2 years ago

The issue here is that Enhanced Conditions logic is proxied through a GM, so any macros associated to a Condition will be executed by/as the GM. However in most cases this should still result in the desired outcome (eg. the TokenMagicFX being applied/removed). There is possibly some other bug causing the context (actor/token) to not be passed correctly.

thatlonelybugbear commented 2 years ago

A video from the Foundry discord that show cases the same issue when executing a secondary macro with no token selected in the GM's client and the macro breaking as a consequence: https://discord.com/channels/170995199584108546/699750150674972743/1000801560462368839

dodgepong commented 1 year ago

There's a related "bug" here where, since macros that are triggered by conditions being added/removed are run as GM, that means that any reference to, say, canvas.tokens.controlled specifically refers to whichever tokens are being controlled by the GM. If a player adds or removes a condition from a token, and that triggers a macro to be run, if the GM is selecting a different token than the player, the macro will be run as if the GM's selected token is the triggering token rather than the player's. Or if the GM is selecting no token, then canvas.tokens.controlled is empty even when the player triggering the change is selecting one.

Fortunately it looks like Enhanced Conditions passes the actual token/actor being affected as a parameter, an object that either looks like { token: <affected TokenDocument> } or { actor: <affected Actor> }. In CUB 1.9.2 and earlier, this argument can be accessed in the macro with arguments[0].args[1], or in CUB 1.10 and later it can be accessed with arguments[0].args[0]. At least, that's how I was able to get it to work.

dodgepong commented 1 year ago

Update: I forgot I had Advanced Macros installed... the above solution will only work with that installed.