MV Yanfly SkillCore + Limited Uses custom cost issues

I have two skills. One is a limited use skill that is firing a gun. The other is reloading the gun. The cost of reloading is based in gold (in-world the currency is indeed bullets), I'm not sure if that is the complication here. On top of that, I've replaced the stats so that defense is "Resourceful" and makes it cheaper to reload guns. Here's how I've built the reload skill (thanks to a lot of internet searching):

Code:
<Skill 18 Limited Uses: +4>
<Custom Requirement>
user._goldCost = Math.ceil(6 * (1 - (a.def * 0.08)));
   if ($gameParty.gold() > user._goldCost) {
     value = true;
   } else {
     value = false;
   }
</Custom Requirement>

<Custom Execution>
$gameParty.loseGold(user._goldCost);
</Custom Execution>

<Cost Display Eval>
user._goldCost = user._goldCost || 0;
var variableId = 4;
var value = user._goldCost;
$gameVariables.setValue(variableId, value);
</Cost Display Eval>

<Custom Cost Display>
\v[4] \G
</Custom Cost Display>

This all works, however I've encountered two problems I'm not sure how to fix, or if they can be fixed:

1. The display for the ammo cost does not update until I've entered combat. I think I have to use the skill as well. So it just says the cost is "0 ammo". Once I've used it in combat, it'll say "6 ammo", or "5 ammo" if I raise my defense stat.
2. I can't use the reload skill from the menu, only in combat. When I try, it just gives me an error sound like I'm out of "mana" or something.

As a bonus question, I was wondering if I could fix this (although not necessary):
3. I'm able to use the reload skill even at full ammo. I think this is just default RPM logic, though, since you can also do things like heal a full HP ally.

EDIT:
It turns out the cost eval was the culprit. I never liked that OR, but didn't think that would break the whole thing when I try to change the variable. Here's how it looks now:
Code:
<Cost Display Eval>
user._goldCost = Math.ceil(6 * (1 - (a.def * 0.08)));
var variableId = 4;
var value = user._goldCost;
$gameVariables.setValue(variableId, value);
</Cost Display Eval>
You have some wonkiness in your code, but it shouldn't be too hard to do what you want.
2. I can't use the reload skill from the menu, only in combat. When I try, it just gives me an error sound like I'm out of "mana" or something.
The menu won't let you skills that don't "do" something - it can't read notetags to see that the skill will change anything on the target character. Try using the traits section to add a state, then immediately remove the same state. That should do it.
3. I'm able to use the reload skill even at full ammo. I think this is just default RPM logic, though, since you can also do things like heal a full HP ally.
Just add it to your custom requirement.
Code:
<Custom Requirement>
user._goldCost = Math.ceil(6 * (1 - (a.def * 0.08)));
value=user.skillLimitedUseCurrent(this.itemId()) < user.skillLimitedUseMax(this.itemId()) && $gameParty.gold() > user._goldCost;
</Custom Requirement>
Code:
<Cost Display Eval>
user._goldCost = Math.ceil(6 * (1 - (a.def * 0.08)));
var variableId = 4;
var value = user._goldCost;
$gameVariables.setValue(variableId, value);
</Cost Display Eval>
If it pleases you, it doesn't break anything, but this would be half the size if you didn't declare extra variables you only use once and don't manipulate at all.
Code:
<Cost Display Eval>
user._goldCost = Math.ceil(6 * (1 - (a.def * 0.08)));
$gameVariables.setValue(4, user._goldCost);
</Cost Display Eval>
The menu won't let you skills that don't "do" something - it can't read notetags to see that the skill will change anything on the target character. Try using the traits section to add a state, then immediately remove the same state. That should do it.

I love stuff like this, haha. I did that and made it even sillier by giving the state a 0% chance to succeed. So weird because I can use attacks from the menu even though I obviously don't have a valid target. Anyway, this works, thanks!

Just add it to your custom requirement.

I figured something like this was possible, but I'm such a novice I never know the syntax or how to figure it out. This works with a little modification (since it's a different skill it needs to check for the limited uses). Interesting how you wrote the value part. I never would have thought to do this without using an "if" statement:
Code:
value = user.skillLimitedUseCurrent(18) < user.skillLimitedUseMax(18) && $gameParty.gold() > user._goldCost;
Thanks, again!

If it pleases you, it doesn't break anything, but this would be half the size if you didn't declare extra variables you only use once and don't manipulate at all.

You know, I *thought* that was pointless to have those in there, but I just meekly copied the code as written. Seems like a good idea to clean those out, I guess in case I declare variables elsewhere and use the same ones by accident and trip things up?

Anyway, I guess you've got me covered! You're amazing! 😀
I never would have thought to do this without using an "if" statement
Yeah - any time you find yourself writing an if statement when the only thing you change is a boolean, you can always get rid of it since the result of a condition is a boolean value. I know Yanfly does it in all of the Tips & Tricks, and it doesn't hurt anything, but I was taught to code with efficiency in mind, so it hurts a little piece of my soul to see stuff that takes up lines and lines more than it needs to 😉

Heck, all of the braces in those cases are also unnecessary, since an if or else automatically applies to the next single statement...so if you're just saying value=true; you don't need braces around that.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-skillcore-limited-uses-custom-cost-issues.143603/