Run Common Events in a State?

Hello!
I have been trying out some new things for my game. Right now, I'm trying to make an item that can only be used in battle, heals 5HP every turn until the battle is over or the player runs out of gold, and every turn, drains 1 gold from the player after use.
I set up a common event to deal with the gold, but I want the item to add a state to the character that runs every turn, and activates the common event. Is there a way I can run a common event in a state?
Thanks in advance!
You can't call a common event from a state, unfortunately. The good news is, though that with a couple of plugins, you can definitely achieve this effect without a common event at all.

With the Buffs and State Core plugin from yanfly, you can use lunatic mode coding to remove gold per turn that the state is active, using the following note tag on the state:

Code:
<Custom Regenerate Effect>
$gameParty.gainGold(-1);
</Custom Regenerate Effect>
The above tag will drain 1 gold per turn that the state remains active, but we can also change it so that if this is your last gold, it will remove the state!

Code:
<Custom Regenerate Effect>
$gameParty.gainGold(-1);
if ($gameParty._gold <= 0) {
 user.removeState(stateId);
}
</Custom Regenerate Effect>
This will remove the state if the party has zero or fewer gold left after the regeneration effect.
Ah, thank you very much!
However, I seem to be getting type errors whenever I initiate a battle. When I have Yanfly's Battle Engine Core off, it's this:
Cannot read property 'parent' of undefined
But when it's on, it says this:
Failed to execute 'createLinearGradient' on 'CanvasRenderingCOntext2D': float parameter 3 is non-finite.
When only the Core plugin is on, there are no errors. Anyway I could fix this?
EDIT: I looked at the error console, and for the latter error, it says this:
Spoiler: error console
TypeError: Cannot read property 'parent' of undefined
at Sprite.addChildAt (pixi.js:8196)
at Spriteset_Battle.updateZCoordinates (YEP_BattleEngineCore.js:3122)
at Spriteset_Battle.update (YEP_BattleEngineCore.js:3108)
at Spriteset_Battle.Spriteset_Base.initialize (rpg_sprites.js:2127)
at Spriteset_Battle.initialize (rpg_sprites.js:2428)
at new Spriteset_Battle (rpg_sprites.js:2421)
at Scene_Battle.createSpriteset (rpg_scenes.js:2150)
at Scene_Battle.createDisplayObjects (rpg_scenes.js:2140)
at Scene_Battle.create (rpg_scenes.js:2033)
at Function.SceneManager.changeScene (rpg_managers.js:1810)
For the former, it says this:
Spoiler: error console 2
TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': float parameter 3 is non-finite.
at TypeError (native)
at Bitmap.gradientFillRect (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_core.js:997:24)
at Window_BattleStatus.Window_Base.drawGauge (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:469:19)
at Window_BattleStatus.Window_Base.drawActorHp (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:555:10)
at Window_BattleStatus.drawGaugeAreaWithTp (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:5525:10)
at Window_BattleStatus.drawGaugeArea (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:5518:14)
at Window_BattleStatus.drawItem (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:5491:10)
at Window_BattleStatus.Window_Selectable.drawAllItems (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:1250:18)
at Window_BattleStatus.refresh (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:5485:10)
at Window_BattleStatus.initialize (file:///D:/me/Documents/MVGames/GameTitle/js/rpg_windows.js:5463:10)
Is the stateId replace with the id of the state? Cuz that maybe you're problem.
Why can't you just set it up via troop events? On each turn, check to see if the character is affected by the state. If they are, check how much gold they have. If they have enough, decrease gold and increase HP.

I don't see why you have to rely on a script for this.
@Zarsla This was likely a problem, but changing it did not affect the error. Thank you for the advice, though!

@Shaz Because since this works off an item, using troop events would cause me to have to apply that same event to every troop, which is both a hassle and a waste of space.

Also, it it just me, or do the errors seem mostly centered around sprites and graphics? I added the error console for the other error as well, by the way.
I know that it hasn't been three days exactly yet, but I'll just bump this thread up anyway.
Again, bump.

...I'm so lonely here...
Unfortunately I cannot help with any plugin issues right now, but you could save some of the work using Shaz's solution for now if you put all of your code into a Common Event (and call that event from the troop page using the "Call Common Event" command).

This way you'd still have to copy the troop event page for every troop, but modifications to your state as well as additional similar states can be done by changing the common event without the need of touching the troop events ever again.
In my experience, the gradient error messages only come up when you end up accidentally dealing with an hp/mp or I guess tp value that isn't a whole number. The code I gave you for the state itself wouldn't cause that, as it isn't dealing with any of those values, though.
I am not sure what the other error message indicates. It seems like maybe both errors are pointing towards a battler or sprite that doesn't exist, or was improperly created by a plugin, but buffs/states core doesn't really deal with that. It could be a plugin incompatibility.

Original thread: https://forums.rpgmakerweb.com/threads/run-common-events-in-a-state.79281/