MZ Script to change variable when user has skill *SOLVED*

Hello!

I've spent a lot of time trying to figure out how to execute this within the formula of an attack skill:

" (If user of skill has specific skill, set specific variable to specific number) (*insert attack formula*) "

I have checked this script list and have gone through forum posts like this one, and the best I've been able to come up with is:

if ($gameActors.actor($gameParty._targetActorId).skills().contains($dataSkills[43,44]) then $gameVariables.setValue(13, 1); 5 - b.def * 2

I understand the syntax is completely wrong with this, but I'm java illiterate (I pay for it every day I work on this lol).
Any help with this would be greatly appreciated. I initially had a web of common events meant to solve this issue, but after testing it for a while, a couple holes cropped up that cannot be fixed by non-script means. Its unfortunate.

Thank you all.
JavaScript:
[43, 44].every(id => a.hasSkill(id)) ? (v[13] = 1, 5 - b.def * 2) : otherAttackFormula
Replace otherAttackFormula with your own formula.

Example:
JavaScript:
[43, 44].every(id => a.hasSkill(id)) ? (v[13] = 1, a.atk * 5 - b.def * 2) : a.atk - b.def

Also, your current attack formula doesn't factor in any attack value from the user so '5 minus double the defense of the enemy' might be too much, making it return 0 or something below that instead.

Changes as needed to fit what you want.
JavaScript:
[43, 44].every(id => a.hasSkill(id)) ? (v[13] = 1, 5 - b.def * 2) : otherAttackFormula
Replace otherAttackFormula with your own formula.

Example:
JavaScript:
[43, 44].every(id => a.hasSkill(id)) ? (v[13] = 1, a.atk * 5 - b.def * 2) : a.atk - b.def

Also, your current attack formula doesn't factor in any attack value from the user so '5 minus double the defense of the enemy' might be too much, making it return 0 or something below that instead.

Changes as needed to fit what you want.

ah Thank you!

I should've clarified in the original post; The variable I'm trying to change isn't related to damage. I'm using the variable to identify the skill used for a common event.

Would the formula work if I used it like this?:

[43, 44].every(id => a.hasSkill(id)) ? (v[13] = 1) : a.atk - b.def

Also, would I have to change 'id' with the specific id of an actor or would it work with any actor that uses the skill?

Sorry if that question is obvious, I don't really know what I'm doing with scripting.

Thank you, I appreciate your time with this!
The 'a' here refers to the user. In order to use a different actor, you will have to write it out with $gameActor.actor(2) or whatever number for the specific actor. The 'b' refers to the target.

The 'id' here is the parameter that refers to the ids you used for the skill (43 and 44).

'v[#]' is the shorthand allowed inside the damage formula to refer to the data inside the game variable; in this case, we are referring to variable 13.

It can actually be this based on what you are saying:
JavaScript:
if ([43, 44].every(id => a.hasSkill(id))) v[13] = 1; a.atk - b.def
The 'a' here refers to the user. In order to use a different actor, you will have to write it out with $gameActor.actor(2) or whatever number for the specific actor. The 'b' refers to the target.

The 'id' here is the parameter that refers to the ids you used for the skill (43 and 44).

'v[#]' is the shorthand allowed inside the damage formula to refer to the data inside the game variable; in this case, we are referring to variable 13.

It can actually be this based on what you are saying:
JavaScript:
if ([43, 44].every(id => a.hasSkill(id))) v[13] = 1; a.atk - b.def

I see, thank you for the clarification.

I plugged the new script into the attack and It nearly works how I need it! This is what I got now:

if ([43, 44].every(id => a.hasSkill(44))) v[20] = 1; a.atk - b.def

I changed the variable ID to a new one just to test. I have the attack running a common event which displays the variable set in the formula. With this formula, it will fully work if the actor has skill #44. However, I need it to where it works if the user has 44 or 43.

I tried modifying it to this:

if ([43, 44].every(id => a.hasSkill(43,44))) v[20] = 1; a.atk - b.def

But doing this ends up requiring both skills I believe. Is there a way to have the variable trigger whether they have 43 or 44? Also, did I place the variable number in the correct spot? that may be the problem.

Thank you!
Is there a way to have the variable trigger whether they have 43 or 44?
use Array.some() instead of Array.every()
use Array.some() instead of Array.every()


if ([43, 44].some(id => a.hasSkill(id))) v[20] = 1; a.atk - b.def

Thank you! this worked

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.

Original thread: https://forums.rpgmakerweb.com/threads/script-to-change-variable-when-user-has-skill-solved.177988/