Yanfly Element and Buff/States Core Help

Hello, everyone.


Currently need help with a character's passive state. It's going to involve the Element core mostly as part of one of the character's unique attribute.


- The passive state is applied at the beginning of the battle or She applies a buff to herself whenever needed.


- At the end of every turn, the character would have a random element amplified to do 20% more damage.


- Every turn would continue the same cycle, amplifying a random element until either five turns (As a buff) or until the end of battle (Passive State.)


Help implementing this would be appreciated. I tried rolling a random variable and using the $gameVariables.value(n) tag in an amplify element, but that didn't work.
You need a few steps to make it works


First create a base state, lets call it "Buffer" with id 101


Notetag(using Yanfly buff and state core)


<Custom Battle Effect>
user._randomElement = Math.floor(Math.random() * 10);
user._randomElement += 111;
// this give user random state from 111 to 120
user.addState(user._randomElement);
</Custom Battle Effect>



<Custom Turn End Effect>


// remove state


user.removeState(user._randomElement);


user._randomElement = Math.floor(Math.random() * 10);
user._randomElement += 111;



// adding other random state from 111 to 120


user.addState(user._randomElement);


</Custom Turn End Effect>


<Custom Remove Effect>


user.removeState(user._randomElement);


</Custom Remove Effect>


Then make states from 111 to 120 that gives elemental buff with removed at the end of battle


If you want to make it only work for 5 turns after begins battle(and state is not removed)


<Custom Battle Effect>
user._stateCount = O;
user._randomElement = Math.floor(Math.random() * 10);
user._randomElement += 111;
// this give user random state from 111 to 120
user.addState(user._randomElement);
</Custom Battle Effect>



<Custom Turn End Effect>


// remove state


user.removeState(user._randomElement);


if (user._stateCount < 5) {


user._stateCount++;


user._randomElement = Math.floor(Math.random() * 10);
user._randomElement += 111;



// adding other random state from 111 to 120


user.addState(user._randomElement);


}


</Custom Turn End Effect>


<Custom Remove Effect>


user.removeState(user._randomElement);


</Custom Remove Effect>


Hope it helps a little, if you need diferrent elemental buff states other than multiply of 10 you need to change user._randomElement formula. I`m on mobile so i can't check it but it is in very first lines in one of js engine files in js folder. 
Sorry for doubleposting but cannot modify aboved


There should be also


<Custom Apply Effect>


//reseting count when state is added


user._stateCount = O;


</Custom Apply Effect>


If you want add it middle in battle, as a buff like you say, it only reset or set the count to 0, so firts element buff will be applied in next turn end


Also you may change user.removeState(user._randomElement);


to 


if (user._randomElement > 0) { 


if(user.isStateAffected(user._randomElement) {


user.removeState(user._randomElement);


}}


if somehow it throws error

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-element-and-buff-states-core-help.63880/