State/Scripting Help

Hi sort-of newbie here,

I need a bit of help with some mechanics in my game, hopefully I can explain my problem well.

Basically, my game has five elements, Fire, Earth, Metal, Water and Wood. Hitting an enemy with an elemental attack gives them a weakness to the next element along the "chain" (Fire > Earth > Metal > Water > Wood > Fire). This weakness increases the longer the chain is kept going, topping at 3x (so 1.5x, 2x, 2.5x then 3x). Further attacks would just keep the weakness multiplier at 3x. However if the wrong element was used, the "chain" would reset back to a 1.5x weakness to the next element.

For example, if an enemy is hit with a Fire attack, they'd gain a 1.5x weakness to Earth attacks, then if they were hit with an earth attack they'd gain a 2x Metal weakness. However, if they were then hit by Water attack, they'd lose the 2x Metal weakness, but gain a 1.5x weakness to Wood, which would become a 2x Fire weakness if they were hit with a Wood attack.

I use states with the each of the elements and weakness levels, so 20 all up. So my idea was to have each attack check to see if the target had particular state (a weakness to the attacking element), add the appropriate state and remove the original. I (miraculously) got this a prototype to work with MV thanks Yanfly, but I've since switched to MZ. Which due to the changes in how MZ operates, means my prototype no longer works.

At the moment I'm trying to run a Common Event for each element. But I can't seem to get it to work, as I'm not very experienced with scripting. My major problem is I'm not sure what code to use to check the target's state, as the options menu only asks for specific enemies not generic ones. If anyone is able to help me that would great.
(Apologies for double posting). Right, so I solved this by modifying my old prototype along with some trial and error. The idea is to get the script to check if the target has a certain weakness (state) or not and apply the next appropriate weakness (state) in the sequence.

Here's a copy of the code I'm using. Obviously I'm switching out the state numbers for each element, but otherwise their all identical.

1638326027506.png


This code works, but if there was any way to make it run smoother, I'd love to hear about it.

Original thread: https://forums.rpgmakerweb.com/threads/state-scripting-help.141867/