JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 120 of 171 View original ↗
  1. Dark_Ansem said:
    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.
  2. Arthran said:
    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
    Arthran said:
    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.
  3. Dark_Ansem said:
    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.
  4. Arthran said:
    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?
  5. Dark_Ansem said:
    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).
  6. Arthran said:
    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!
  7. Dark_Ansem said:
    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.
  8. Arthran said:
    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.
  9. 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>
  10. Dark_Ansem said:
    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%).
  11. ATT_Turan said:
    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.
    ATT_Turan said:
    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.
  12. Dark_Ansem said:
    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?
  13. ATT_Turan said:
    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.
    ATT_Turan said:
    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 :)

    ATT_Turan said:
    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 :?
  14. Dark_Ansem said:
    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.

    Dark_Ansem said:
    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.
  15. ATT_Turan said:
    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.
    ATT_Turan said:
    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.
    ATT_Turan said:
    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?
    ATT_Turan said:
    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.
  16. Dark_Ansem said:
    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.

    Dark_Ansem said:
    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:
  17. ATT_Turan said:
    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.
    ATT_Turan said:
    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
  18. 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
  19. dewm3734 said:
    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:
    W3Schools.com
    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

    dewm3734 said:
    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.
  20. ATT_Turan said:
    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.
    Thank you. I appreciate your reply, my issue lay with the recommendation of placing all of a plugin inside of
    Code:
    (()=>{});
    which defined the scope of all functions within and stopped me from being able to access any of the code from another plugin. I looked into other peoples implementations and decided that the best way was to do away with the aforementioned method and instead preface all object names with my name, making them unique.