MZ Help to finish a plugin script for a Skill Type Swap System

I wrote a plugin that makes States permanent, they persist after the three “this.clearStates();” checks are done, so I can use them for a dynamic Skill Types system.

I want to make this plugin only works with States marked with a specific Note Tag, but I couldn’t figure out how to make the checks.


So in the context of Game_BattlerBase.clearStates(), you'd have to look at the individual IDs stored in this._states and check $dataStates[id].meta["notetag name"]
Something like this?

const Game_Actor_setup = Game_Actor.prototype.setup;

Game_Actor.prototype.setup = function (actorId) {
// Call the original function
Game_Actor_setup.call(this, actorId);
this._states = $dataStates[id].meta["Permanent"].meta.state || null;
};

if (actor.state) {// Script here later
I was trying to use a tutorial that I found here, but it was about Actors and Nicknames. I’m not sure how to translate it to States.
No, that's not correct.

All of this relies on you having some moderate knowledge of JavaScript - if you don't yet, you're really better off doing tutorials until you understand the syntax better rather than trying to modify too-advanced things and just guessing.

this._states = $dataStates[id].meta["Permanent"].meta.state || null;
1 - You're setting a property that's an array equal to a non-array value.

2 - id is not a variable you defined or initialized anywhere.

3 - Why are you trying to do this inside Game_Actor.setup()? It should be inside Game_BattlerBase.clearStates(), as I said in my previous reply.

4 - Where did the syntax meta["Permanent"].meta.state come from? That's not what I said in my post, nor what either thread I linked for you said.

5 - Why would your default be to set this._states to null? That's not done anyplace in MZ's code.

6 - Calling the original method before running your extra code defeats the point; by the time your code sees anything, the states will have been cleared.

if (actor.state) {// Script here later
That wouldn't do anything, there's no such property as state on a Game_Actor.
I only found one tutorial about tags, how to check tags in the plugin, but it was about Actors and Nicknames. I tried to change things to work with States, but I’m not sure what to do.

I just wanted the plugin to recognize a tag in a State.
I only found one tutorial about tags, how to check tags in the plugin
I don't understand what you're talking about. I linked you to two threads in my first reply that explain the structure and syntax, one of which specifically talks about states.

I also gave you the specific syntax you would use in my first reply - but, again, this isn't just something you can copy and paste in if you don't understand JavaScript syntax.

You might be better off with a Plugin Request thread - there are existing plugins that make states persist after death by using a notetag. You don't need to write your own.
I couldn’t find a good simple plugin or an updated one, that worked on the project so I was trying to learn how to make my own.

I needed something simple to happen, which I managed to make it work, but I needed to attach a tag to make sure it only worked when necessary.

Game_BattlerBase.clearStates() = function(stateId) {
var checkState = $dataStates[stateId].meta.state;
if (checkState === "Permanent") {
//The part bellow here is already working:
// When dying:
Game_BattlerBase.prototype.die = function() {
this._hp = 0;
this.clearBuffs();
};
// When healing:
Game_BattlerBase.prototype.recoverAll = function() {
this._hp = this.mhp;
this._mp = this.mmp;
};
// When escaping battle:
Game_Battler.prototype.escape = function() {
if ($gameParty.inBattle()) {
this.hide();
}
this.clearActions();
SoundManager.playEscape();
};
};
};

Would the Plugin Request thread helps me finish that? How should I request it?

A way to finish this code that I wrote? Should I request a full code that does this one thing?

Could I do that without plugins or at least without tags?

I never used a forum request before.

Following your recommendation, I prepared a post for the “JS Plugin Requests”, detailing what I need and what I had done so far, I’ll see if I can get help completing the plugin or if there is another solution there.

Thank you for your time mr. ATT_Turan.

Case closed.
I need help to finish a plugin script that I was working on for a Skill Type Swap System. The script itself is about a simple State persistence thought the three “this.clearStates();” checks, I need to apply this effect only in States that have a Note Tag associated (e.g.: <state: permanent>).

// When dying:
Game_BattlerBase.prototype.die = function() {
this._hp = 0;
this.clearBuffs();
};

// When healing:
Game_BattlerBase.prototype.recoverAll = function() {
this._hp = this.mhp;
this._mp = this.mmp;
};

// When escaping battle:
Game_Battler.prototype.escape = function() {
if ($gameParty.inBattle()) {
this.hide();
}
this.clearActions();
SoundManager.playEscape();
};

I tested the script and it already works, but I don’t know how to implement Tags in it, so the script applies itself to all States in the project. I needed to attach it only when necessary, the States associated with the Skill Types, to avoid breaking all the other vanilla States.

The idea behind all that is to use States that hold Skill Types for customizing characters between two Classes. When the character activates a specific event, it will have its Class changed and a “major” Skill Type attributed to it, all other Skill Types will be removed. Afterwards the character can add a second “minor” Skill Type, as long it knows at least one Skill from that Skill Type.

This will help with the customization of Class Builds, it also helps on a separated system of Dynamic Leveling already implemented and I guess it could be used to apply passive effects as well, like diseases/blight, which can be only be cured with events and script calls.
I tested the script and it already works, but I don’t know how to implement Tags in it, so the script applies itself to all States in the project. I needed to attach it only when necessary, the States associated with the Skill Types, to avoid breaking all the other vanilla States.
FWIW, instead of removing the clearStates() call from those places, i would have either changed clearStates() to loop over the actor's states and call remove/eraseState() if the state isnt a permanent state, or changed states() to pick up your special states and make some other property on the actor to hold them
Would it still need to use Note Tag functionality?

Because my main issue is that I still don’t understand how Tags are checked, I think that checking a Tag and running this script will fulfill my goals based on the tests I did so far.

When you mean “other property on the actor to hold them”, you mean like a custom script property?

Or is it like using a hidden Equipment to hold the Skill Type?
Would it still need to use Note Tag functionality?
the first method, yes. the second, no.

if you go the first route where you edit clearStates(), then while looping over the actor's states you would set a condition check if the state's meta property has a .Permanent property within it, give the special states a <Permanent> tag, and have that determine if the state gets removed or not.

for the second method youd write extra properties onto the actor like actor._primary and actor._secondary. thosell hold a reference to whatever state you need considered and then youd extend the states() function to also push the states contained by _primary and _secondary into its returned array.
Would be something like this?

Game_Temp.prototype.dualClass = function() {
return this.actor._primary;
return this.actor._secondary;
};

if (this._classId == 1){
this.actor._primary == 41

}
Checks the class and assign a number to Primary, then I should convert Primary to a State?

Then I do the same for Secondary and call individual triggers for each?

Then I make Primary and Secondary skip the previous checks. Could I program the reserved States to skip the previous check instead?

I’m not very good at scripting, so I thought that assigning a Tag on the previous script that was already working would be simpler for someone like me.
Would be something like this?
no

Spoiler
Game_Temp.prototype.dualClass = function() {
1) I hadnt mentioned $gameTemp, and im unsure of a reason to have this function in it.

return this.actor._primary;
2) unless you give $gameTemp an actor property, calling that function will just crash the game

return this.actor._primary;
return this.actor._secondary;
3) functions end whenever return is called. the second line will never be reached

