JavaScript questions that don't deserve their own thread

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
I looked at the VisuStella Skills and States instructions and your notetag is wrong. It's JS On Add State, not On Apply.
Thank you. and of course JS On Erase State is what should be in place of JS on remove?

EDIT: after making this change, for some reason, it's the user of the skill that dies on the first use - progress, but I wonder what happened
 
Last edited:

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
951
Reaction score
1,262
First Language
English
Primarily Uses
RMMZ
EDIT: after making this change, for some reason, it's the user of the skill that dies on the first use - progress, but I wonder what happened
That's because you typed user in all of your code. You need to be doing all that stuff to the target object instead.

However, there's one other big issue in your code. You've got it coded so that the effect is stackable, yet once the state wears off, it will only restore the atk that was drained by the last stack applied. So if a target gets the state applied to them multiple times before it wears off, they will permanently lose some atk.

I haven't tested it, but assuming that you do want the effect to be stackable, something like this should be close to what you're going for:
Code:
<JS On Add State>
  const drainAmount = Math.randomInt(8) + 1;
  target._drainedAttack ??= 0;
  target._drainedAttack += drainAmount;
  target.addParam(2, -drainAmount);
  if (target.atk <= 0) {
      target.die();
  }
</JS On Add State>

<JS On Erase State>
  if (target._drainedAttack) {
      target.addParam(2, target._drainedAttack);
      delete target._drainedAttack;
  }
</JS On Erase State>

*edit* Oops, I had accidentally left in one reference to user in the "On Erase State" note tag. It is now fixed.
 
Last edited:

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
That's because you typed user
oh goodness me, then again, I am an amateur, thank you for pointing that out! if any of you is looking for a self-destruct skill feel free to use my original version LOL
However, there's one big issue in your code. You've got it coded so that the effect is stackable, yet once the state wears off, it will only restore the atk that was drained in the last application of the state. So if a target gets the state applied to them multiple times before it wears off, they will permanently lose some atk.
this is a significantly more serious issue. as in, this would permanently reduce stats, end of? not even a recovery possible? (I'm an amateur, again)

I tested your fix, and it seems to have done the trick! the stats stay diminished in the menu screen! and using "full recovery" fixes them up.
 
Last edited:

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
951
Reaction score
1,262
First Language
English
Primarily Uses
RMMZ
this is a significantly more serious issue. as in, this would permanently reduce stats, end of? not even a recovery possible? (I'm an amateur, again)
Yep, it'd be permanent for the remainder of the game, because each time the state was added to the target, it would be overwriting the previous value of target._drainedAttack, meaning that only the attack drained by the latest stack is being kept track of. So then when the state was finally removed, it would only add back the atk from that latest stack, and the rest of the atk that had been drained would remain lost in the nether.

Now we've got it set to keep a sum of all the atk that gets drained, so that we can add that full sum back in once the state is removed.
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
Yep, it'd be permanent for the remainder of the game, because each time the state was added to the target, it would be overwriting the previous value of target._drainedAttack, meaning that only the attack drained by the latest stack is being kept track of. So then when the state was finally removed, it would only add back the atk from that latest stack, and the rest of the atk that had been drained would remain lost in the nether.

Now we've got it set to keep a sum of all the atk that gets drained, so that we can add that full sum back in once the state is removed.
Thank you again very much :) is there a way to make the reduced attribute be highlighted in red on the status menu with the notetag?
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
951
Reaction score
1,262
First Language
English
Primarily Uses
RMMZ
Thank you again very much :) is there a way to make the reduced attribute be highlighted in red on the status menu with the notetag?
Not solely with the note tag, no. That's probably the type of thing that deserves its own thread, since it would require a standalone plugin, and the answer would depend on which other plugins you're already using (i.e. if you're using VisuStella Elements and Status Core, that would completely change how you've gotta go about it).
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
Not solely with the note tag, no. That's probably the type of thing that deserves its own thread, since it would require a standalone plugin, and the answer would depend on which other plugins you're already using (i.e. if you're using VisuStella Elements and Status Core, that would completely change how you've gotta go about it).
Thanks, I really appreciate your help and fixing the mistake I made!
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
951
Reaction score
1,262
First Language
English
Primarily Uses
RMMZ
Thanks, I really appreciate your help and fixing the mistake I made!
No problem. The color thing isn't exactly hard to do. It's just possibly going to require more back and forth than what this thread was really designed for, so it's probably best to put it into its own thread. If too many different conversations get going at the same time in the same thread, things can get confusing pretty fast.

