Eventing a way for the party to heal a state with choices?

Morpheus

Jack-of-Trades
Veteran
Joined
Mar 14, 2012
Messages
231
Reaction score
85
First Language
english
Primarily Uses
N/A
Hello, here is what I am trying to accomplish:
  • Let's say there are 4 states the party can have.
  • They can use an item to heal one of those states at a time.
  • If they don't have the state, then the choice to heal that state doesn't show up.
  • (The item calls Common Event X which would check if the states are applied)
The problem I'm running into is I can't for the life of me figure out if this can be accomplished with only eventing. I tried Himes Hidden Choice Conditions but can't quite get that to work, so I'm trying to event it now.

Please and thank you if you know how to solve this.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
For hiding choices under certain conditions, you could also try ALOE_ConditionalChoices, which in my personal opinion is easier to use than Hime's version. In that case you'd just set the choice to something like this for example:

Code:
Poison <<$gameParty.members().some(who => who.isStateAffected(4))>>
That will show the choice only if someone in the party is poisoned. Replace 4 with whatever state ID you need to check, and write the choice text before the <<.

If you don't want to use a plugin, I think the only option would be to check for every possible combination of the states and showing a different set of choices in each case. It won't be pretty.
 

QuietPenguin

Veteran
Veteran
Joined
May 24, 2020
Messages
30
Reaction score
12
First Language
English
Primarily Uses
RMMV
For hiding choices under certain conditions, you could also try ALOE_ConditionalChoices, which in my personal opinion is easier to use than Hime's version. In that case you'd just set the choice to something like this for example:

Code:
Poison <<$gameParty.members().some(who => who.isStateAffected(4))>>
That will show the choice only if someone in the party is poisoned. Replace 4 with whatever state ID you need to check, and write the choice text before the <<.

If you don't want to use a plugin, I think the only option would be to check for every possible combination of the states and showing a different set of choices in each case. It won't be pretty.
Second this. ALOE_Conditional Choices is a must-use plugin IMHO.
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
I'm working on your problem, to solve it I'm using lots of scripting (but it's in the events and common events so it's not plugin). However I suggest you to make an Item that remove all the four states and costs more, it's really a simple solution and works really well ahah
edit:
I found a possible solution, is really boring but I learned something doing it, so thank you.
1) make an item that will be used on an actor to remove one of the 4 states you wanted. In my example these states will be: Poisoned (stateId=4), Blind (id=5), Mute (id=6) and Angry (id=7) with id I mean that I can call them as objects with the script:
$dataStates[id]; and if I want their name with: $dataStates[id].name; (we'll see this better later on).
In my case this Item is called NOOBCODER Potion and it's my 24th item in Database. Screenshot below:
Cattura.JPG
As you can see an important part of this item is that he can be used on an ally, inflicting it the state Target, this is because I want to mark my target actor for the following scripts and events that will occur.
the second effect, very important, is the calling for the common event "heal a state". As its name says this event will remove the state you select from you targeted party member.

2) Make a common event called as you wish, in my example it is heal a state, screenshots below (don't worry if you can't read everything, I'll post a copy of the text in each Script field you see in the images:
1.JPG
2.JPG
3.JPG
and there are the scripts:
script 1:
for (var i = 0; i<$gameParty.members().length; i++) {

if ($gameParty.members().isStateAffected(19)){

$gameVariables.setValue(29, i);

$gameParty.members().removeState(19);

};

};
script 2:
var target = $gameVariables.value(29);

var status = [];

for (i = 4; i < 8; i++ ) {

if ($gameParty.members()[target].isStateAffected(i)) {

var name=$dataStates.name;

status.push(name);

};

};

$gameVariables.setValue(26,status);
script 3:
choices = $gameVariables.value(26); params = [];

$gameMessage.setChoices(choices, 0)

params.push();

var length = choices.length;

$gameMessage.setChoiceCallback(function(responseIndex) {

$gameVariables.setValue(32,responseIndex);

});
script 4:
var target = $gameVariables.value(29); var choices = $gameVariables.value(26); var response = $gameVariables.value(32);

switch (choices[response]) {

case "Poisoned":

$gameVariables.setValue(31,4);

break;

case "Blind":

$gameVariables.setValue(31,5);

break;

case "Mute":

$gameVariables.setValue(31,6);

break; case "Angry": $gameVariables.setValue(31,7); break;};

$gameParty.members()[target].removeState($gameVariables.value(31));

BEWARE: I saw that script 4 has the first line broken in var response=.... $game....
MAKE SURE THAT when you copy the scripts there are no broken lines, this is up to you.

The global variables used in my scripts are for example and can be changed as you wish.

3) to test if this whole thing works you can create a tutor event that gives to one of your party members some of these states and a bunch of this Potion item, you'll see that when you use it on a party member it will have the icon of "target" state (if you delete the icon from the database you won't see it at all and all is perfectly polished) and rapidly you'll have to choose from a list of the states you have (i didn't coded the case in wich there are no states on the selected party member... it could be done but I think it's a waste of time just doing all this stuff). after you choose the state from the list my script make you'll see two text that reports the number of choice index (for testing purpose, you can delete that "add message" command from the common event) and the index of state to remove (in my case, 4,5,6 or 7) then the whole thing is done because if you return to your menù the actor won't have the chosen state anymore. Screenshots of the test field below:
10.JPG11.JPG12.JPG13.JPG14.JPG15.JPG16.JPG