if (this._classId == 1){
this.actor._primary == 41
4) half of the code is outside of the function, and i cant tell if it is to be a part of a new one or unreachable in the current one.

Game_Temp.prototype.dualClass = function() {
...
};
...
}
5) the extra closing parenthesis would also cause an error.

if (this._classId == 1){
6) if the second portion is a part of the same function or is a part of another $gameTemp method, then unless you give $gameTemp a _classId property your conditional statement would always be false. the this refers to it, not the actor.

this.actor._primary == 41
7) see 2)

Checks the class and assign a number to Primary
its not checking the class of anything. $gameTemp doesnt have a _classId
then I should convert Primary to a State?
it'd be easier in the long run to have the property be a reference to the state itself, not its Id, but it would just mean a little extra work when fetching it for Game_Actor.states()

Then I do the same for Secondary and call individual triggers for each?
i dont know when youre calling this. you make it sound like this would run on class change? ignoring that the relevant bit is outside the function and would be after a return if it were in it, that would make this an extension for Game_Actor.changeClass()?

What i mentioned would just require a scriptcall to change the actor's properties if done as i said.

Then I make Primary and Secondary skip the previous checks.
youre mixing up and combining the 2 separate methods i mentioned. you dont do both, you do one or the other. the purpose of making the state-properties and pushing them into Game_Actor.states is to not have them in the _states property and not be erased by the game's standard functions.

Could I program the reserved States to skip the previous check instead?
That is what the first method is for.

I’m not very good at scripting, so I thought that assigning a Tag on the previous script that was already working would be simpler for someone like me.
which is why i suggested two methods. the first one would let you do that if you rewrote clearStates() the way i described.


now that youve given more details, i believe Visustella's class change plugin lets you do most if not all of what you want. have you looked into it?

If youre going to work on making your own plugins, id strongly suggest learning more about JS on a fundamental level first through a tutorial resource like w3schools and then learning about engine before continuing further.
Yes, I did try some Visustella plugins before, but they are a bit complex and sometimes messed up other things in the project, most likely a problem in my end, not theirs.

So I was building all the project’s mechanics and systems by trying to use as little scripts as possible, with focus in finding the simplest scripts to solve the hurdles that I couldn’t solve with events.

I tried a script from 姫HimeWorks that solved the issue, but it was for RMMV and it didn’t work with FOSSIL. So I had gone to the forums to understand better how everything works and see if I could find a solution, in the end I came up with the original script that broke the States, so the last piece of the puzzle was to add that Tag thing, which I thought would be simple to learn, but in this case I need to “Commission a Plugin” then, not “Plugin Request”, correct?

I did managed to solve the initial problem for now, I found a way to bypass the breaking of the States in the correct instances with events, so I can continue working on the Skill Type Swap System, but you are right I need to study more, I’ll check w3schools and if you have more places to recommend I’ll check it out as well.

