MZ Using Common Events to control Switches

Hello all!

I am struggling to understand how to set up (what I assume needs to be ) a common event that triggers a switch = ON when a skill is learned as well when a skill is used outside of battle

Ex 1:
If
Actor A learns Skill B
Turn Switch C ON

Ex 2:
If
Actor X Uses Skill Y
Turn Switch Z ON


Use case:

I am attempting to activate node visibility in Felski's Skill Tree Plugin via switches as well as some situation switches.


Associated skill plugins being used:
Fomar's Equipment Skill
Class Change System Visustella MZ
CGMZ Skill Shop
First, I suggest you try to use the correct terminology whereever possible - it actually helps making things more understandable and others can help you better.

in this case, switches are never triggered, they are always controlled. that is an important difference because a trigger is something else.

second, the only way a common event can run independently or affect anything else if it is a parallel process.
theoretically you can have a parallel process do those checks, but that usually causes lag if you add the wrong number of waits (the correct number reduces lag but needs to be found by experimenting).

that said it would be much better if the switch is not controlled by a parallel process common event but by the action to be tested itself.

if an event teaches a skill, that event can also control the switch.
if a skill is used, that skill can also control the switch (either by damage formula coding or by attaching a simple, non-triggered common event.

what is not checked that way is skills learned by leveling - for that you realy need the parallel (skill has been learned yes or no) or a plugin to implement other ways.
So basically, the best thing to do would be to request (from Felski or in plugin requests) help with adding what is probably a single line of code to the plugin.

I would suggest adding a notetag to the skill that gives the ID of a switch, and the function in the plugin that teaches the skill can check that notetag to turn that switch on.
If I remember correctly Felski's plugin supports execution of javascript on skill learning anyway. Just use the following in the eval (where x is the id of the switch):
JavaScript:
$gameSwitches.setValue(x, true);
If I remembered wrongly I also wrote a small plugin to execute arbitrary javascript on skill learning. So if you don't figure out how to do that with Felski's plugin, I can share that.

For your second example I would personally handle that with a custom execution notetag from Yanfly's Skill Core. I am sure MZ has a VisuStella equivalent for that.
So basically, the best thing to do would be to request (from Felski or in plugin requests) help with adding what is probably a single line of code to the plugin.
Have done so to Felski via Youtube, and also on the original post for the plugin. I have what seems to be the unfortunate luck of finding awesome plugins made by folks who haven't been on the forums on a while though haha.

Due to the complexity of my skill system Im running into a lot of roadblocks with integration. Thankfully folks like you have been instrumental and overcoming them. Though since this is the Plugin Support forum I assumed it would be the appropriate place to ask since I'm not trying (unless truly need be) to create a whole new plug in


what is not checked that way is skills learned by leveling - for that you realy need the parallel (skill has been learned yes or no) or a plugin to implement other ways.
I wish it were as simple as a skill learned by leveling xD. Actors learn some skills via Skill shop, and others using Fomars Equipment skill plugin. So the code/notetagging would have to be reflective of that.

Also if the joined date wasn't a giveaway, I am fairly new and still learning a lot of the proper terminology so please bear with me

If I remember correctly Felski's plugin supports execution of javascript on skill learning anyway. Just use the following in the eval (where x is the id of the switch):
The execution JS is when activating or deactivating the node via the tree. The goal here is to use a switch or notetag outside of the skilltree to activate the Node in the Skill tree. which seems to be the opposite of what you're suggesting
Wait. So you're not asking to do this when you learn a skill from the Skill Tree? You want it to happen when it's from some Skill Shop?

Well what the heck is that? How does it work? Is it another plugin?
The execution JS is when activating or deactivating the node via the tree. The goal here is to use a switch or notetag outside of the skilltree to activate the Node in the Skill tree. which seems to be the opposite of what you're suggesting
Ah ok, so you have an actor learn skills by other means and want that to do something in the skill tree. I thought you wanted to do something when one skill was learned with the skill tree with some other skill also in the tree.

You could try my the plugin I wrote for my personal project. That is for MV, but I think it will probably also work in MZ.
Wait. So you're not asking to do this when you learn a skill from the Skill Tree? You want it to happen when it's from some Skill Shop?

Well what the heck is that? How does it work? Is it another plugin?
Remember when I said elsewhere my wife says I made this too complicated xD.

Skills are Handled 3 ways at the moment:

  • Fomar's Equipment Skill:
    1. Trait based AP Learning System
    2. Weapon X enables Skill Y to be used. Once Skill Y fills its associated AP meter it is permanently learned by the actor
  • Felski's Skill Tree +/ VS Class System:
    1. Allows for visual skill tree to teach skills
    2. Class system allows for Actors to change classes in menu
    3. Together Skill trees can be associated directly with classes for actors to build up a custom skill set from multiple classes
  • CGMZ Skill Shop
    1. Simple plug in that allows a scene to be called to buy skills, shop style
    2. Able to set up notetags for skills that create prerequisites before a skill can be purchased via the called shop


      So the goal ultimately is to have learning a Skill Turn a Switch ON, this enabling the Node on the Skill Tree
You could try my the plugin I wrote for my personal project. That is for MV, but I think it will probably also work in MZ.
I will play around with this thankyou!
If you still need help, please include links to both the equipment skill and skill shop plugins.

depending on how those are programmed it might be possible to create a patch-plugin that adds direct data association between them. That will only work if they are simple enough themselves, but would have each plugin directly change the data of the other plugins to work together.
Added details in
Ah ok, so you have an actor learn skills by other means and want that to do something in the skill tree. I thought you wanted to do something when one skill was learned with the skill tree with some other skill also in the tree.
So I've seemingly got it set up correctly:


<EOM_OnLearnEval: if(a.actorId(1) $gameSwitches.setValue(21, true);>

But I get the following syntax error once the prerequisite skill has been Learned:

SyntaxError: Unexpected identifier
at Game_Actor.learnSkill (EOM_LearnEval.js:50)
at Game_Actor.<computed>.learnSkill (VisuMZ_1_SkillsStatesCore.js:2723)
at Game_Actor.gainSkillAP (Fomar0153_EquipmentSkills.js:114)
at Game_Action.eval (eval at VisuMZ.<computed>.<computed> (VisuMZ_1_BattleCore.js:17825), <anonymous>:37:10)
at Game_Action.<computed> [as applyBattleCoreJS] (VisuMZ_1_BattleCore.js:17825)
at Game_Action.<computed>.<computed> [as executeDamage] (VisuMZ_1_BattleCore.js:17825)
at Game_Action.apply (rmmz_objects.js:1923)
at Game_Action.<computed>.<computed> [as apply] (VisuMZ_1_BattleCore.js:17825)
at Function.BattleManager.invokeNormalAction (rmmz_managers.js:2784)
at Function.BattleManager.invokeAction (rmmz_managers.js:2776)



Im far from an expert, but it seems that since VS and Fomar are using this, its getting confused?
syntax error
Syntax error basically means a typo for the computer.
in such cases screenshots of the errors are better to prevent another typo when retyping here, but I think I already have it:

your line is missing an )
you have three open ( but only two closing )
your line is missing an )
you have three open ( but only two closing )