That's all... I liked to event some crazy stuff like this item, but I higly recommend to create a simple item that removes one of these states.

PS: I didn't understand well if you wanted the item to remove the state from one person or from the entire party, if you want it to remove from entire party I recommend to create a simple Show choices from the User Interface of RPGMMV and event everything from the UI (user interface).
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,960
First Language
English
Primarily Uses
RMMV
NoobCoder, your solution is neat! I took the liberty of streamlining the code you used:


code.png
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
Trihan, I can't express all my appreciation for your work, I have a whole bunch of things to learn from your elegant solution. Thank you!
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
Wait... variables declared in one script call can be referenced in another? Are such variables actually global, then?
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
I haven't tested the Trihan solution yet, but I think that all the scripts and commands he wrote on that event page are seen by the system like 1 Module or something similiar (sorry... I'm a NoobCoder so my specific language is really poor) and so if you define the array "choices" in the first script it is possible to recall it in the second like a local variable (I did not do that in my solution because I tought it was impossible).

Its only a theory and I would appreciate to be corrected if necessary, but maybe the same event page is read like a whole piece of code (module???)

I'll try it out soon to see it working, I also have a doubt about the function(index) in the second script. This Index variable is not defined... but maybe it is a standard property of an array (item, index) and so Try can use it with no worries in defining it.

Correct me and I'll be happy xD
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,960
First Language
English
Primarily Uses
RMMV
If you use "var" the variables will only be declared within the scope of the script command and will no longer exist afterwards. If you just name them without var, they're created in the window scope and will be retained to be used afterwards.
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
Perfect explanation, thanks :)
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
That explanation seems to be accurate. I just tried this trivial event:

Code:
◆Script:var test = 3;
◆Script:console.log(test)
Selecting those two lines in the event editor and pressing Ctrl+R yields "ReferenceError: test is not defined". Removing the "var" makes it run without errors, and then I can press F8 / F12 and type in "test" and it tells me the value is 3.

I think perhaps it is better to create variables in the scope of the interpreter, rather than globally. That would just mean adding "this." in front of any variables used in both of the script commands, like this:

JavaScript:
// First script command (don't include this line)
var healStates = [4, 5, 6, 7];
this.choiceStates = [];
this.choices = [];
healStates.forEach(state => {
  this.target = $gameParty.menuActor();
  if(this.target.isStateAffected(state)) {
    var name = $dataStates[state].name;
    this.choices.push(name);
    this.choiceStates.push(state);
  }
});
// Second script command (don't include this line)
var states = this.choiceStates, target = this.target;
$gameMessage.setChoices(this.choices, 0);
$gameMessage.setChoiceCallback(index => target.removeState(choiceStates[index]));
// Optional - clean up variables.
delete this.target;
delete this.choices;
delete this.choiceStates;
Notes:
  • Using menuActor() instead of _menuActorId just makes it fall back to the lead actor if for some reason _menuActorId is not the ID of an actor in the party.
  • Using => instead of function means that I can refer to this in the nested function. You can still make it work with function but you need to add .bind(this) after the closeing brace of the function. In other words:
    JavaScript:
    healStates.forEach(function(state) {
      // ...
    }.bind(this));
  • Importing target and choiceStates to be local was only needed because I then clear them with delete. If you don't care about cleaning up the variables when you're done with them, you can instead use the following for the second script command:
    Code:
    $gameMessage.setChoices(this.choices, 0);
    $gameMessage.setChoiceCallback(index => this.target.removeState(this.choiceStates[index]));
  • With this method, the script condition becomes this.choices.length > 0.
  • Even if you don't clean up the variables when you're done with them, they would be cleared if the map's game interpreter is rebuilt. I'm not sure if that happens when you change maps or only when the game starts or is loaded.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,960