That, and I think the question is of a nature that other people might also be able to benefit from the answer, so it's probably good to put it in its own thread, so that it will come up in searches easier and such.
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
No problem. The color thing isn't exactly hard to do. It's just possibly going to require more back and forth than what this thread was really designed for, so it's probably best to put it into its own thread. If too many different conversations get going at the same time in the same thread, things can get confusing pretty fast.

That, and I think the question is of a nature that other people might also be able to benefit from the answer, so it's probably good to put it in its own thread, so that it will come up in searches easier and such.
Maybe I will do it then - thankfully, the state icon still appears in the status screen, so it would just be for extra signposting.
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
I was trying to work for a solution which allows multiple types of magic to work. There is however one issue. Magic Resistance trait simply zeroes all damage notwithstanding where it comes from. After tinkering a bit, I came up with 2 options.

1: assign a custom hidden element to each (arcane, divine, psionic etc) and then set immunity to that, if using a multiplier damage formula.

2: this script here, which I'd love you to check.

JavaScript:
<JS Pre-Apply as Target>
// Replace 3 with the ID of the skill type you want to be immune to
if (this.isSkill() && this.item().stypeId === 3) {
  target.result().success = false;
  target.result().critical = false;
  target.result().hpAffected = false;
  target.result().mpAffected = false;
  target.result().tpAffected = false;
}
</JS Pre-Apply as Target>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,875
Reaction score
6,677
First Language
English
Primarily Uses
RMMV
1: assign a custom hidden element to each (arcane, divine, psionic etc) and then set immunity to that, if using a multiplier damage formula.
I don't see why you would do anything with notetagas for this, this is what the built-in elements system is for. I'm not sure what "a multiplier damage formula" has to do with it, but every actor, class, enemy, etc. in the game can be given a Trait with Element Rate to make them more or less susceptible to a specific element (including immune, if you set the rate to 0%).
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
I'm not sure what "a multiplier damage formula" has to do with it, but every actor, class, enemy, etc. in the game can be given a Trait with Element Rate to make them more or less susceptible to a specific element (including immune, if you set the rate to 0%).
The reason being that say, in the VS Status Core plugin, you can pick between these 4 lovely approaches:

Multi-Element Ruling:
Ruling on how to calculate element rate when there are multiple
elements used for damage calculation.
- Maximum (largest rate of all elements)
- Minimum (smallest rate of all elements)
- Multiplicative (product of all elements used)
- Additive (sum of all elements used)
- Average (of all the elements used)
Now for the first part of your observation.
I don't see why you would do anything with notetagas for this, this is what the built-in elements system is for.
This is a once again D&D inspired feature. In D&D, you have a number of main types of ability: magic, supernatural, extraordinary, psionic. Only the first type is subject to spell resistance.

This sort of variety is what I'm trying to emulate. Using different elements as attributes is a workaround which presumes I'll never use two databases traits, physical and magical resistance.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,875
Reaction score
6,677
First Language
English
Primarily Uses
RMMV
This sort of variety is what I'm trying to emulate. Using different elements as attributes is a workaround which presumes I'll never use two databases traits, physical and magical resistance.
I can't find those traits at all. Are you talking about the Physical Damage and Magical Damage Sp-Parameters?

If no, please tell me where to find it because I'm missing something.

If yes, that's already an entirely different thing than spell resistance in D&D, so you wouldn't be comparing those two things at all.

Spell resistance in D&D also works differently than how you had it in your original notetag, because there's a caster level check involved :wink:

So, aside from that, what is the actual problem with the notetag you posted?
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
I can't find those traits at all. Are you talking about the Physical Damage and Magical Damage Sp-Parameters?

If no, please tell me where to find it because I'm missing something.
Yes I am. Was on the train, couldn't check exact terminology.
Spell resistance in D&D also works differently than how you had it in your original notetag, because there's a caster level check involved :wink:
yes, but caster levels don't exist in RPG maker and AD&D in video games (Baldur's gate 2, for example) works more or less with a % system, so I took that as an inspiration :)

So, aside from that, what is the actual problem with the notetag you posted?
It doesn't seem to work, so I must have made a mistake in the syntax :?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,875
Reaction score
6,677
First Language
English
Primarily Uses
RMMV
yes, but caster levels don't exist in RPG maker
Well, sure they do - your level in the class is exactly the same as in D&D your level in the class. But if you prefer to do it this way, that's of course your choice.

I was just questioning it because the notetag you wrote also isn't going off of any kind of percentage anything. It's just nullifying it completely, no caster level check and no percentage reduction, the two things you have talked about.

It doesn't seem to work, so I must have made a mistake in the syntax :?
I don't see anything glaring. The trick is, you're trying to tell the game "Hey this didn't hit and doesn't do anything" after it already hit. I don't know if that can work, that's why I wouldn't try to implement it this way at all.

