MZ [Skills and States Core VisuStella] Skill Cost Type with SP/AP?

(English is not my native language, sorry for my english google translate)

I came across this post a while ago, which helped me at the time, and going back to it recently I had a question about one of this effects:

Spoiler: Stat Upgrades
Requires the tier 2 Skill Learn System plugin.
If you wish to use Job Points for advancement, this will also require the tier 2 Class Change System plugin, but you can achieve the same effect using Skill Points or Ability Points.

JavaScript:
<JS On Learn Skill>
const id = 0;
user._paramPlus[id] += 200;
user._upgradeParam ??= [];
user._upgradeParam[id] ??= 0;
user._upgradeParam[id] += 1;
user.forgetSkill(skill.id);
user.refresh();
</JS On Learn Skill>

<JS Learn SP Cost>
const id = 0;
user._upgradeParam ??= [];
user._upgradeParam[id] ??= 0;
cost = 1000 + user._upgradeParam[id] * 200;
</JS Learn SP Cost>

<Hide in Battle>

The code supplied is for adding 200 to HP per upgrade.
Adjust the param ID and additional values according to your needs. (1 = MP, 2 = ATK, 3 = DEF, 4 = MAT, 5 = MDF, 6 = AGI, 7 = LUK)

Looking back at this, I tested it on my MZ project, and it works great, but I realized that it doesn't necessarily match the way I manage skills to the actors in my game.

I have a problem with the fact that it's a skill to learn, but I like the idea of using SP, or even AP, for this effect.

So here is my question :

Is there a way to use SP (or AP) as skill cost?

What I would like to have in the end is not a skill to learn, but a normal skill with the effect "Stat Upgrades", with SP (or AP) as a cost.
I want to point out that this would concern skills that can only be used outside of combat.


SkillsStatesCoreParams02.png


I know that in Skills and States Core VisuStella plugin we can configure different types of costs.
(<- Skill States Core Parameter / Skill Cost Types )
​


Used with the notetag <Skill Cost: x>, that would be the solution.


But if anyone has a better idea to achieve the same result (use SP or AP as cost), I'm certainly interested.



Given my level of coding/development, I am absolutely not capable of creating a new type of cost.

But if any generous person feels the need to help a big noob, I would be very grateful.

And please feel free to give ideas if you have any, it can always help.
Do you need to go fancy with skill cost types if you don't have rates affecting the costs and don't use them in battle etc? Just use skill notetags (and put effect to grow the parameter):

<JS Skill Enable>
enabled = user.getAbilityPoints(0) >= 10;
</JS Skill Enable>

<Custom Cost Text>
This skill costs 10 AP.
</Custom Cost Text>

<JS Post-Apply>
user.loseAbilityPoints(10, 0);
</JS Post-Apply>
Do you need to go fancy with skill cost types if you don't have rates affecting the costs and don't use them in battle etc?

I was really hoping someone would give me another solution.
Yours is definitely easier to set up.

I got stuck on my first idea, without imagining another way to do it, which led me to make this post.

<JS Skill Enable>
enabled = user.getAbilityPoints(0) >= 10;
</JS Skill Enable>

<Custom Cost Text>
This skill costs 10 AP.
</Custom Cost Text>

<JS Post-Apply>
user.loseAbilityPoints(10, 0);
</JS Post-Apply>

It works fine for me after trying, but regarding the <JS Post-Apply>, is it possible to do as the Stat Upgrades effect?

That is, the more you use the skill, the more the cost increases.
Yeah, I think you can put your own property on the actor. And then make any kind of formula you like. For example:

<JS Skill Enable>
const addCost = user._myUpgrade1 || 0;
enabled = user.getAbilityPoints(0) >= 10 + addCost * 2;
</JS Skill Enable>

<JS Post-Apply>
user._myUpgrade1 = user._myUpgrade1 + 1 || 0;
user.loseAbilityPoints(10+user._myUpgrade1 * 2, 0);
</JS Post-Apply>
<JS Skill Enable>
const addCost = user._myUpgrade1 || 0;
enabled = user.getAbilityPoints(0) >= 10 + addCost * 2;
</JS Skill Enable>