First Language
English
Primarily Uses
RMMV
That's a good point SolarFlare. I actually do usually use "this" but this was a quick-and-dirty optimisation so I forgot. Thanks!
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
Tons of new infos (thank you veterans!)
I tried your script and I have to inform that the Trihan's script works fine but heals only the first actor in party (In my solution I used a "target" state to get the target partymember, so it can be solved easily adding that piece of code and it works great!)
Solar_flare script does not work for some reason I don't know very well:
JavaScript:
// First script command (don't include this line)
var healStates = [4, 5, 6, 7];
this.choiceStates = [];
this.choices = [];
healStates.forEach(state => {
this.target = $gameParty.menuActor();
if(this.target.isStateAffected(state)) {
var name = $dataStates[state].name;
this.choices.push(name);
this.choiceStates.push(state);
}
});
// Second script command (don't include this line)
var states = this.choiceStates, target = this.target;
$gameMessage.setChoices(this.choices, 0);
$gameMessage.setChoiceCallback(index => target.removeState(choiceStates[index]));
// Optional - clean up variables.
delete this.target;
delete this.choices;
delete this.choiceStates;
I also modified the script to avoid all the error messages it gave me in a game test and went up with this:
JavaScript:
// comment - first Script block
var healStates = [4, 5, 6, 7];
this.choiceStates = [];
this.choices = [];
healStates.forEach(state => {
  this.target = $gameParty.menuActor();
  if (this.target.isStateAffected(state)) {
    var name = $dataStates[state].name;
    this.choices.push(name);
    this.choiceStates.push(state);
  };
});

// comment - second Script block
var states = this.choiceStates, target = this.target, stateName = this.choices;
$gameMessage.setChoices(this.choices, 0);
$gameMessage.setChoiceCallback(index => target.removeState(stateName[index]));
delete this.target;
delete this.choices;
delete this.choiceStates;
and a screenshot of the common event page called by the item:
Cattura.JPG

But this one, that gets no error in test phase, doesn't heal the state of any of the partymembers...
I'm not really sure I understood all the code the veteran used (i did by best but I'm Noob eheh) but I think the problem is in the targeting system of this script. I'm working on it but if someone gets it working could he please post the solution?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
Your change to make it use stateName instead of states looks wrong. I see that in my original code I accidentally wrote choiceStates instead of states, so I guess that confused you, but it should be target.removeState(states[index]).
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
I tried that too and the error is gone as you said, but the actor who get healed is alwais the first party member, but it can be adjusted with the use of a "target" status like Trihan's.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
I dunno what to say to that, because as far as I can tell, the correction I just gave you should be correct. Maybe I'm missing something. What's the exact error message with that correction? Or actually... try this code, then press F8 and show the full contents of the console.

JavaScript:
var states = this.choiceStates, target = this.target, stateName = this.choices;
console.log('before', states);
$gameMessage.setChoices(this.choices, 0);
$gameMessage.setChoiceCallback(index => {console.log('after choice', states); target.removeState(states[index])});
delete this.target;
delete this.choices;
delete this.choiceStates;
console.log('after delete', states);
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,960
First Language
English
Primarily Uses
RMMV
Sorry NoobCoder, menuActor() was the wrong way to go. Change that line to
Code:
this.target = $gameActors.actor($gameParty._targetActorId);
So the whole thing is:

Script 1:
Code:
var healStates = [4, 5, 6, 7];
this.choiceStates = [];
this.choices = [];
healStates.forEach(state => {
  this.target = $gameParty.targetActor();
  if(this.target.isStateAffected(state)) {
    var name = $dataStates[state].name;
    this.choices.push(name);
    this.choiceStates.push(state);
  }
});
Script 2:
Code:
var states = this.choiceStates, target = this.target;
$gameMessage.setChoices(this.choices, 0);
$gameMessage.setChoiceCallback(index => target.removeState(states[index]));

// Optional - clean up variables.
delete this.target;
delete this.choices;
delete this.choiceStates;
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
That would be the same as:
JavaScript:
this.target = $gameParty.targetActor();
Except the latter guarantees you get an actor who's actually in the party.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,960
First Language
English
Primarily Uses
RMMV
That would be the same as:
JavaScript:
this.target = $gameParty.targetActor();
Except the latter guarantees you get an actor who's actually in the party.
Good call, I didn't see that function. I'll edit.
 

NoobCoder

Villager
Member
Joined
Jun 27, 2020
Messages
12
Reaction score
2
First Language
Italian
Primarily Uses
RMMV
var healStates = [4, 5, 6, 7];
this.choiceStates = [];
this.choices = [];
healStates.forEach(state => {
this.target = $gameParty.targetActor();
if(this.target.isStateAffected(state)) {
var name = $dataStates[state].name;
this.choices.push(name);
this.choiceStates.push(state);
}
});
Script 2:
Code:
var states = this.choiceStates, target = this.target;
$gameMessage.setChoices(this.choices, 0);
$gameMessage.setChoiceCallback(index => target.removeState(states[index]));

// Optional - clean up variables.
delete this.target;
delete this.choices;
delete this.choiceStates;
It works like a charm (I tried to make it doing mistakes also with adding more than 4 ator in the party and it can heal also the 6th actor in party if it is stateaffected by a state between 4 and 7), screenshot of the item to create and the common event it has to call below:

1) make this item, very important thing, price has to be 27 ( :) just a joke)
item.JPG

2) make this common event:

common event.JPG

If you want this item to affect more state (like some sort of hi-tech panacea XD) you can change status indexes in the first line of the first script, it works really well for me.
 

Attachments

Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,585
Latest member
Reversinator
Top