# How to make an item have a different effect for each actor?

#### Mylkie

##### Villager
I want an item to restore MP for 3 actors, but have the same item restore TP for the fourth actor (because this actor does not use MP).

#### ATT_Turan

##### Forewarner of the Black Wind
Set the item's Scope to All Allies. In the damage formula box, do:
Code:
``\$gameActors.actor(id1).gainMp(X); \$gameActors.actor(id2).gainMp(X2); \$gameActors.actor(id3).gainMp(X3); \$gameActors.actor(id4).gainTp(Y); 0``
Where it says id1-4 you put the appropriate actor ID. Where it says X-X3 you put how much you want that actor to gain for MP. Where it says Y you put how much TP you want the fourth actor to gain.

Ooh. I don't know if setting it to all allies will make that formula execute for each actor. If it does, let me know and I'll give you a longer, corrected version. If you need that, you can let me know whether the MP actors are getting different amounts of MP back or the same amount.

#### Mylkie

##### Villager
Set the item's Scope to All Allies. In the damage formula box, do:
Code:
``\$gameActors.actor(id1).gainMp(X); \$gameActors.actor(id2).gainMp(X2); \$gameActors.actor(id3).gainMp(X3); \$gameActors.actor(id4).gainTp(Y); 0``
Where it says id1-4 you put the appropriate actor ID. Where it says X-X3 you put how much you want that actor to gain for MP. Where it says Y you put how much TP you want the fourth actor to gain.

Ooh. I don't know if setting it to all allies will make that formula execute for each actor. If it does, let me know and I'll give you a longer, corrected version. If you need that, you can let me know whether the MP actors are getting different amounts of MP back or the same amount.
Hello! I tested this with 1 ally and all allies and it gives the certain amount of MP and TP that I wanted! But the item restores MP for all the 3 actors, including TP for that fourth actor. I want it so that it only restores it to one targeted actor only! I would really like the longer version though!

#### ATT_Turan

##### Forewarner of the Black Wind
I want it so that it only restores it to one targeted actor only! I would really like the longer version though!
Ah. That's not how I interpreted your first post, it creates a few extra steps. You also didn't answer my question about the MP gain.

#### Mylkie

##### Villager
Ah. That's not how I interpreted your first post, it creates a few extra steps. You also didn't answer my question about the MP gain.
I did answer o.o
I said that it gave me the same amount of MP for the 3 actors
Sorry if I made you confused, my english is bad sometimes >_<

#### ATT_Turan

##### Forewarner of the Black Wind
I said that it gave me the same amount of MP for the 3 actors
You did not - you just said that the item gave MP to the 3 actors, indicating that the code worked correctly. But it's no problem, I just wanted to ask before I wrote out code that was more complicated than it needed to be.

So here's what you need to do.

1) Create a new state in your database. It doesn't need an icon or anything filled in on the page. It doesn't matter what you call it, I will call it Restore.

2) On the right-hand side of the item screen, where it says Effects, add 2 effects - one that gives the Restore state, and then the second takes Restore back off.

(This is necessary for the TP actor. If you have the item's damage formula set to restore MP or restore HP and his MP/HP is full, you can't target him with the item since it wouldn't change any stats. Putting a state on the item means you can still target any actor.)

3) Put this in the damage formula:
Code:
``(a._actorId==id1 || a._actorId==id2 || a._actorId==id3 ? a.gainMp(X) : a._actorId==id4 ? a.gainTp(Y) : 0); 0``

Follow the same instructions before for id1-4, X and Y. This will work even if you have more than those 4 actors in your game, it just will have no effect if it's used on someone else.

#### Mylkie

##### Villager
You did not - you just said that the item gave MP to the 3 actors, indicating that the code worked correctly. But it's no problem, I just wanted to ask before I wrote out code that was more complicated than it needed to be.

So here's what you need to do.

1) Create a new state in your database. It doesn't need an icon or anything filled in on the page. It doesn't matter what you call it, I will call it Restore.

2) On the right-hand side of the item screen, where it says Effects, add 2 effects - one that gives the Restore state, and then the second takes Restore back off.

