YEP_X_CounterControl

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
Hi, so I'm currently encountering difficulties due to some inherent incompatibilities between YEP_X_CounterControl and LeTBS. I think I've found a simple solution, but it would involve making the <Default Counter> notetag useable in more than just actor & enemy noteboxes. At a minimum, I need to be able to use it in the weapons notebox, but other areas could prove useful. Anyways, I have no idea what part of the code dictates where it can be used. Here's the snippet of code for <Default Counter> in YEP_X_CounterControl.js.
JavaScript:
DataManager.processCounterNotetags1 = function(group) {
  for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);

    obj.defaultCounter = Yanfly.Param.CounterDefault;
    obj.counterTotal = Yanfly.Param.CounterTotal;

    for (var i = 0; i < notedata.length; i++) {
      var line = notedata[i];
      if (line.match(/<DEFAULT COUNTER:[ ](\d+)>/i)) {
        obj.defaultCounter = parseInt(RegExp.$1);
      } else if (line.match(/<DEFAULT COUNTER:[ ](.*)>/i)) {
        var name = String(RegExp.$1).toUpperCase();
        var id = Yanfly.SkillIdRef[name];
        if (id) obj.defaultCounter = id;
      }
    }
  }
};
Edit: Could this have something to do with it?
JavaScript:
Yanfly.Counter.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
  if (!Yanfly.Counter.DataManager_isDatabaseLoaded.call(this)) return false;
  if (!Yanfly._loaded_YEP_X_CounterControl) {
    this.processCounterNotetagsI($dataItems);
    this.processCounterNotetagsW($dataWeapons);
    this.processCounterNotetagsA($dataArmors);
    this.processCounterNotetagsS($dataSkills);
    this.processCounterNotetagsT($dataStates);
    this.processCounterNotetagsSys($dataSystem);
    this.processCounterNotetags1($dataActors);
    this.processCounterNotetags1($dataEnemies);
    this.processCounterNotetags2($dataActors);
    this.processCounterNotetags2($dataClasses);
    this.processCounterNotetags2($dataEnemies);
    this.processCounterNotetags2($dataWeapons);
    this.processCounterNotetags2($dataArmors);
    this.processCounterNotetags2($dataStates);
    this.processCounterNotetags3($dataSkills);
    this.processCounterNotetags4($dataSkills);
    this.processCounterNotetags4($dataItems);
    Yanfly._loaded_YEP_X_CounterControl = true;
  }
  return true;
};
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
Code:
this.processCounterNotetags1($dataActors);
    this.processCounterNotetags1($dataEnemies);
These lines in DataManager.isDatabaseLoaded are where you want to be looking. If you want to process notetags in more groups than the ones the plugin already does, add them here.