<JS Post-Apply>
user._myUpgrade1 = user._myUpgrade1 + 1 || 0;
user.loseAbilityPoints(10+user._myUpgrade1 * 2, 0);
</JS Post-Apply>

Everything works fine, it's perfect. Thanks a lot.
The last point to resolve that comes to mind would be the <Custom Cost Text>.

<Custom Cost Text>
text
</Custom Cost Text>

- Used for: Skill Notetags
- Allows you to insert custom text into the skill's cost area towards the
end of the costs.
- Replace 'text' with the text you wish to display.
- Text codes may be used.

If I understand correctly, we can use text code, but can we display the current cost of the skill, even after each use? (and not just its initial cost)
Try to add:

<JS Skill Enable>
const addCost = user._myUpgrade1 || 0;
$gameVariables.setValue(10, 10+addCost*2);
enabled = user.getAbilityPoints(0) >= 10 + addCost * 2;
</JS Skill Enable>

<Custom Cost Text>
This skill costs \V[10] AP.
</Custom Cost Text>

PS. Also, in that post-apply stuff, change 0 after || to 1

EDIT: (and make another small change)
<JS Post-Apply>
user._myUpgrade1 = user._myUpgrade1 + 1 || 1;
user.loseAbilityPoints(10+(user._myUpgrade1-1) * 2, 0);
</JS Post-Apply>
<JS Skill Enable>
const addCost = user._myUpgrade1 || 0;
$gameVariables.setValue(10, 10+addCost*2);
enabled = user.getAbilityPoints(0) >= 10 + addCost * 2;
</JS Skill Enable>

<Custom Cost Text>
This skill costs \V[10] AP.
</Custom Cost Text>

<JS Post-Apply>
user._myUpgrade1 = user._myUpgrade1 + 1 || 1;
user.loseAbilityPoints(10+(user._myUpgrade1-1) * 2, 0);
</JS Post-Apply>

Everything is working properly.
The cost text is also updated correctly and is specific to each actor.

I wouldn't have made it without your help, so thank you very much 🙂

I will now look at how to show the number of AP/SP that the actor has at the time of using the skill because currently you have to go back to the Learn menu to get this information.

I'm asking just in case, but if we can retrieve the information, can we put it in the cost text with another variable (for example \v[11] ) like to show the number of AP?

which could give for example:
<Custom Cost Text>
This skill costs \V[10] / \V[11] AP.
</Custom Cost Text>

With \V[10] : current cost, and \V[11] : current number of AP of the actor.

I also thought about putting this information directly in the skill description but it doesn't update immediately.
You have to select something else (another skill for example) and then return to the skill so that the description displays the current updated cost.
So it remains less practical than putting it in the cost text.

Screenshot1.png
Screenshot2.png


I just realized that in the end, when using the skill, we did not see the cost text, but only the description of the skill.

Screenshot3.png


I feel like I'm going to have to use the skill description in any case.
Put this as a plugin file to update it (I tested using the refresh from the notetag, but it didn't seem to work):

Scene_Skill.prototype.useItem = function() {
Scene_ItemBase.prototype.useItem.call(this);
this._statusWindow.refresh();
this._itemWindow.refresh();
this._helpWindow.refresh();
};

If you want to do that variable thing, you can set variable 11 in 'JS skill enable' to:
$gameVariables.setValue(11, user.getAbilityPoints(0));
If you want to do that variable thing, you can set variable 11 in 'JS skill enable' to:
$gameVariables.setValue(11, user.getAbilityPoints(0));

Tested. It works very well.

Put this as a plugin file to update it (I tested using the refresh from the notetag, but it didn't seem to work):

Scene_Skill.prototype.useItem = function() {
Scene_ItemBase.prototype.useItem.call(this);
this._statusWindow.refresh();
this._itemWindow.refresh();
this._helpWindow.refresh();
};

I didn't immediately understand what I had to do with this code.
I ended up creating a new plugin file with it, and after testing it, everything works fine.

Thank you very much for your help, we spent a little time on it but it's exactly how I imagined it would work.

Do I have your permission to cite you as the author of the plugin? Since you gave me the code.
Cool. Yeah no need for credits, I just added one line to base game function.

Original thread: https://forums.rpgmakerweb.com/threads/skills-and-states-core-visustella-skill-cost-type-with-sp-ap.179366/