I would either do what you said you were inspired by and reduce damage by a percentage, or if you want to make it all or nothing like D&D 3+ spell resistance, do it with a custom hit formula.
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
Well, sure they do - your level in the class is exactly the same as in D&D your level in the class. But if you prefer to do it this way, that's of course your choice.
I mean, not if you multiclass, but that's beside the point.
I was just questioning it because the notetag you wrote also isn't going off of any kind of percentage anything. It's just nullifying it completely, no caster level check and no percentage reduction, the two things you have talked about.
I'm not sophisticated enough to go with a percentage :kaoswt: I thought that I'd start with an all or nothing.
I don't see anything glaring. The trick is, you're trying to tell the game "Hey this didn't hit and doesn't do anything" after it already hit. I don't know if that can work, that's why I wouldn't try to implement it this way at all.
oh? I thought it was pre-apply?
I would either do what you said you were inspired by and reduce damage by a percentage, or if you want to make it all or nothing like D&D 3+ spell resistance, do it with a custom hit formula.
I'm not sure how to do either, so help is appreciated.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,875
Reaction score
6,677
First Language
English
Primarily Uses
RMMV
I mean, not if you multiclass, but that's beside the point.
The Class Change System allows you to track levels per class, just like D&D does.

oh? I thought it was pre-apply?
The description of Pre-Apply says "Runs JavaScript code at the start of an action hit" (emphasis mine).

There is no notetag with the timing that allows you to affect whether it's a hit or not.

Applying a percentage change to damage is easy, you just use the condition you wrote above and change the damage value.
Code:
<JS Pre-Damage as Target>
// Replace 3 with the ID of the skill type you want to be resistant to
if (this.isSkill() && this.item().stypeId == 3) 
    value*=.8; // Modify math as desired
</JS Pre-Damage as Target>

And boom, that enemy takes only 80% damage from whatever skill type 3 is.

If you need more help, I'd suggest making a thread - I feel five exchanges on a question rather meets the criteria "deserves its own" :wink:
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
541
Reaction score
133
First Language
English
Primarily Uses
RMMZ
Applying a percentage change to damage is easy, you just use the condition you wrote above and change the damage value.
wow this is way simpler than what I did. Thank you.
If you need more help, I'd suggest making a thread - I feel five exchanges on a question rather meets the criteria "deserves its own" :wink:
I'll make a thread, mark this as exchange 6 only for the purpose of thanking you
 

dewm3734

Warper
Member
Joined
Aug 11, 2014
Messages
3
Reaction score
1
First Language
English
Primarily Uses
Hello again
What is the correct syntax for variables if you want to be able to access them across plugins. For example, if I write a custom menu plugin and a custom item menu plugin, how can I access the custom item menu from inside the custom menu plugin? At the moment nothing happens
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,875
Reaction score
6,677
First Language
English
Primarily Uses
RMMV
What is the correct syntax for variables if you want to be able to access them across plugins.
There are a variety of ways to do this, and it's difficult to recommend something specific without seeing your code.

You may find it useful to read up on how coding scope works:

Some typical ways to do this would include:
- Making a global variable
- Making it a member variable of another object (see how the default windows are contained within scenes)
- Passing the variable as an argument when you call functions

For example, if I write a custom menu plugin and a custom item menu plugin, how can I access the custom item menu from inside the custom menu plugin?
That sounds a little hinky - customarily a custom menu would be a scene created by calling functions, not just a variable.

You might want to re-read how some of the menus work in the default engine, then if you still have questions post a thread about it with examples of your code.
 

Latest Threads

Latest Posts

Latest Profile Posts

imgur sure is getting weird, one day I lose gradually all my images, the other I get them back randomly and then again they disappear again.
Despite OPT2 praise it still has some strange stories in it. Lady Mikka is trying to work herself to death because of guilt. Guilt over what? ¯\_(ツ)_/¯ So instead of finding a NPC to have a heart to heart with her they decide the cure is a new kimono. So when she drops dead she'll at least be well dressed. I haven't even got to the strange part yet.
Did so much work on the game today. I wish I could post it all in this status update but there is a character limit of course haha. I thought about making a topic for updates, though... maybe.
The most recent sign that I am old. I have done martial arts for over 4 decades. Never HAD to stretch out. Good, of course, but never required. Was doing some kicks in the kitchen because, why not, and I felt a pop in the back of my thigh. Now I am limping around. Gotta love getting old.
One of the biggest perks of being fluent in English is how many new and interesting recipes I am able to find and try out that I would have hardly come across if I just spoke my mothertounge :3

Forum statistics

Threads
131,684
Messages
1,222,241
Members
173,437
Latest member
Manic_Umbra
Top