MV Question about a couple of Yanfly's Tips and Tricks

Yanfly has two Tips and Tricks that I am interested in tweaking but I am very unfamiliar with scripting and could use some help. The two I am looking at are Cup of Life and Damage Dispersion. Cup of Life redirects any excess healing back to the caster while Damage Dispersion spreads any damage taken into allies.

What I would like is for both of them to only work when the other allies have State X. So Cup of Life will only redirect any excess healing if the targeted ally has State X and Damage Dispersion will only spread damage into allies with State X. What would I add to the code to insert that qualifier?

Original thread: https://forums.rpgmakerweb.com/threads/question-about-a-couple-of-yanflys-tips-and-tricks.135587/