MZ looking for a few js codes in srd hud maker and visustella plugins

ive wrote and copy pasted so much code the past week but those are the 4 l cannot find an answer to. any help is greatly appreciated and also a classified request should be on the way if you are looking for payment.


1. random state removal or add on a list of state when condition is true on a skill
Example: I use a skill that can remove buff A or B or C or D if target is below 50% hp

state categories doesn't work unless l can have the script call because its a notetag.

the only thing l found this here but it doesn't work on MZ:


<JS Post-Apply>
// List all the states the item can remove (change to your state IDs)
// If there a lots of them in consecutive order, you can also use a loop to add them more conveniently.
var removeStates = [1, 2, 3, 4];
// Make an empty pool of states
var currentStates = [];
// Loop through each of the padawan states
for (var i = 0; i < removeStates.length; ++i) {
// Get the currently looped state
var current = removeStates;
// Check if the target is affected by that state
if (target.isStateAffected(current)) {
// If it is, add it to the pool of states
currentStates.push(current);
}
}
// Run the following code 3 times (or five times, or however many times you want - just change the number)
// For the tier 1 items, when it should run only once, you can remove the loop (this line and the very last curly bracket).
for (var j = 0; j < 3; j++) {
// Check if the pool of states isn't empty
if (currentStates.length > 0) {
// Get a random state from that pool
var removedState = currentStates[Math.floor(Math.random() * currentStates.length)];
// Remove the random state
target.removeState(removedState);
// Remove the state from the list of current states
currentStates.splice(currentStates.indexOf(removedState), 1);
}
}

</JS Post-Apply>



2. putting a condition in a function that targets the whole party doesn't work
in this example l put if (member.hp = member.mhp) { meaning for the state 11 to be added the targeted member must be full hp. theres probably just something wrong with how l wrote it but lve tried around 100 different ways.

$gameParty.aliveMembers().forEach(function(member) {
if (member.hp = member.mhp) {
member.addState(11); })};
}

3. l need a code similar as 2 but will detect which of all the alive actors who has a state or who has the highest hp
the reason why l need it is to show the exact damage the enemy skill will do depending on the stats of the actor with the condition as true so instead of
value = Math.floor((($gameTroop.members()[0].atk * 1) * dmg) * $gameParty.members()[0].pha) it can be
value = Math.floor((($gameTroop.members()[0].atk * 1) * dmg) * member.pha)

4. SRD hud maker crash when party member is not there
if you do anything that calls the second or third party member and those are not in the party the game will crash
l tried to do this condition but the crash still persist, anything related to those actors shouldnt be loaded when theyre not in the game.
if ($gameParty.members().length > 1) {
return true; }
1645002850391.png
3 days
  1. Remove a random listed state from the target

    <JS Post-Apply> // Get list of IDs for possible states to remove const stateIds = [1, 2, 3, 4].filter( // ignore states not on the target id => target.isStateAffected(id) ); // repeat up to 3 times for (let n = 1; n <= 3; n++) { // end now if no eligible states remain if (stateIds.length < 1) break; // get random index for state ID list const r = Math.randomInt(stateIds.length); // remove that state ID from the target target.removeState(stateIds[r]); // remove that ID from the list stateIds.splice(r, 1); } </JS Post-Apply>

  2. Add state ID 11 to all party members at 100% HP:

    $gameParty.aliveMembers().forEach(actor => { if (actor.hp === actor.mhp) { actor.addState(11); } });

  3. I'm not sure I understand the context here, but here's a snippet that should find the first actor in the party with highest HP%:

    $gameParty.members().reduce((a, c) => c.hpRate() > a.hpRate() ? c : a );
    I've used Array#reduce here as a shorthand:
    Alternatively you could use a standard for loop (might be easier to understand?), e.g.

    let actor = $gameParty.leader(); for (let n = 1; n < $gameParty.members().length; n++) { const member = $gameParty.members()[n]; if (member.hpRate() > actor.hpRate()) actor = member; }

  4. I don't know if SRD's HUD Maker expects an eval or a function body wherever you're entering that code. The condition seems sound: the second party member only exists if there's more than one member in the party! Maybe this would work?

    $gameParty.members().length > 1
    Otherwise, I suggest you show a screenshot of where, exactly, you have used that condition in the HUD Maker plugin. Maybe someone more familiar with it will come along with suggestions~
