For creating a nemesis semi-randomly, there are two ways of selecting said nemesis: before the fight (if [RandNum] commander is defeated, becomes nemesis), and during/after the fight (if player performs [awesome maneuver], target becomes nemesis). For caching reasons, I recommend the pre-selection method because the game keeps a small set of logs instead of logging everything to keep up with what the player does.
For "remembering the player," knowing what you'll want the nemesis to say will help you figure out what variables to keep logged. I.e., "Remember when we fought in {Map Name] and you set me on fire?" "Remember when we fought in [Map Name] and you threw me?"
The code would look ballpark-ish to
mapmemory = mapID
if statusailment == true
battlememory = statusID
if maneuvergroup == true
battlememory = maneuverID
weaponmemory = weaponID
Then, when he pops up as the nemesis, you incorporate mapmemory, battlememory, and weaponmemory into his speech and stats.
Granted, you likely won't end up using those exact variable names, but hopefully, you get the idea.