MV script usage

Yesterday, I thought that a user consumed 20% of his MHP and restored 20% of his MHP for the team, but this script seems to be unusable in battle. Once used, an error will be displayed, and there will be no error in other places
var c = $gameParty._targetActorId var b = $gameActors.actor(c) var d = Math.round(-0.4 * b.mhp) var KO = true Game_Interpreter.prototype.changeHp.call(this, b, d, KO); var a = $gameActors.actor(c).mhp $gameParty.members().forEach(function(m){ m.gainHp(Math.round((a * 0.2))); });
Where are you executing this and in what context? What error is being displayed? In order to properly help you, we'll need a lot more information than this. Just saying "there is an error" doesn't do anything for anyone.
Moved to: Plugin Support

Depending on where you're putting this, note that a, b and v are already variables in the damage formula, so you shouldn't be using it there.
Moved to: Plugin Support

Depending on where you're putting this, note that a, b and v are already variables in the damage formula, so you shouldn't be using it there.
=。= I don't know why I can use it for a while, and how to modify it
Where are you executing this and in what context? What error is being displayed? In order to properly help you, we'll need a lot more information than this. Just saying "there is an error" doesn't do anything for anyone.
=。= I don't know why I can use it for a while, and how to modify it,I write the script in the public event, and then select the public event for skill effect. The skill use range is user and can be used in battle
1635493835401.png
I know the reason. I used it in battle because variable C could not read the user ID, resulting in an error. When I used that skill in the menu once, I entered the battle to use the skill. At this time, variable C has read the role ID, so I can use it
Double-post notice: @xiamumomo
What is "public event"? No idea what that means.

Is it a plugin you are creating?
Is it a note box in the database?
Is it a script in a troop event, common event, or map event?

Show us a screenshot (of the whole event / plugin) so we can see how and where you've set it up.

Is it a common event (is that what you mean by "public" event?) that you've attached to a skill or an item?
Double-post notice: @xiamumomo
What is "public event"? No idea what that means.

Is it a plugin you are creating?
Is it a note box in the database?
Is it a script in a troop event, common event, or map event?

Show us a screenshot (of the whole event / plugin) so we can see how and where you've set it up.

Is it a common event (is that what you mean by "public" event?) that you've attached to a skill or an item?
It's common events. Because my English is not good, I use translation software, resulting in some different words
1635495265240.png
Unfortunately $gameParty._targetActorId is only set when using items in the menu. 😴

Also, this kills the user if they have less than 40% max HP. I don't know if that's intentional. 😅

For battle, try this instead:
  1. Set the skill to target User, formula type Damage HP.

  2. Use a damage formula like this:

    v[1] = a.actorId(); 0.2 * a.mhp
    I.e. "store user's actor ID in variable 1; then do 20% HP damage".

  3. In your common event, try this:

    var actorId = $gameVariables.value(1); var user = $gameActors.actor(actorId); $gameParty.members().forEach(function(m) { if (m !== user) m.gainHp(Math.round(0.2 * m.mhp)); });
    I.e. "make everyone in the party except the user gain 20% HP".
In steps 2 and 3, you can change the 1 to use a different variable.

If you're still having trouble, post a screenshot of the skill page in the database. 👋
Unfortunately $gameParty._targetActorId is only set when using items in the menu
Thanks, original $gameparty_ Targetactorid is a menu that can only be used. Knowledge + 1, that knowledge is my example 😂
Yay! Is your skill working correctly now?
Yay! Is your skill working correctly now?
yes,Now I'm thinking about various skills, such as lol dog head Q
OK, I'll close this thread then. Happy RPG Making! 😂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Reopening due to further questions.

Context:
xiamumomo said:
I also want to ask a question, how to judge whether all enemies are killed by my skill. My skill range: single enemy, skill damage v[10] = b.enemyId();a.atk * 0.65 + v [2], common event is
var e = $gameVariables.value(10); var m = $gameTroop.members(e)[0]; if (m <= 0)$gameVariables.setValue(2, $gameVariables.value(2) + 100);
I want to be a lol dog head Q to kill the enemy and increase skill damage
caethyril said:
I think this does +100 to variable 2 if all enemies are dead:

var alive = $gameTroop.aliveMembers(); if (alive.length <= 0) { $gameVariables.setValue(2, $gameVariables.value(2) + 100); }
xiamumomo said:
Yes, but its skill is to designate one enemy, not all
caethyril said:
Oh, that is more difficult.

You could check in the skill formula if the damage is more than the target's HP, e.g.

var dmg = 0.2 * a.mhp; if (dmg > b.hp) v[2] = (v[2] || 0) + 100; dmg
But that doesn't check for resistances or anything. 😴
Yay! Is your skill working correctly now?
Thank you. I can always learn a lot from you. DMG was not mentioned in the (Damage Formulas 101) skill formula in the forum before
OK, I'll close this thread then. Happy RPG Making! 😂
Thread closedModerator note: Reopening due to further questions.Context:
Can you answer my question? I want to make a werewolf W skill in lol. my game is to make the character change into a werewolf after using the skill, and then obtain state A. use skill a to make the enemy obtain state B. when the enemy HP < 30%, the player will obtain state C. if the player loses state a, the enemy and the player will lose state B and C respectively

Incidentally, I use yep_ Buffs & States core, I currently realize that when the player loses state a, the player loses State C at the same time, but how can I set the enemy to lose state B
This seems to split into multiple parts:
  • Transform - this might help:

  • Add state to user - you can use .addState(id) to add a state to a battler. E.g. in many YEP script tags, you can do this:

    user.addState(123);
    I.e. "add state 123 to the skill user".

  • Add state when enemy HP < 30%... I'm not sure what the best approach is for this. If you only need to check for any enemy at low HP, maybe try YEP Auto Passive States:
    Then try a tag like this on the passive state:

    <Custom Passive Condition> condition = $gameTroop.members().some(function(enemy) { return enemy.hpRate() < 0.3; }); </Custom Passive Condition>

  • Remove state B from enemies if/when the character loses state A - I'm not sure what the best approach for this is. One option: check every enemy for state B when A gets removed, e.g.

    <Custom Remove Effect> $gameTroop.members().forEach(function(enemy) { if (enemy.isStateAffected(123)) { enemy.removeState(123); } }); </Custom Remove Effect>
Hope that helps! 👋
Hope that helps! 👋
To judge the enemy's HP < 30, I use the label < custom deselect effect > < / custom deselect effect > to cause other labels. I can't achieve that effect. Only this can be done. As for removing the enemy's state, I'm in the tag of status a
< custom leave effect > i
user. removeState(135);
$gameTemp. reserveCommonEvent(46);
< / custom leave effect > use CommonEvents scripts

Thank you for helping me

Original thread: https://forums.rpgmakerweb.com/threads/mv-script-usage.141629/