Need Help Making A Skill That Has A Chance To Consume 0 MP When A State Is Applied

Hi, so I'm making a skill in my game that has a 30% chance to consume 0 MP when a particular state is active, but I've been running into some errors with the Skill Cost not appearing or appearing wrong when it's applied. The Skill Cost shows up perfectly fine when the state isn't applied, but when it is applied, sometimes it just won't show up altogether, or it'll show up as 0 MP, which I don't the player knowing for obvious reasons. Also, it'll allow the use of the skill even though the user doesn't have sufficient MP, which I also don't want.

What I want the skill to do is, if the state is applied, the user has a chance to consume 0 MP when using the skill, but they still will require the needed MP to actually perform the skill. Also, the player shouldn't be able to see if the skill will consume 0 MP beforehand since that completely defeats the purpose of the "chance" mechanic if the player knows if it'll consume 0 MP or not.

Could I get some help? Here's the code! And I'll also add some screenshots to give you an example.

Code:
<Custom MP Cost>
if(user.isStateAffected(106) && Math.random() < 0.3)
{
  cost=0;
} else
  cost=1;
</Custom MP Cost>
What I want the skill to do is, if the state is applied, the user has a chance to consume 0 MP when using the skill, but they still will require the needed MP to actually perform the skill. Also, the player shouldn't be able to see if the skill will consume 0 MP beforehand since that completely defeats the purpose of the "chance" mechanic if the player knows if it'll consume 0 MP or not.
id approach it differently then. instead of making it not consume MP 30% of the time, you can have it refund the MP used 30% of the time. you wouldnt have to explain it any differently, and chances are it wont mechanically make a difference
id approach it differently then. instead of making it not consume MP 30% of the time, you can have it refund the MP used 30% of the time. you wouldnt have to explain it any differently, and chances are it wont mechanically make a difference
That probably would work better actually, how would that look like code wise? The code above is one someone made for me from a previous post, I just made slight adjustments.
i cant remember if the tag runs before or after skill costs are paid, but try
Code:
<custom execution>
if (Math.random() < .3)
  user.gainMp(item.mpCost);
</custom execution>
i cant remember if the tag runs before or after skill costs are paid, but try
Code:
<custom execution>
if (Math.random() < .3)
  user.gainMp(item.mpCost);
</custom execution>
Thanks. I'll test it out in the morning.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-making-a-skill-that-has-a-chance-to-consume-0-mp-when-a-state-is-applied.172140/