As a long time Advanced Excel instructor I cannot begin to explain how pissed that mistake made me at myself xD. (then again its past 12am here lol)

Success!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

This thread is solved! (for now!)
<EOM_OnLearnEval: if(a.actorId(1) $gameSwitches.setValue(21, true);>
As an additional note (aside from the missing ')') your condition also seems to be wrong. At least it would be in MV. As I don't own MZ I can't confirm how things work there.
But the idea is that a.actorId() returns the id of the actor learning the skill which you then can compare to a number to find out which specific actor is currently learning the skill. For example:
JavaScript:
a.actorId() == 1
Passing a parameter to a function that has takes none seems to just have no additional effect in javascript. As a consequence, as long as the learning actor has any ID (and every actor should have one) your condition will be true. So no matter which actor learns the skill, the switch will be turned on.
As a consequence, as long as the learning actor has any ID (and every actor should have one) your condition will be true. So no matter which actor learns the skill, the switch will be turned on.
Noted. I'll strip the ID and test again to be sure. It would of course be ideal to not have to add a EvalLearn to account for every potential party member. Good catch
If you want to have a switch for every actor that can learn the skill, there is a way easier way. You can simply use the following:
Code:
<EOM_OnLearnEval: $gameSwitches.setValue(20 + a.actorId(), true);>
This will turn on switch 21 for actor 1, switch 22 for actor 2, etc. Way less code than checking for each ID individually and assigning a specific switch for that.

Edit:
Also when you do want to use multiple statements for a single skill, make sure to put them all into one single notetag. As my plugin doesn't do its own notetag parsing, but rather relies on the built in meta object multiple notetags for my plugin will overwrite each other. You can use newlines in the notetag though to keep things neatly looking.
Code:
<EOM_OnLearnEval: $gameSwitches.setValue(20 + a.actorId(), true);>
I'll give this a go today. Im trying to have multiple actors use the same skill trees. If I can do that without duplicating witches thatd be swell.


Also when you do want to use multiple statements for a single skill, make sure to put them all into one single notetag. As my plugin doesn't do its own notetag parsing
Should I be doing this in respect to plugin order. Say for example I have your eval highest, should that then be followed by for example any VisuStella statements, or should it need to be in reverse?
Should I be doing this in respect to plugin order. Say for example I have your eval highest, should that then be followed by for example any VisuStella statements, or should it need to be in reverse?
No, the order of my notetag and notetags from other plugins will not matter. What I wanted to say was simply this:
Code:
//do this for several statements in the same notebox
<EOM_OnLearnEval:
someStatement();
otherStatement();
>

//do not do this for several statements in the same notebox
//the first one will be overwritten by the second one
<EOM_OnLearnEval: someStatement();>
<EOM_OnLearnEval: otherStatement();>

I'll give this a go today. Im trying to have multiple actors use the same skill trees. If I can do that without duplicating witches thatd be swell.
I am not quite sure what you are getting at. In your very first post your example was this:
If
Actor A learns Skill B
Turn Switch C ON
That is why I suggested the condition in the first place. If you simply want to turn on the same switch, no matter which actor learns the skill then that is even easier. Simply don't put a condition there and instead use:
Code:
<EOM_OnLearnEval: $gameSwitches.setValue(21, true);>
This will turn on switch 21 every time any actor learns the skill. Of course turning on a switch that already is on will not do anything. So unless you reset it somewhere the switch will just stay on after the first actor has learned the skill.
Duplicating switches wasn't the right phrasing. Essentially the setup:

Actor X: Can Use Skill Tree 1
Actor Y: Can ALSO use Skill Tree 1(ST1)

If X Learns Skill A, that enables visibility of the corresponding Node on ST1

My assumption is that will result in that node being activated for every single actor that can use ST1. Which isn't ideal and would mean having to use 4 versions of your note tag that are actor specific and point to different switches (for however many skills I set as prereqs).

That's why this read to me as a potential solve:

If you want to have a switch for every actor that can learn the skill, there is a way easier way. You can simply use the following
<EOM_OnLearnEval: $gameSwitches.setValue(20 + a.actorId(), true);>



I've been trying to re-get Felskis attention on this because I reckon there's a way to have a the nodes activated more directly and be actor specific that I'm just not seeing. In the meantime workarounds have been the thing haha



Sidenote: the ranking bar here is pretty low if I'm already considered a Vet xD

Original thread: https://forums.rpgmakerweb.com/threads/using-common-events-to-control-switches.150942/