Note that depending on what those notetags end up doing, you may have to tweak other parts of the plugin to deal with the new groups, especially if the notetags cause manipulation of properties unique to the groups in question.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
Damn, I was hoping it'd be a simple tweak. I added this.processCounterNotetags1($dataWeapons); but upon doing a counter in battle, it's not using the counter skill I set...hmm.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
Do a search in the plugin to see what the defaultCounter property is actually doing.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
Besides the code in my OP, the only other times "defaultCounter" come up in the plugin is:
JavaScript:
Game_Actor.prototype.makeCounterSkills = function() {
    Game_Battler.prototype.makeCounterSkills.call(this);
    var length = this.equips().length;
    for (var i = 0; i < length; ++i) {
      var obj = this.equips()[i];
      if (!obj) continue;
      if (obj.counterSkills) {
        Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      }
      this.extendCounterSkillsEval(obj);
    }
    if (this.currentClass().counterSkills) {
      obj = this.currentClass();
      Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      this.extendCounterSkillsEval(obj);
    }
    if (this.actor().counterSkills) {
      obj = this.actor();
      Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      this.extendCounterSkillsEval(obj);
    }
    if (this._counterSkills.length <= 0) {
      this._counterSkills.push(obj.defaultCounter);
    }
};
and also
JavaScript:
Game_Enemy.prototype.makeCounterSkills = function() {
    Game_Battler.prototype.makeCounterSkills.call(this);
    if (this.enemy().counterSkills) {
      obj = this.enemy();
      Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      this.extendCounterSkillsEval(obj);
    }
    if (this._counterSkills.length <= 0) {
      this._counterSkills.push(obj.defaultCounter);
    }
};
Shouldn't the code in my OP be setting obj.defaultCounter to whatever skill ID is in the notetag?
Edit: I'm referring to this...
JavaScript:
DataManager.processCounterNotetags1 = function(group) {
  for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);

    obj.defaultCounter = Yanfly.Param.CounterDefault;
    obj.counterTotal = Yanfly.Param.CounterTotal;

    for (var i = 0; i < notedata.length; i++) {
      var line = notedata[i];
      if (line.match(/<DEFAULT COUNTER:[ ](\d+)>/i)) {
        obj.defaultCounter = parseInt(RegExp.$1);
      } else if (line.match(/<DEFAULT COUNTER:[ ](.*)>/i)) {
        var name = String(RegExp.$1).toUpperCase();
        var id = Yanfly.SkillIdRef[name];
        if (id) obj.defaultCounter = id;
      }
    }
  }
};
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
What is the one for weapons doing?
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
What is the one for weapons doing?
I just put a simple <Default Counter: 292> notetag in the weapon's notebox. Or do you mean the plugin's code? As far as I'm aware, there's no instance of defaultCounter being used other than in the sections I've posted above. I'm guessing that's my issue huh? I was under the assumption this snippet would set obj.defaultCounter to the ID listed in the notetag.
JavaScript:
      if (line.match(/<DEFAULT COUNTER:[ ](\d+)>/i)) {
        obj.defaultCounter = parseInt(RegExp.$1);
      } else if (line.match(/<DEFAULT COUNTER:[ ](.*)>/i)) {
        var name = String(RegExp.$1).toUpperCase();
        var id = Yanfly.SkillIdRef[name];
        if (id) obj.defaultCounter = id;
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
I just wanted to make sure the weapon part wasn't overriding that.
 

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
Sorry if this is not helpful, but why not just use the custom counter skills lunatic code since it works in the weapon note tag box?

Code:
  <Custom Counter Skills>
   if (user.name() === 'Harold') {
     skills.push(50, 51, 52);
   } else if (user.name() === 'Therese') {
     skills.push(53, 54, 55);
   } else if (user.name() === 'Marsha') {
     skills.push(56, 57, 58);
   } else if (user.name() === 'Lucius') {
     skills.push(59, 60, 61);
   }
  </Custom Counter Skills>
Since it uses skills.push, if you reduce the skill Id to just the one skill you would like to use as the counter, would that not then technically become the 'default' counter associated with that weapon?
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
Because I'm using LTBS, which totally ignores Yanfly's CounterControl plugin. I was able to do a hackjob with the code so it would at least read defaultCounter. If I could get it to read the counter skill array, then I'd happily do that, but I haven't been able to after several attempts.

I've tried your suggestion at the simplest scale, i.e. <Counter Skills: 3> but it didn't make that the defaultCounter...
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
I appreciate the attempt though lol.

---

Ok, instead of getting defaultCounter to work in the Weapons' notetag, I think a different approach would be better. I'm thinking of calling the skill ID of a skill within the array of possible counter skills, as defined by the Yanfly CounterControl plugin. So basically obj.counterSkills instead of obj.defaultCounter. The problem is, I'm currently using $dataSkills[$dataActors[entity.battler().actorId()].defaultCounter]; to call the skill ID of the counter. It fails when I try to sub counterSkills in its place, due to it being an array. How do I have it pick a single skill ID out of that array of skill IDs? Any method will do, even random. I'm probably gonna have to use Math.floor and Math.random to do this, and probably "length", but I'm lost as far as syntax goes...

Edit: I'm also not sure whether I'm supposed to use counterSkills or _counterSkills, whats the difference? Btw, this is the code in YEP_X_CounterControl.js for counter skill creation.
JavaScript:
Game_Battler.prototype.counterSkills = function() {
    if (this._counterSkills === undefined || this._counterSkills === []) {
      return [];
    }
    var array = [];
    var length = this._counterSkills.length;
    for (var i = 0; i < length; ++i) {
      var skillId = this._counterSkills[i];
      var skill = $dataSkills[skillId];
      array.push(skill);
    }
    return array;
};

Game_Battler.prototype.makeCounterSkills = function() {
    this._counterSkills = [];
    var length = this.states().length;
    for (var i = 0; i < length; ++i) {
      var obj = this.states()[i];
      if (!obj) continue;
      if (obj.counterSkills) {
        Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      }
      this.extendCounterSkillsEval(obj);
    }
};
Or it might be this...
JavaScript:
Game_Actor.prototype.makeCounterSkills = function() {
    Game_Battler.prototype.makeCounterSkills.call(this);
    var length = this.equips().length;
    for (var i = 0; i < length; ++i) {
      var obj = this.equips()[i];
      if (!obj) continue;
      if (obj.counterSkills) {
        Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      }
      this.extendCounterSkillsEval(obj);
    }
    if (this.currentClass().counterSkills) {
      obj = this.currentClass();
      Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      this.extendCounterSkillsEval(obj);
    }
    if (this.actor().counterSkills) {
      obj = this.actor();
      Yanfly.Util.extend(this._counterSkills, obj.counterSkills);
      this.extendCounterSkillsEval(obj);
    }
    if (this._counterSkills.length <= 0) {
      this._counterSkills.push(obj.defaultCounter);
    }
};
Edit2: I just tried the following and got "Cannot set property 'commandOn' of undefined"
var counterId = Math.floor(Math.random()*$dataActors[entity.battler().actorId()]counterSkills.length)
var skill = $dataSkills[$dataActors[entity.battler().actorId()].counterId];


This was the working code from before:
var skill = $dataSkills[$dataActors[entity.battler().actorId()].defaultCounter];

I also tried this and got the same error (still using same var counterId though)
var skill = $dataSkills[counterId];

Edit3: Lol derp, I forgot a period...ok, so now I'm using this, which at least let's me load into the game. However, when my unit tries to counter-attack, I get "Type Error: Cannot read property 'id' of null".
var counterId = Math.floor(Math.random()*$dataActors[entity.battler().actorId()].counterSkills.length)
var skill = $dataSkills[counterId];


The error points to this line of code:
var data = obj.id === battler.attackSkillId() ? entity.getAttackScopeData() : entity.getObjectScopeData(obj);
Which leads me to think I need to include the skill's scope data...but I have no idea how. I find that weird since I didn't need to do so when I was using defaultCounter.

Edit4: Can someone please tell me how to get the skill IDs out of an array of skills? I think that's all I need to proceed.

This is what I got to work with so far:
I know that $dataActors[entity.battler().actorId()] will point to the unit in question, so I just need to tac on .counterSkills or ._counterSkills to the end of that to get the array of skills for countering right? I know I have to use .length somehow, but I don't know how to use this correctly. I know that ._counterSkills.length simply returns the amount of skills in the array, but not the skill ID of those skills themselves. How would I get the skill IDs of said skills? @Trihan, would you know how? Ideally, I'd like to select the skill with the highest skill ID in the counter skills array, so probably Math.max?

So if $dataActors[entity.battler().actorId()]._counterSkills would return an array containing skills 1, 2, & 3...how do I get it to select skill ID 3?

Edit5: What if I use reverse() to flip the array, then use slice(0, 1) to select the (now) 1st item in that array, which should be the highest skill ID. Or is there a simpler way?

Edit6: Ok, it looks like the find() function would better serve my needs. But once I obtain get the value of an element from the array, "return" simply spits it out right there and then, how do I put that into a var?
 
Last edited by a moderator:

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

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,034
Messages
1,018,446
Members
137,820
Latest member
georg09byron
Top