Help with writing custom Notetags for YEP plugins

I'm using the YEP Core plugins, and I'm curious how I would go about using javascript to call for specific party members and targets. For instance I would like to have a skill that consumes 75% of the HP of all party members EXCEPT the user of the skill and converts the HP 'paid' into damage split among enemy targets.


I have messed around with javascript in the past and know how to do very basic functions, but I am in the dark as to how I would call specific party members, targets, etc.

Also, I'm unsure of if this should be in the learning javascript section as I'm attempting to learn specific javascript functions and utilize them with someone else's plugin, or if I should post this in the script support section.
Hi!


As a tip, press f8 to see the console in game then type window in it.


It will show every object in your game, and from there you can see all their properties. If you already know a bit of javascript, by exploring a bit you'll quickly find anything you want. Taking a look at the mv files is also a great help. There's a thread with split files for each object that is much more readable if you look around a bit.


As for your specific question: party members are stored in the $gameParty.members() array.


Battle members, you guessed it, in the $gameParty.battleMembers() array.


Enemies are stored in the $gameTroop.members() array.


Using this information a loop and a variable to store the hp consumed you should be able to do what you want.


If you aren't able to do it with the information I provided or just want a solution, I posted below an example of how to do what you want.

Spoiler
var hpUsed = 0; //recording total hp consumed
var percent = 0;
for (var i = 0; i < $gameParty.battleMembers().length; i++) { //for every battle member
if ($gameParty.battleMembers() !== user) { //if the battle member is not the user
percent = Math.floor(75 * $gameParty.battleMembers().hp / 100) //get 75% of the party member current hp
hpUsed += percent //add it to the hp used
$gameParty.members().gainHp(-percent) //removing hp from the actor
}
}

var individualDmg = Math.floor(hpUsed/$gameTroop.members().length) //to get individual damage, divide total hp used by the number of enemies.
//record this into a game variable to re-use it later when dealing dmg to each enemy
$gameVariables.setValue(yourVariableId,individualDmg)


This is assuming that "user" will return the user of the spell in yanfly's notetags. I believe it does.

Wow thank you very much for the reply. The F8 window is a godsend, and thank you for the resources to look up. I did look at the code you wrote and it gave me a very good idea of how to not only accomplish this one skill, but really gave me a head start with writing out any of the skills that were a little more complex.


Thanks again, I really appreciate it!
In the YEP_CoreEngine is a Parameter called Show Console, if you set it to true the console (F8 window) will show up automatically. 
In the YEP_CoreEngine is a Parameter called Show Console, if you set it to true the console (F8 window) will show up automatically. 

OMG I feel so dumb. How did I miss this >_<. Thanks for that!
Ok so I've run into another problem. My skill isn't working for various reasons. If I try to make it only accessible after a certain number of turns, it simply doesn't show up, ever. If I try to make it available from the start, my game crashes with the following result;
 

Spoiler
The main screen displays "TypeError undefined is not a function" while my debugger shows:


