MV Assistance With Counter Control

Hello all!

First time posting (and I hope this is the right place) spent the better part of like 3 ish hours looking on google for help. Figure I'd just post to the forum.

So I'm totally new to RPG Maker (I know how to code a bit on c#) I got some of the Yanfly plugins that I think would relate to the game I wanna make. But I can't for the life of me figure out how it works.

I know that via the video you can make a character counter x amount of times. But when I try to set up the UI it will just remove the ability upon the next turn in the order.

What I am trying to make is a Counter based class that provides covering fire for their allies based on shots in a magazine. So if an Ally takes a hit from an attack (magical or physical) the counter ability triggers making the user fire in response. And once the user is out of charges/uses of the counter state they must reapply it.

I plan on having a Tank/Taunt role in the game, the Sniper has support/medic role. So the counter attacks allow for the Sniper to get shots in while still able to do heals and the like during his normal turn.

(And yes I plan for an ammo system for this character I just want the core ability to actually function before I set parameters)
Hi, I'm not as proficient in MV as I am MZ...

In MZ I managed to make an ammo-based resource, and states that have depleting charges using Visustella plugins (MZ's version of Yanfly)

By your post I'm assuming you've tried to put this ability together already, are you able to share a little more info?

I'm also assuming you're using YEP_BattleEngineCore & YEP_BuffsStatesCore?


The way I'd approach this: (Disclaimer, I often 'get it working' - there are pros on here who may supply a cleaner approach)

2 states, 2 skills.

State 1: Covering Fire (applied to sniper - store the magazine shots here using the notetags, only removed at battle end or when magazine is 0)
State 2: Under Watch (applied to all allies - if hp damaged, order sniper to shoot "Skill 1", deduct 1 from magazine count, only remove with logic)

Skill 1: Covering Shot (What the sniper will use as retaliation)
Skill 2: Ability that Watches (applies the two states using notetag code (so only the sniper gets State 1, and all allies get state 2.)
Hi, I'm not as proficient in MV as I am MZ...

In MZ I managed to make an ammo-based resource, and states that have depleting charges using Visustella plugins (MZ's version of Yanfly)

By your post I'm assuming you've tried to put this ability together already, are you able to share a little more info?

I'm also assuming you're using YEP_BattleEngineCore & YEP_BuffsStatesCore?


The way I'd approach this: (Disclaimer, I often 'get it working' - there are pros on here who may supply a cleaner approach)

2 states, 2 skills.

State 1: Covering Fire (applied to sniper - store the magazine shots here using the notetags, only removed at battle end or when magazine is 0)
State 2: Under Watch (applied to all allies - if hp damaged, order sniper to shoot "Skill 1", deduct 1 from magazine count, only remove with logic)

Skill 1: Covering Shot (What the sniper will use as retaliation)
Skill 2: Ability that Watches (applies the two states using notetag code (so only the sniper gets State 1, and all allies get state 2.)
Yup I'm using both YEP_BattleEngineCore & YEP_BuffsStatesCore!

I'll take a crack at trying to replicate this thank you! I had originally applied a state onto the other actors in the party, but my backwards way of getting used to the system made them do counterattacks over the intended user. But the way you describe the scene makes sense! If it doesnt work out I appreciate the help regardless~
So I'm back at it (I normally work on personal stuff on weekends)

I have managed with Atramentia's advice to get the states applied to all the characters. By using a custom execution that removes the 'Under Watch' state from user and applying the 'Covering Fire' state to the user.

Sadly being inexperienced with Java or RPG I can't make heads or tails of what writing conventions to use for this ability. I'm assuming I need to use a Target Action (from YEP_BattleEngineCore & YEP_X_ActSeqPack1)

I think? Using my C-Sharp knowledge it would go something like this?

Under Watch State notes:

<target action>
target with Under Watch state takes attack
actor with Covering Fire attacks user who attacked target.
</target action>


But as someone reviewing all the videos yanfly posted for Battle sequences/abilities/skills or even looking at the forums to see other peoples battle related ideas I cannot figure out what I'm actually supposed to write in these action lists?
Sadly being inexperienced with Java or RPG I can't make heads or tails of what writing conventions to use for this ability
MV uses javascript, not java. you wont get any use of java here

I'm assuming I need to use a Target Action (from YEP_BattleEngineCore & YEP_X_ActSeqPack1)
the action sequence notetags only apply to skills, not states.

since your counterattack is triggered by a state thats placed on another battler, you should be able to use a react effect from the buffs and states core to force the origin of the state to use a skill on the attacker.
something along the lines of this
Code:
<custom react effect>
if (this.isDamage() && this.isForOpponent())
    BattleManager.queueForceAction(origin, 1, user);
</custom react effect>
however, im not 100% certain how it functions in battle systems other than STB. in STB, forced actions had a result of consuming a battler's turn if it happened before they took their normal turn that round. Im not sure if that remains to be the case in the default battle system.
Alright - here's how I'd go about it, in detail!
I've not tested this, so some troubleshooting may be required. I'm sure someone on here may be able to advise corrections, also.

For some reason, if I type a = followed by a >, it turns into an arrow. Incredibly irritating. You'll need to correct those in the codes below.

Edit: (It looks like it rendered correctly in the code blocks. Do please check the arrow function tokens just in case.)

State 1: Covering Fire (applied to sniper - store the magazine shots here using the notetags, only removed at battle end or when magazine is 0)
State 2: Under Watch (applied to all allies - if hp damaged, order sniper to shoot "Skill 1", deduct 1 from magazine count, only remove with logic)

Skill 1: Covering Shot (What the sniper will use as retaliation)
Skill 2: Ability that Watches (applies the two states using notetag code (so only the sniper gets State 1, and all allies get state 2.)

State 1: Covering Fire
Auto-remove timing: none. Remove at battle end: on.
Notetags:
Spoiler: Notetag code
JavaScript:
<State Counter>
value = 5; // magazine size - change as desired!
</State Counter>

<Custom Apply Effect>
  // Store shots on the Sniper, mirror to the visible state counter
  user._coverShots = typeof user._coverShots === 'number' ? user._coverShots : 0;
  user._coverShots = Math.max(user._coverShots, value);
  user.setStateCounter(stateId, user._coverShots);
</Custom Apply Effect>

<Custom Remove Effect>
  // When removed (empty), clear tracker :)
  user._coverShots = 0;
</Custom Remove Effect>

-=-=-=-=-=-=-=-=-=-

State 2: Under Watch
Notetags: (Correct '=>' below)
Spoiler: Notetag code
JavaScript:
<Custom Respond Effect>
  // Runs right before damage is applied to THIS ally, proced if real HP dmg.
  if (!this.isHpEffect || value <= 0) { return; }

  // Identify the current attacker
  var attacker = BattleManager._subject;
  if (!attacker || attacker.isDead()) { return; }

  // Find our 'Sniper' in party who currently has 'Covering Fire' state. Change 9999 for Covering fire's STATE ID in DB. Check the => here.
  var sniper = $gameParty.aliveMembers().find(a => a.isActor() && a !== user && a.hasState(9999));
  if (!sniper) { return; }

  // Prevent infinite loops if the 'Covering Shot' SKILL itself triggers this (Change 7777 for Covering Shot's SKILL ID in DB.)
  var act = BattleManager._action;
  if (act && act.item && act.item() && act.item().id === 7777) { return; }

  // Check ammo and update counter (change 9999 here for Covering Fire's STATE ID.)
  sniper._coverShots = (typeof sniper._coverShots === 'number') ? sniper._coverShots : sniper.stateCounter(9999) || 0;
  if (sniper._coverShots <= 0) {
    sniper.removeState(9999);
    return;
  }

  // Spend one shot, remove state if last shot (change 9999 for Covering Fire's STATE ID.)
  sniper._coverShots -= 1;
  sniper.setStateCounter(9999, sniper._coverShots);
  if (sniper._coverShots <= 0) { sniper.removeState(9999); }

  // Order the counter-shot at the attacker (change 7777 to Covering Shot's SKILL ID.)
  sniper.forceAction(7777, attacker.index());
  BattleManager.forceAction(sniper);
</Custom Respond Effect>

-=-=-=-=-=-=-=-=-=-

Skill 1: Covering Shot
Scope: 1 enemy. Hit Type: whatever your flavour, certain or weapon hit. Damage formula: yours to determine. message/anime: as you like.

NO notetags here.

-=-=-=-=-=-=-=-=-=-

Skill 2: Ability that watches, let's call it 'Overwatch'
Scope: User. Effects: none, we'll apply via notetags.

Notetags:
Spoiler: Notetag code
JavaScript:
<Custom Apply Effect>
  // Give the Sniper their magazine state 'Covering Fire' and set shots
  var sId = 9999;         // change to Covering Fire STATE ID.
  var mag = 5;
  user.addState(sId);
  user._coverShots = mag;
  if (user.setStateCounter) user.setStateCounter(sId, mag); // i'm assuming using YEP State Counter


  // Now put the "Under Watch" state on all living allies (including the user) (Check the = > arrows again here)
  var wId = 8888;         // change to Under Watch STATE ID. Apply to all party members
  $gameParty.aliveMembers().forEach(m => m.addState(wId));
</Custom Apply Effect>

Alternative, if you don't want the sniper to have Under Watch, replace the last line of code with: (Check the = > arrows again here)
JavaScript:
$gameParty.aliveMembers().forEach(m => { if (m !== user) m.addState(wId); });
MV uses javascript, not java. you wont get any use of java here


the action sequence notetags only apply to skills, not states.

since your counterattack is triggered by a state thats placed on another battler, you should be able to use a react effect from the buffs and states core to force the origin of the state to use a skill on the attacker.
something along the lines of this
Code:
<custom react effect>
if (this.isDamage() && this.isForOpponent())
    BattleManager.queueForceAction(origin, 1, user);
</custom react effect>
however, im not 100% certain how it functions in battle systems other than STB. in STB, forced actions had a result of consuming a battler's turn if it happened before they took their normal turn that round. Im not sure if that remains to be the case in the default battle system.
Sorry for using the wrong terms lol I often just shorthand Javascript to Java, which I guess can get confusing.

I did not notice the two words in the Yanfy wiki that said Action Sequences only affect Skills and Items whoops my bad lol! Although it seems from what you informed me I was looking in the entirely wrong direction and should of been looking at the Buff & States Core wikis! I figured since its an attack using a skill it would be in the Battle Core/Sequences since it's adding attack mid combat!

Thank you for putting me into the right Direction I'll take a look at what Atramentia also suggested and hopefully with both of your helps I can get to finishing what I had hoped to accomplish!
As said, SerChansey, what I put down is just 'fired from the hip', check the docs for the appropriate plugins, check the notetags, and check the javascript is right for MV 😉

As a coder, I'm sure you'll piece together the above solution, or one better in the process of checking it over.
As said, SerChansey, what I put down is just 'fired from the hip', check the docs for the appropriate plugins, check the notetags, and check the javascript is right for MV 😉

As a coder, I'm sure you'll piece together the above solution, or one better in the process of checking it over.
Regardless I very much appreciate you taking the time to push me into the right direction lol went from looking at the Counter Control pulgin to Buffs&States which is more what I should be looking at.

I have tried your solution but sadly the skill doesnt apply the states, and when I use a work around to custom apply the states to the party and sniper it the counter attack doesn't work just yet. But I do feel I'm on the right direction with your guidance and will play around with what you have suggested!


Edit: I think it's not applying due to Custom Apply Effect only working for States themselves and not Skill! Looking into it more to see if my way of applying the stats will work with your code

Edit2: Seems to do the trick for applying states; changing <Custom Apply Effect> to <After Eval> has allowed the Skill code to play out correctly! Now to find the source of the problem for the states!

Edit3: After looking over the Yanfly documents the only thing I can see that would/could cause and issue with the States is that;
if (!this.isHpEffect || value <= 0) { return; } is being used in a <Custom Respond Effect> which only applies after damage is dealt. Since this part of the code is supposed to run BEFORE damage is dealt its possible the loop never starts. But even after putting it in a <Custom React Effect> just to check the values its still not executing. Gonna play around with everything
most of that wouldnt function
<State Counter> value = 5; // magazine size - change as desired! </State Counter>
isnt a notetag recognized by yanfly's plugins

<Custom Apply Effect> // Store shots on the Sniper, mirror to the visible state counter user._coverShots = typeof user._coverShots === 'number' ? user._coverShots : 0; user._coverShots = Math.max(user._coverShots, value); user.setStateCounter(stateId, user._coverShots); </Custom Apply Effect>
would make that _coverShots property NaN as value wouldnt be defined

if (!this.isHpEffect || value <= 0) { return; }
any return statement inside these eval'd notetags will cause an immediate error and would invalidate the entire notetag. also attacker and sniper would already be the preset user and origin variables
<Custom Apply Effect> // Give the Sniper their magazine state 'Covering Fire' and set shots
apply effects only work in states, not skills

@SerChansey im assuming youre also using yanfly's skill core plugin? i suggest it since it adds additional evals to make things easier.
State 1: Covering Fire (applied to sniper - store the magazine shots here using the notetags, only removed at battle end or when magazine is 0)
assuming 5 shots should be loaded when the setup skill is used and the state is gained...
Code:
<Custom Apply Effect>
user._coverShots = 5;
user.setStateCounter(stateId, user._coverShots);
</Custom Apply Effect>

<Custom Remove Effect>
delete user._coverShots;
user.friendsUnit().aliveMembers().forEach(member => member.removeState(stateId+1));
</Custom Remove Effect>
this is under the assumption that state 2 will be the next state in the database. if not, remove the stateId+1 and replace it with the id for state 2
State 2: Under Watch (applied to all allies - if hp damaged, order sniper to shoot "Skill 1", deduct 1 from magazine count, only remove with logic)
Code:
<Custom Respond Effect>
if (this.isDamage() && this.isForOpponent() && origin._coverShots)
    BattleManager.queueForceAction(origin, x, user);
</Custom Respond Effect>
replace the x here with the id for the counter skill
Skill 1: Covering Shot (What the sniper will use as retaliation)
Code:
<Custom Execution>
if (user._coverShots){
    user._coverShots--;
    user.setStateCounter(x, user._coverShots);
    if (user._coverShots <= 0)
        user.removeState(x);
};
</Custom Execution>
replace the x's here with the id for state 1
Skill 2: Ability that Watches (applies the two states using notetag code (so only the sniper gets State 1, and all allies get state 2.)
this is why i recommended yanfly's skill core. so that the one skill could do something for the user and something else for everyone else easily
Code:
<Custom Execution>
user.addState(y);
user.friendsUnit().aliveMembers().forEach(member => {
  if (member != user) member.addState(z);
});
</Custom Execution>
replace the y with state 1 and the z with state 2

be sure to test it, as im not sure if an actor countering with this prematurely consumes their action doing this in whatever battle system you may be using
most of that wouldnt function

isnt a notetag recognized by yanfly's plugins


would make that _coverShots property NaN as value wouldnt be defined


any return statement inside these eval'd notetags will cause an immediate error and would invalidate the entire notetag. also attacker and sniper would already be the preset user and origin variables

apply effects only work in states, not skills

@SerChansey im assuming youre also using yanfly's skill core plugin? i suggest it since it adds additional evals to make things easier.

assuming 5 shots should be loaded when the setup skill is used and the state is gained...
Code:
<Custom Apply Effect>
user._coverShots = 5;
user.setStateCounter(stateId, user._coverShots);
</Custom Apply Effect>

<Custom Remove Effect>
delete user._coverShots;
user.friendsUnit().aliveMembers().forEach(member => member.removeState(stateId+1));
</Custom Remove Effect>
this is under the assumption that state 2 will be the next state in the database. if not, remove the stateId+1 and replace it with the id for state 2

Code:
<Custom Respond Effect>
if (this.isDamage() && this.isForOpponent() && origin._coverShots)
    BattleManager.queueForceAction(origin, x, user);
</Custom Respond Effect>
replace the x here with the id for the counter skill

Code:
<Custom Execution>
if (user._coverShots){
    user._coverShots--;
    user.setStateCounter(x, user._coverShots);
    if (user._coverShots <= 0)
        user.removeState(x);
};
</Custom Execution>
replace the x's here with the id for state 1

this is why i recommended yanfly's skill core. so that the one skill could do something for the user and something else for everyone else easily
Code:
<Custom Execution>
user.addState(y);
user.friendsUnit().aliveMembers().forEach(member => {
  if (member != user) member.addState(z);
});
</Custom Execution>
replace the y with state 1 and the z with state 2

be sure to test it, as im not sure if an actor countering with this prematurely consumes their action doing this in whatever battle system you may be using
Atramentia did say they were more a MZ user over a MV one but I'm still thankful for the help and assistance! Alot of the logic in the code made sense to me coming from Unity and the coding there. But again using different versions of the software can't exactly be perfect!

I do infact have Skill Core (because I wanted to have a system where you can have abilities that consume items so I needed it for SkillCostItem)

I already identified some of what you found but I'll take a look at your edits you've placed here and see about getting things working! Just finished eating supper so going to look through everything. Will edit my posts with updates like my prior reply!


Edit1: So the current code definitely works as planned! But the problem you mentioned about counter attack consuming the players turn is true (had to boost the agility of the enemy to test it since the Sniper always went before they did). As well as the counter cancels any battle animations on the damaged ally (assuming because it plays the action directly after damage is applied)
Alright - here's how I'd go about it, in detail!
Sorry but this entire post reads like it’s AI-generated.
Sorry but this entire post reads like it’s AI-generated.
I'm near sure it is, or at least the code is.
Actually had a good stab at that myself... 🙁 I've been trying to help out where I can in recent days... find some positive and kindness by being positive and kind. I've learned a TON over the last year. (And have further to go) But if you want to call it AI, I can't stop that.
I've got some other posts, too, here on the forums if anyone wants to go dump on those, too? >_>
As well as the counter cancels any battle animations on the damaged ally (assuming because it plays the action directly after damage is applied)
that one is easier to deal with. you can use state 2 to apply a 3rd, invisible state to the attacker and then give that state an action end effect to make the sniper act after the skill has fully resolved.

state 2
Code:
<Custom Respond Effect>
if (this.isDamage() && this.isForOpponent() && origin._coverShots){
  user.addState(stateId+1);
  user.setStateOrigin(stateId+1, origin);
}
</Custom Respond Effect>
like before, replace stateId+1 with the id of state 3 if its not going to be the immediate next state in the database

state 3
Code:
<Custom Action End Effect>
BattleManager.queueForceAction(origin, x, user);
user.removeState(stateId);
</Custom Action End Effect>
and x is the counter skill id
But the problem you mentioned about counter attack consuming the players turn is true
that one is the bigger issue.
I believe that would best be addressed with patch to the battle engine core. afaik, you need a way for the sniper to never leave the _actionBattlers list to maintain turn order and for them to not be pushed into the _performedBattlers list to be able to act again, but i woudnt be able to write and test that for a while.
a more direct method of manually saving those lists before doing the counter and resetting them after the counter shot might work? id have to test that later.

theres also workaround possibilities of delaying the counter to the end of the turn or by faking the counter entirely by running some simple damage calc, playing an animation on the counter target, deducting their hp, and forcing a popup.
that one is easier to deal with. you can use state 2 to apply a 3rd, invisible state to the attacker and then give that state an action end effect to make the sniper act after the skill has fully resolved.

state 2
Code:
<Custom Respond Effect>
if (this.isDamage() && this.isForOpponent() && origin._coverShots){
  user.addState(stateId+1);
  user.setStateOrigin(stateId+1, origin);
}
</Custom Respond Effect>
like before, replace stateId+1 with the id of state 3 if its not going to be the immediate next state in the database

state 3
Code:
<Custom Action End Effect>
BattleManager.queueForceAction(origin, x, user);
user.removeState(stateId);
</Custom Action End Effect>
and x is the counter skill id

that one is the bigger issue.
I believe that would best be addressed with patch to the battle engine core. afaik, you need a way for the sniper to never leave the _actionBattlers list to maintain turn order and for them to not be pushed into the _performedBattlers list to be able to act again, but i woudnt be able to write and test that for a while.
a more direct method of manually saving those lists before doing the counter and resetting them after the counter shot might work? id have to test that later.

theres also workaround possibilities of delaying the counter to the end of the turn or by faking the counter entirely by running some simple damage calc, playing an animation on the counter target, deducting their hp, and forcing a popup.
The bootleg jury-rig idea would have the Scout (the class of the Sniper) being very high agility focused thus they normally would act before enemies, probably would have to balance the party to have low to medium agility to compensate and obviously boss battles would potentially have bosses being faster.


Either way I very very much appreciate the help you've given with your experience with the software Robro33! As well as any of the other assistance from Atramentia (despite the mean comments from other posters). This project has been fun for my creative outlet to get me back into game making! I think I should try to learn some Javascript as well so in the future I can tackle problems myself.

Original thread: https://forums.rpgmakerweb.com/threads/assistance-with-counter-control.180401/