Okay, I'll break it down. 🙂
So we're trying to get the enemy ID of a troop member. We know we can call enemyId, but first we need to know which member to get.
Game_Actor has a property called _lastBattleSkill, which contains details on the last skill they used in battle. This contains a property called _itemId, which is the skill ID of the skill they used.
.filter is a function you can call on an array which finds all elements that meet a given criteria. In this case, we're passing in a function, storing each party member being checked in a variable called "member". For each one, we'll return true if the _itemId of their _lastBattleSkill is equal to the ID of the Talk skill. If so, they're returned in the filtered array. If not, they're discarded.
Now obviously, once we've filtered it, we need the specific member who used the skill, so we take the [0]th element, which is the only one there will be. This gives us a Game_Actor, where we can once again access the _lastTargetIndex. Providing the result of that filter function to the index reference for $gameTroop.members() will give us the ID of the enemy the party member who used Talk targeted, and then enemyId() will tell us what kind of enemy that was.
Code:
$gameTroop.members()[
$gameParty.members().filter(function(member) {
return member._lastBattleSkill._itemId == 10;
} )[0].
_lastTargetIndex]
.enemyId()
So we're trying to get the enemy ID of a troop member. We know we can call enemyId, but first we need to know which member to get.
Game_Actor has a property called _lastBattleSkill, which contains details on the last skill they used in battle. This contains a property called _itemId, which is the skill ID of the skill they used.
.filter is a function you can call on an array which finds all elements that meet a given criteria. In this case, we're passing in a function, storing each party member being checked in a variable called "member". For each one, we'll return true if the _itemId of their _lastBattleSkill is equal to the ID of the Talk skill. If so, they're returned in the filtered array. If not, they're discarded.
Now obviously, once we've filtered it, we need the specific member who used the skill, so we take the [0]th element, which is the only one there will be. This gives us a Game_Actor, where we can once again access the _lastTargetIndex. Providing the result of that filter function to the index reference for $gameTroop.members() will give us the ID of the enemy the party member who used Talk targeted, and then enemyId() will tell us what kind of enemy that was.