TypeError: undefined is not a function
    at Game_Actor.eval (eval at <anonymous> (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_SkillCore.js:717:13), <anonymous>:5:27)
    at Game_Actor.Game_BattlerBase.skillHpCost (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_SkillCore.js:717:3)
    at Game_Actor.Game_BattlerBase.canPaySkillHpCost (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_SkillCore.js:755:21)
    at Game_Actor.Game_BattlerBase.canPaySkillCost (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_SkillCore.js:750:15)
    at Game_Actor.Game_BattlerBase.canPaySkillCost (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_X_PartyLimitGauge.js:764:56)
    at Game_Actor.Game_BattlerBase.canPaySkillCost (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_X_SkillCostItems.js:574:56)
    at Game_Actor.Game_BattlerBase.meetsSkillConditions (file:///C:/Users/DARKazen/Documents/Games/Project1/js/rpg_objects.js:2778:48)
    at Game_Actor.Game_BattlerBase.meetsSkillConditions (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_SkillCore.js:661:44)
    at Game_Actor.Game_BattlerBase.meetsSkillConditions (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_X_LimitedSkillUses.js:570:61)
    at Game_Actor.Game_BattlerBase.meetsSkillConditions (file:///C:/Users/DARKazen/Documents/Games/Project1/js/plugins/YEP_X_SkillCooldowns.js:914:61)



The code I'm attempting to use through notetags is as follows;

Spoiler
<Hide in Battle>
<Hide in Field>
<Limit Uses: 1>
<After Battle Uses Recover: 1>
<Custom Show Eval>
if ($gameTroop.turnCount() = 3) {
    visible = true;
    } else {
    visible = false;
    )
</Custom Show Eval>


<Custom HP Cost>
var percent = 0;
for (var i = 0; i < $gameParty.battleMembers().length; i++) {
    if ($gameParty.battleMembers() !== user) {
        percent = Math.floor(75 * $gameParty.battleMembers().hp / 100)
        $gameParty.members().gainHP(-percent)
        $gameVariables.setValue(100, percent)
        }
    }
</Custom HP Cost>


<Pre-Damage Eval>
var percent = $gameVariables(100);
var individualDmg = Math.floor(percent/$gameTroop.members().length);
value = individualDmg;
</Pre-Damage Eval>

 


I've also tried to remove the first several lines of code up til <Custom HP Cost> in order to just have the skill normally available, which is what then causes the crash.


 


Any ideas?
Hi! Please use the code tag (next to the quote tag) when pasting code. I thought I had seen writing errors with your arrays, but then I saw Italics so that means you did manipulate arrays properly.


There is a lot if problems with your code, and your yanfly plugin use. Please read the help file of the plugins you use with care.


You should consider re reading some basic things about javascript such as comparators and assignment operators too before delving too deep into coding.


First for the show:

  • You tell the game to look at game troop, but what if the party is not in battle? Do you want the skill to normally show in the menu or not?.

You can use $gameParty.inBattle() for that.

  •  Using an = sign doesn't mean check for equality, = means set whatever is on the left to whatever is on the right example a = 3; To check for equality you have to use === so if (a === 3) {do something} or >= if you want any value greater than.

I used this website to learn javascript if it can help you: http://www.w3schools.com/js/js_operators.asp


Then for the hp Cost:

  • You have no cost variable. Yanfly skill core requires that you put a cost varaible as the product of your calculations.
  • You also probably don't want to reduce the actors hp when showing the skill in the menu, so the gain Hp command doesn't belong in there.
  • Then the issue of actually using this notetag is that it will make the actor have to pay that cost. I don't really know how to get around this.



Then the pre Dmg eval itself:


It will trigger each time damage is dealt, so for each enemy. You're probably better off using action sequences for this skill. I'd do it this way: in action setup calculate cost and remove hp from everyone then set a variable to individual dmg. In the predmg itself set value to the variable.


Edit: I got it to work with a common event and 2 variables. Still the problem of the casting actor needing to pay the HP cost remains. If you remove the custom hp cost, the skill works flawlessly.

Spoiler
<setup action>
eval: $gameVariables.setValue(1,user) //set variable 1 to the spell caster
common event: 5 //call your common event
</setup action>

<Custom Show Eval>
if ($gameParty.inBattle()) {
if ($gameTroop.turnCount() >= 3) {
visible = true;
} else {
visible = false;
}
} else {
visible = true
}
</Custom Show Eval>

<Custom HP Cost>
var percent = 0;
cost = 0;
for (var i = 0; i < $gameParty.battleMembers().length; i++) {
if ($gameParty.battleMembers() !== user) {
percent = Math.floor(75 * $gameParty.battleMembers().hp / 100)
cost += percent
}
}
</Custom HP Cost>

<Pre-Damage Eval>
value = $gameVariables.value(2) //set the value to the variable defined in the common event
</Pre-Damage Eval>


The common event itself is:

Code:
var percent = 0;
var cost = 0;
for (var i = 0; i < $gameParty.battleMembers().length; i++) {
  if ($gameParty.battleMembers()[i] !== $gameVariables.value(1)) { //variable 1 contains the user
    percent = Math.floor(75 * $gameParty.battleMembers()[i].hp / 100)
   $gameParty.battleMembers()[i].gainHp(-percent) //remove the hp from other party members on spell cast
    cost += percent
  }
}
var individualDmg = Math.floor(cost/$gameTroop.members().length);
value = individualDmg;
$gameVariables.setValue(2, individualDmg) //variable 2 will ocntain the final damage to apply
Ok, so a few things to note.


I read the plugin help extensively, like every 3 seconds I was checking back to it while working on the code in notepad++. I guess I should have just opened the plugins and actually read the code inside the plugin itself?


The Skillcore plugin and it's extensions allow me to use the tags <Hide in Battle> and <Hide in Field> which I had used, because I want the skill to only show up for use when the condition was met (which I guess in itself was posing a problem and I didn't think to add being in battle as another condition which seems stupid of me in retrospect.) I also have in my editor >= 3 as opposed to =3 (which I had originally wrote as == 3 which was still wrong, not sure where I got that it was double and not triple = for an equal statement.)

You have no cost variable.

.............................*sigh*


After a good night's sleep and looking at what I pasted and what you said, all I can say is WOW. So the end of that code should read something like "cost += percent", yet, that will only deduct the cost from the user if I'm not mistaken.


I just read your code which confirms my idea that I should have used "cost += percent", and as for figuring out the whole taking hp from other actors, I'm thinking that maybe I should use a custom state. Perhaps have the skill itself inflict a custom state on all the actors (and just have the user actor be immune to the state) which reduces their hp by 75% at turn end and restores their state to normal, and then have the common event that runs when the skill is activated total the math formula and use it as damage. That's really the only thing I can think of.


Sorry my code is rather appalling, I've only ever really worked with Java, and haven't even touched it in a couple of years. I will definitely check out that website you linked to brush up on everything and use it as a reference should I get stuck working on something else.
No worries 🙂  


I just felt like pointing out the mistakes one by one would help you figure out a solution.


As for the >= instead of the = that's also why it's better to use the code tag, or else the forum eats up characters, like for smileys.


As for not noticing variables, that's normal, I mess up script calls for plugins I wrote myself all the time 😉 . Then I look back at my own plugin file and think that I'm an idiot.


I just wanted to make sure you actually do read the help files (some people don't...).


I'm not very familiar with yanfly plugins too.


I didn't know about the hide in battle tag for example, so I just ignored it. I actually downloaded skill core just to try and see what was wrong with your code.


If I understand properly, the cost variable is used to both display and make the actor actually pay for his skill.


There may another way to modify the skill cost display other than using that notetag, but I don't know it if it exists.


For clarification: == means check for equality of value and === checks for equality of type and value.


I find it better to use ===, to ensure I don't get silly results like "2" == 2, but that's just my opinion.


I look at the help file for other plugins by opening them in notepad ++ myself because I find it easier to read the plugins in there.


Looking at the plugin itself is a plus if you can understand it, but is not required most of the time.
So as of right now I've got the draining HP of all actors except the caster by using a state that ends after the action with just a -75% HP regen. This isn't ideal but it's a step and if in the end I can make it work, than that's fine by me. I believe that this calculates based on MaxHP though, which is fine as I'll just add a state resist to knockout which should leave the party members at 1 HP if it would have killed them otherwise.


What I'm going to try and do now is use the common event to store the math result of 75% of everyone's HP as a variable and then activate a second skill which will actually do the damage. The only downside I see with this is that it's going to calculate an extra characters HP into the damage.


Alternatively I could attempt to use your common event, figure out how to apply the state to all party members (sans the user who will be state resistant to said state) and that should solve all of my problems as well, right?


Also, yeah, pointing out the mistakes was really helpful as well as that website you linked. The other thing is learning how to call all of the functions and objects in MV itself. Really simple things like a party members max hp I just don't know how to call them. I wish there was some sort of post that already had everything listed out so I could just skim through it and grab the ones I need for what I'm doing.... but  hey, learning is part of the fun right?


EDIT: I got it working! Well, 99% working. The only problem right now is that the state is only applied after the damage, so in the event you win the battle with the skill it will not drain the hp of the party members, BUT, it is correctly only draining the hp of the other party members instead of the casters as well.


Something interesting to note though, is that in the editors test battle the skill properly doesn't display until turn 4, however in an actual test run of the game itself it will display from turn 1 but isn't usable until turn 4. A minor annoyance at the moment, but overall this is a huge victory for me. Thanks for all of your help and patience! Now to move on to some rather easy skills before tackling my next big challenge which will be a move that allows you to become immune to damage and unable to act for two turns but regens your hp based on the damage your dots do during those two turns. Fun fun.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-writing-custom-notetags-for-yep-plugins.70747/