(This is necessary for the TP actor. If you have the item's damage formula set to restore MP or restore HP and his MP/HP is full, you can't target him with the item since it wouldn't change any stats. Putting a state on the item means you can still target any actor.)

3) Put this in the damage formula:
Code:
``(a._actorId==id1 || a._actorId==id2 || a._actorId==id3 ? a.gainMp(X) : a._actorId==id4 ? a.gainTp(Y) : 0); 0``

Follow the same instructions before for id1-4, X and Y. This will work even if you have more than those 4 actors in your game, it just will have no effect if it's used on someone else.
I followed your instructions, and I only get actor ID 1 to restore MP. If I select the other actors to use the item it only restores MP to actor ID 1. What did I do wrong?

#### ATT_Turan

##### Forewarner of the Black Wind
What did I do wrong?
I have no idea, your screenshot doesn't show your full damage formula.

Are you using this outside of battle?

#### Mylkie

##### Villager
I have no idea, your screenshot doesn't show your full damage formula.

Are you using this outside of battle?
Yes, I want the item to be used outside of battle too

#### ATT_Turan

##### Forewarner of the Black Wind
I don't know. If you copied the code I gave you, it should work regardless. My only suggestion is to actually copy and paste what you have in the damage formula, instead of a screenshot of just a small part.

#### Mylkie

##### Villager
I don't know. If you copied the code I gave you, it should work regardless. My only suggestion is to actually copy and paste what you have in the damage formula, instead of a screenshot of just a small part.
Oh! It works during battle! But it still doesn't work outside of battle...
Thank you for being patient with me and helping me this far >u<;;

#### Andar

##### Veteran
instead of using the damage formula you can use a common event. That will work everywhere but has the disadvantage of delaying the effect to the end of turn in battle (unless you have battleplugins that allow you to specify when a common event is executed).

have one effect "target" state - that state does nothing, it is only to identify the target that used the item.
then have the common event as the second effect.
in the common event, you'll need one branch for each actor checking if that actor has the state.
if yes, apply the effect for that actor to it and remove the state from the actor

#### ATT_Turan

##### Forewarner of the Black Wind
Code:
``var member=\$gameParty.inBattle() ? a : \$gameActors.actor(\$gameParty._targetActorId); (member._actorId==id1 || member._actorId==id2 || member._actorId==id3 ? member.gainMp(X) : member._actorId==id4 ? member.gainTp(Y) : 0); 0``

That should work in and out of battle.

#### Mylkie

##### Villager
instead of using the damage formula you can use a common event. That will work everywhere but has the disadvantage of delaying the effect to the end of turn in battle (unless you have battleplugins that allow you to specify when a common event is executed).

have one effect "target" state - that state does nothing, it is only to identify the target that used the item.
then have the common event as the second effect.
in the common event, you'll need one branch for each actor checking if that actor has the state.
if yes, apply the effect for that actor to it and remove the state from the actor
Code:
``var member=\$gameParty.inBattle() ? a : \$gameActors.actor(\$gameParty._targetActorId); (member._actorId==id1 || member._actorId==id2 || member._actorId==id3 ? member.gainMp(X) : member._actorId==id4 ? member.gainTp(Y) : 0); 0``

That should work in and out of battle.
Both of these worked!! Thank you so much

### Latest Profile Posts

Making games is the only thing I'm good at. Real talk.
So, uh... where's the RPG Maker MZ update with the MV animation system? Is there a release date confirmed?
Also I'm kind of brave enough to admit this. I... I have a crush on Sephiroth.
Please don't call me anything offensive. I'm naturally crazy.
thanks to a lot of lunatic coding... my game finally has a stun mechanic that I feel really good about. damage enemy's mental psyche (mp), and once empty, hitting with certain attacks trigger combos that can stack the damage.
Waiting for the 1.40 update before testing out my copy of MZ so that I don't end up adding unnecessary work to my plate. Meanwhile the current fourth draft for my story is taking shape, and I'm fleshing out the lore as I realize how things would make better sense here and there for the world that I'm building.
Just found out about your complications. I'm so sorry that you're going through this. I wish I could do something substantial for you, but our distance from each other makes that an impossibility. Still, if you ever need to talk or vent, I'm here.