Sorry if I caused any issues.
in this case I need to “Commission a Plugin” then, not “Plugin Request”, correct?
You never even requested a plugin. You duplicated your original post in this forum section, asking for help with your code, which was pointless 😛

As I said in your first thread on this topic, there are existing plugins to do everything you're trying to do - whether it's changing classes or maintaining states through death. But you're not asking for plugin recommendations or for help getting a plugin to work - which is way easier than writing your own code - you keep asking for help with code you clearly don't understand the basics of.

I'm glad you got something working for yourself, good luck with your project.
Ah, I made a mistake. I had read the page about “Plugin Request Rules” and clicked on the “Convince Strangers to Write Scripts for You!” inside it, so I got things mixed up.

I thought that I could “request” help for finishing a script if it was partially done and if it was a good idea to get helped, as I don’t have the know-how of how to do it.

So in this case, for “JS Plugin Requests”, I should ask for specific recommendations of plugins that I may had not find while looking in the internet, is that correct?

If I wanted help with coding something, that I don’t know how to finish, is there a forum page that I can ask for help to finish it? Or do I need to commission it?

In the case of commissions, is there a specific forum page I could find someone or I need to approach people individually?
for “JS Plugin Requests”, I should ask for specific recommendations of plugins that I may had not find while looking in the internet, is that correct?
Personally if I need help writing a plugin or script I will isolate it to a specific Javascript inplementation question and ask the Javascript thread.

You can ask someone to write a plugin for you in JS plugin requests, Sometimes if a programmer takes interest in the idea or it's a simple request they'll do it for free. Or more often someone will recommend one if one already exists.

There is a commission forum but you need 30 posts to access it.

I've merged your previous thread (first 7 posts) with this one.

All right, so what was it you wanted?
a plugin that makes States permanent, they persist after the three “this.clearStates();” checks are done, so I can use them for a dynamic Skill Types system.

I want to make this plugin only works with States marked with a specific Note Tag, but I couldn’t figure out how to make the checks.
OK so: a plugin that makes states with a given notetag not get removed by clearStates, right?

I would suggest something like this (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc States tagged <Permanent> will persist through clearStates.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/174052/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (function() {
"use strict";
  /** Tag name. @type {string} */
  const TAG_NAME = "Permanent";

  /**
   * @param {number} id State ID to check.
   * @returns {boolean} `true` iff that state is tagged as "Permanent".
   */
  const hasTag = function(id) {
    return !!$dataStates[id].meta[TAG_NAME];
  };

  // Patch - silently replace "Permanent" states after clearance.
  void (function(alias) {
    Game_BattlerBase.prototype.clearStates = function() {
      const s = this._states ? this._states.filter(hasTag) : [];  // get present tagged state IDs
      alias.apply(this, arguments);           // optimal compatibility
      this._states = this._states.concat(s);  // replace tagged states
    };
  })(Game_BattlerBase.prototype.clearStates);

//  // Patch - skip erase state for "Permanent" states.
//  void (function(alias) {
//    Game_BattlerBase.prototype.eraseState = function(id) {
//      if (!hasTag(id))
//        alias.apply(this, arguments);
//    };
//  })(Game_BattlerBase.prototype.eraseState);

})();
I've included a commented-out patch for eraseState too: remove the // on those lines if you want the tagged states to be truly permanent.

[Edit: added check for existence of _states to clearStates patch.]
Personally if I need help writing a plugin or script I will isolate it to a specific Javascript inplementation question and ask the Javascript thread.

You can ask someone to write a plugin for you in JS plugin requests, Sometimes if a programmer takes interest in the idea or it's a simple request they'll do it for free. Or more often someone will recommend one if one already exists.

Understood, I’ll look up more thoroughly the contents of the threads now, to avoid posting on the wrong places again.

There is a commission forum but you need 30 posts to access it.

I’ll work towards this goal as well.
OK so: a plugin that makes states with a given notetag not get removed by clearStates, right?

I tested the code now, in a fresh project, and found this error:

TypeError: Cannot read property 'filter' of undefined
at Game_Actor.Game_BattlerBase.clearStates (CAE_PermanentStates.js:24)
at Game_Actor.clearStates (rmmz_objects.js:4136)
at Game_Actor.Game_BattlerBase.initMembers (rmmz_objects.js:2648)
at Game_Actor.Game_Battler.initMembers (rmmz_objects.js:3312)
at Game_Actor.initMembers (rmmz_objects.js:4047)
at Game_Actor.Game_BattlerBase.initialize (rmmz_objects.js:2639)
at Game_Actor.Game_Battler.initialize (rmmz_objects.js:3308)
at Game_Actor.initialize (rmmz_objects.js:4042)
at new Game_Actor (rmmz_objects.js:4028)
at Game_Actors.actor (rmmz_objects.js:5234)
SceneManager.catchNormalError @ rmmz_managers.js:2036

Original thread: https://forums.rpgmakerweb.com/threads/help-to-finish-a-plugin-script-for-a-skill-type-swap-system.174052/