Can I add variable via Item?

Hello, everyone. I am using RPGMV.

I was wondering if I could change a specific variable while using an Item.

For example, In my game, there is an affection system. Certain actions of the player can rise the affection of certain party members.

For example, I have a part member A and a party member B.

I set one variable for each member, Affection A, and Affection B.
I also named the luck stat 'Affection' so players can check whenever they want for affection status.

Whenever an event occurs to A, it will raise both variable Affection A and the luck stat named "Affection" by the same amount.

However, I also want to create an Item that raises affection. I made it increase luck stat "affection" by 5, but how do I make it increase variables?

Moreover, I want to make it so if the player uses the item on A, it increases variable Affectin A, if use it on B, then it increases variable affection B. So the Stats showed in the menu match the Affection Variable set for each character.

Thank you for your time, Have a nice day!
On the right hand of the item screen of the database is an Effects list: you can specify a common event as one of those effects.

However, items can't by default be used on a party member if they don't change anything, so what you'll want to do is create a useless state in your database and apply that state; then, run the common event to increase the affection of the character last targeted by an item; then, remove the state again.
On the right hand of the item screen of the database is an Effects list: you can specify a common event as one of those effects.

However, items can't by default be used on a party member if they don't change anything, so what you'll want to do is create a useless state in your database and apply that state; then, run the common event to increase the affection of the character last targeted by an item; then, remove the state again.
Thank you for your information, can you tell me how can I set "character last targeted by an item plz?"
The script call $gameParty._targetActorId will contain the ID of the actor you selected as the target of the item.

I don't know how you have your affection system constructed, but you can use that variable in conditional branches and such.
1. Make a common event run in the item's effect tab.
2. Use this script:
Here

In theory it will work, just @ me if it didn't I'll look into it if I have the time on pc.
Moved to: MV Support
1. Make a common event run in the item's effect tab.
2. Use this script:
Code:
Script:
var targetId = $gameParty._targetActorId + x;
$gameVariables.setValue(targetID, $gameActors.actor(targetId).param[7]);
$gameVariables.setValue(targetID, += 1);
$gameActors.actor(targetID).addParam(7, 1));

//*x is the increments so that it matches your variable ID, if Actor 1 affection is stored in var 21, then x is 21. The affection variable must be consistent.
//*1 on the 2nd last and last line is your affection points that gets added when you use the item
//*On the last line, the script set your luck (paramId 7) then set it the same as saved variable.

In theory it will work, just @ me if it didn't I'll look into it if I have the time on pc.
Thanks for the help. I'm a newbie to RPGMV and this script really fascinated me with all the potential interactions RPGmaker can achieve.
I have tried the code but by looking at the script it seems that there is only one variable being adjusted.
I've set each character's affection to a different variable since I want them to be remembered and interacted differently. So this may not be my solution.
However, your script encouraged me to have a look at all the options RPGmaker provides, and I found that I can just simply make a common event that sets the variable equal to luck status. This way I can just let the item add luck to the character. And make the variables just equal to each character's luck.

Thanks for the help again, and hope you have a good day
@Bestboy, I have been editing the code (it's clunkier then because i wrote it after I woke up) but it should do what you wanted now.

The process of the script is like this.
Code:
1. targetID is your party member ID.
2. targetVar is your variable id to save the affection value. The + 10 is if the actor 1's affection variable is saved on var 11.
2. The item will modify party members based on targetID by 1.
3. Then it saved on a variable based on targetID + X.

Code:
Script:
var targetID = $gameParty._targetActorId;
var targetVar = targetID + 10;
$gameActors.actor(targetID).addParam(7, 1));
$gameVariables.setValue(targetVar, $gameActors.actor(targetID).param[7]);
Thank you!
Thank you!
I've tweaked the script again.
Posting on mobile is a challenge lol.

Original thread: https://forums.rpgmakerweb.com/threads/can-i-add-variable-via-item.138779/