Looking for a script to replace the condition below.
condition= user.friendsUnit().aliveMembers().length > 1
I tried
condition= user.friendsUnit().areStateAffected(2).length > 1 but it says undefined is not a function
Script to check if a certain number of allies have a state
● ARCHIVED · READ-ONLY
-
-
it doesn't work that way.
"alive members" does not check for a state, it is an array that actors are sorted into when they get the state.
You'll need to do something similiar to that sorting.
you need a function that checks all actors if a specific actor has the state, and a variable that is counted up if it does.
Then at the end you can check the variable for its number. -
Exactly, there are a bunch of ways to do it, but the first ones that come to mind are a for loop, filter function, or reduce function.
With a 'for loop', you can loop through the array of alive members, and increment a variable if they have the state. Then, return that variable to check in the condition.
In a filter function, you can filter the array of alive members to those that have the state, and check the length of the resulting array.
For the reduce function, you increment an accumulator as the array is read and return the amount. -
Would something like this work?
var members = target.friendsUnit().aliveMembers();
var affected = [];
for (var i = 0; i < members.length; ++i) {
var member = members;
if (member && member.isStateAffected(206)) {
affected.push(member);
}
Where would I put it to change the state condition? -
Pretty close, but it can be even simpler than that. Instead of pushing the member into a new array, you can just increment a counter. Also don't forget that you have to actually access the member using the iterator variable "i" as you are looping through the array of members.
Code:var members = target.friendsUnit().aliveMembers(); var count = 0; for (var i = 0; i < members.length; ++i) { var member = members[i]; if (member && member.isStateAffected(206)) { count = count + 1; } }
In your head, try to go through it line by line (as if you were a computer), and it should help you to understand it.
It also helps to translate it into conversational English:
1. Let's grab all of the living members of our friend's unit and put it into a variable
2. Let's create a variable to count. It will start at zero.
3. Now we check all of the members. If any of the members has state 206, then we'll increase the count.
4. After we checked all the members, the count variable has the final count. We can do more stuff with that. -
Thanks for your help. So the new passive condition would be: condition= count>0 ? Would I put this code in a new plugin or In a note tag?
-
I don't know, I was just answering your question "Script to check if a certain number of allies have a state".
I don't know if you're writing your own plugin, if you're using someone else's plugin, if this is an event command, if this is a notetag... If you're using a plugin, you didn't mention it or provide a link to it, so I really can't say.
But if you understand the code, then you'll understand that at the end, the variable "count" will have a value of how many members have the state. You can do whatever you want with that value afterwards. -
I,m using yanfly's buff and state core and battle engine core. Trying to change the passive condition of this state. I found a temporary solution but it costs me 5 battle troops pages.
State used<Custom Passive Condition>
// The passive effect will only be true if there's more than 1 member on the field
condition = user.friendsUnit().aliveMembers().length > 1;
</Custom Passive Condition>
<Custom React Effect>
// Check if this dealt HP damage
if (this.isHpEffect() && value > 0) {
// Get the current group of alive allies
var allies = target.friendsUnit().aliveMembers();
// Calculate the amount of damage dealt spread across the allies
var dmg = Math.ceil(value / Math.max(1, allies.length - 1));
// Check if the number of allies is greater than 0
if (allies.length - 1 > 0) {
// If it is, reduce the direct damage to 0
value = 0;
}
// Loop through each of the allies
for (var i = 0; i < allies.length; ++i) {
// Get the currently looped ally
var ally = allies;
// Check if the ally exists and isn't the target
if (ally && ally !== target) {
// Make the ally take damage
ally.gainHp(-dmg);
// Show the damage popup
ally.startDamagePopup();
// If the ally is dead
if (ally.isDead()) {
// Then make the ally collapse
ally.performCollapse();
}
// Clear the ally's results
ally.clearResult();
}
}
}
</Custom React Effect> -
I looked up the Yanfly Buffs and States Core and didn't see any documentation for "Custom Passive Condition", so I can't help you there.
-
No problem! The documentation for custom passive is in the autopassive state but I decided to change the effect until I find a solution.
-
OK so in the documentation for Auto Passive States, it says:
So for your query, "Script to check if a certain number of allies have a state", the code I gave above will end up with a variable called 'count', where 'count' contains the amount of allies that have a state.This enables you to input conditions to be met in order for the passive state to appear. If the ‘condition’ variable returns true, the passive state will appear. If the ‘condition’ returns false, it won’t appear.
All you have to do is add a line to the end of the notetag that says:
Code:Where X is the amount of allies that must have the state, in order for the condition to be true.condition = count >= X;
Say that X is 2, and 1 member has the state.
condition = 1 >= 2; // FALSE because 1 is not >= 2
^^in this case the condition will be false
Say that X is 2, and 3 members have the state
condition = 3 >= 2; // TRUE because 3 is >= 2
^^in this case the condition will be true
Overall:
Code:<Custom Passive Condition> var members = target.friendsUnit().aliveMembers(); var count = 0; for (var i = 0; i < members.length; ++i) { var member = members[i]; if (member && member.isStateAffected(206)) { count = count + 1; } } condition = count >= X; </Custom Passive Condition> -
:DI tried it before I see the solution and came back to thank you. It works perfectly. Thanks for the help and teaching me something new!