Thanks a lot for your reply, l took a lot of time testing your code and this is what l found out

1. works perfectly, l just changed the for (let n = 1; n <= 3; n++) { to (let n = 1; n <= 1; n++) { since l didnt need the repeat

2. if there is more than 1 member, the condition when true seem to be repeating itself to the amount of members. l tested by doing $gameParty.aliveMembers().forEach(actor => { if (actor.hp === actor.mhp && actor.isStateAffected(12)) { actor.gainTp(5); } }); } instead of a state and it gave me 10 tp everytime l was doing the skill when there was 2 alive members. im not sure how l could write it so it only does the condition once.

3.l need the target of the skill in this case the one with a taunt state ID 55

currently using this formula, the actor with the state 55 should be the target so taking its pha parameter to show the damage number.

var dmg = 1.00

value = Math.floor((($gameTroop.members()[0].atk * 1) * dmg) * $gameParty.members()[0].pha)

return value

also can you give me an example as to how l can use the highest hp snippet in a condition? l know ill use it in the future but l just dont know how to write it properly.


4.
1645526365566.png


it is just a display condition, l have no idea how l could actually disable them. l might end up having to use blank dead actors when there are none.
2. if there is more than 1 member, the condition when true seem to be repeating itself to the amount of members. l tested by doing $gameParty.aliveMembers().forEach(actor => { if (actor.hp === actor.mhp && actor.isStateAffected(12)) { actor.gainTp(5); } }); } instead of a state and it gave me 10 tp everytime l was doing the skill when there was 2 alive members.
The problem is related to how/where you have used it. Since you haven't given any details about that, I'll guess you're using it in a damage formula.

If so, note that the default battle AI is used by actors with the Autobattle trait; plugins might also extend this to enemies etc. This AI evaluates each action's damage formula against each possible target to decide who to target, which can cause duplication like you describe. The damage formula is only designed to calculate a value: be careful if using it in any other way.

3.l need the target of the skill in this case the one with a taunt state ID 55

currently using this formula, the actor with the state 55 should be the target so taking its pha parameter to show the damage number.

var dmg = 1.00

value = Math.floor((($gameTroop.members()[0].atk * 1) * dmg) * $gameParty.members()[0].pha)

return value
Maybe something like this, then?

const actor = $gameParty.members().find(actor => actor.isStateAffected(55) ); return Math.floor($gameTroop.members()[0].atk * actor.pha);
Technical details for Array#find can be found here:

However, it sounds like you may already have the target? Depending on the context, you might not need to calculate anything at all, e.g.
  • In a damage formula, the target can be referenced as b;
  • Some plugins' scripted fields, e.g. the <JS Post-Apply> notetag from VisuStella MZ Battle Core, may offer variables like target.

also can you give me an example as to how l can use the highest hp snippet in a condition? l know ill use it in the future but l just dont know how to write it properly.
My snippet returns a reference to an actor. reduce is used to loop over all party members and return the one with highest HP%; if 2+ members have the highest HP%, it returns the first of those.

How you use it depends on what you want to do with that actor, e.g.

const actor = $gameParty.members().reduce((a, c) => c.hpRate() > a.hpRate() ? c : a ); alert(`${actor.name()} has the highest HP% in the party.`);
Thank you again for responding so quick

for 2, l probably found why it does the duplication it was because the skill target all allies but if theres no simple solution to that l will just to self target and target manually the other party members using a post eval.

for 3, yes l needed this before there was a target because its not even the enemy turn yet. the player is supposed to know the exact damage the enemy will do on the taunted actor. I didnt had the time to test the solution but will do it very soon and let you know if there is something wrong.

perfect now l understand the snippet and will use it for different params, feel free to message me your paypal l will donate for the time you took for me
Ah, I forgot about multiple targets, that makes sense! A common event or a notetag like Battle Core's <JS Post-End Action> might work?

No need for payment! I'll leave the thread open for now in case someone has suggestions on point 4 (SRD HUD Maker conditions), or in case you have any more problems with point 3. Feel free to report your post if/when you want the thread to be closed. 👋

(In future you might get a faster reply if you split your questions into separate threads, or at least one thread per plugin.)

Original thread: https://forums.rpgmakerweb.com/threads/looking-for-a-few-js-codes-in-srd-hud-maker-and-visustella-plugins.144981/