Thanks for the reply, Tim! I'm only running community scripts; other than some tweaking of character sheets and the huge help you gave me a few months back on my Gaslands game with the Templater script, I haven't done anything with custom scripting, so I'll go ahead and post my macros:
Each character will have an Ability they can click which will deploy a chat menu, and from the chat menu they would click the piece of equipment they want to activate (in this case an M4 assault rifle), which would then (also via chat menu button) allow them to select their fire mode. Single shots and three-round-bursts are all fine and working properly, but as mentioned, the autofire is a different story. Here's the autofire macro that triggers when that fire action is selected:
M4-auto:
!setattr --name Weapons --silent --ident|@{selected|token_id}
!setattr --charid @{selected|character_id} --silent --automod|([[0 - 4 [Base TN] + (@{selected|wounds}-@{selected|wounds|max}) [Wounds] + @{selected|encumbranceMod} [Encumbrance] + ((@{target|size})-(@{selected|size})) [Size Difference] - 2 [Recoil] + ?{Multiple Actions?|No, 0|2 Actions, -2|3 Actions, -4|4 Actions, -6} [Multiple Actions] + ?{Range?|Short, 0|Medium, -2|Long, -4|Extreme, -8} [Range] + ?{Target has Cover?|No, 0|Light, -2|Medium, -4|Heavy, -6} [Cover] + ?{Misc. Modifers (e.g. Aiming, Fatigued, Distracted, target Vulnerable, dim lighting, etc)?|0} [Misc. Modifiers]]])
/w "@{selected|character_name}" &{template:default} {{name=M4 Assault Rifle (@{selected|bar1} rounds)}} {{**Decide how many shots you will fire. If firing at multiple targets, determine in advance how you will allocate your shots:**
[2x (6 rounds)](~Weapons|M4-auto-2)
[3x (9 rounds)](~Weapons|M4-auto-3)}}
(the error hits here, when the user clicks either the 2x (6 rounds) or 3x (9 rounds) chat buttons, since the character token is deselected when the above macro stops running, but the auto-2 and auto-3 macros require a token to still be selected)
M4-auto-2:
!token-mod --ids @{selected|token_id} --set bar1_value|-6
/emas @{selected|token_name} unleashes a burst of fully automatic fire at @{target|token_name}!
[[1d@{selected|shooting} + @{selected|automod}]] First Shot
[[1d@{selected|shooting} + @{selected|automod}]] Second Shot
[[1d@{selected|wilddie} + @{selected|automod}]] Wild die
!roll20AM --audio,nomenu,play|SFX_XCOM_M4_Auto
!delay .4 --!cfx AutoMuzzleFlash @{selected|token_id} @{target|token_id}
!delay 1.4 --!cfx AutoMuzzleFlash @{selected|token_id} @{target|token_id}
``0-3 = Hit;``
``4-7 = Hit + 1 Raise;``
``8-11 = Hit + 2 Raises; etc.``
**Choose the best two results and discard the third, and apply damage by clicking the button below:**
[AP2; 2d8 damage per hit](~Weapons|M4-auto-damage-1)
M4-auto-3:
!token-mod --ids @{selected|token_id} --set bar1_value|-9
/emas @{selected|token_name} unleashes a burst of fully automatic fire at @{target|token_name}!
[[1d@{selected|shooting} + @{selected|automod}]] First Shot
[[1d@{selected|shooting} + @{selected|automod}]] Second Shot
[[1d@{selected|shooting} + @{selected|automod}]] Third Shot
[[1d@{selected|wilddie} + @{selected|automod}]] Wild die
!roll20AM --audio,nomenu,play|SFX_XCOM_M4_Auto
!delay .4 --!cfx AutoMuzzleFlash @{selected|token_id} @{target|token_id}
!delay 1.4 --!cfx AutoMuzzleFlash @{selected|token_id} @{target|token_id}
``0-3 = Hit;``
``4-7 = Hit + 1 Raise;``
``8-11 = Hit + 2 Raises; etc.``
**Choose the best three results and discard the fourth, and apply damage by clicking the button below:**
[AP2; 2d8 damage per hit](~Weapons|M4-auto-damage-1)
(the damage-rolling macros called at the end of the auto-2 and auto-3 macros are working fine as well, so not going to post those unless you think that will help somehow.)
SelectManager looks promising, but can it be called on its own within a macro to select a token? I tried adding:
{& select @{Weapons|ident}}
to the beginning of the auto-2 and auto-3 macros to see if that would work and it unfortunately did not.
I also took a stab at the nesting suggestion but it resulted in the below errors:
No character was found for '-MgdQ6HNha90gue2dfwX'
and
MgdQ6HNha90gue2dfwX X|token_name unleashes a burst of fully automatic fire at Sectoid 01!
Just for reference in case I made a dumb mistake (which is pretty likely), here's the text of the macro with my attempt at integrating the prefix attribute nesting:
!token-mod --ids @{prefix}@{Weapons|ident}|token_id} --set bar1_value|-6
/emas @{prefix}@{Weapons|ident}|token_name} unleashes a burst of fully automatic fire at @{target|token_name}!
[[1d@{prefix}@{Weapons|ident}|shooting} + @{prefix}@{Weapons|ident}|automod}]] First Shot
[[1d@{prefix}@{Weapons|ident}|shooting} + @{prefix}@{Weapons|ident}|automod}]] Second Shot
[[1d@{prefix}@{Weapons|ident}|wilddie} + @{prefix}@{Weapons|ident}|automod}]] Wild die
!roll20AM --audio,nomenu,play|SFX_XCOM_M4_Auto
!delay .4 --!cfx AutoMuzzleFlash @{prefix}@{Weapons|ident}|token_id} @{target|token_id}
!delay 1.4 --!cfx AutoMuzzleFlash @{prefix}@{Weapons|ident}|token_id} @{target|token_id}
``0-3 = Hit;``
``4-7 = Hit + 1 Raise;``
``8-11 = Hit + 2 Raises; etc.``
**Choose the best two results and discard the third, and apply damage by clicking the button below:**
[AP2; 2d8 damage per hit](~Weapons|M4-auto-damage-1)
Appreciate your help on this!