Hello, I’m attempting to create a mimic opponent trainer that checks the players team before battle and copies it. With the trainers PBS file being effectively static during runtime, I’m struggling to think of ways that this could be scripted.
Any ideas?
This would have to be done through a script for sure. You'd still have to create a blank trainer in the trainers PBS but then you'd have to build out the method to clone your party and another method to call that for the trainer and build their party. once you do that, you'd just call the trainer method and start battle with the blank trainer you created.
I don't think this would be crazy hard to build but I won't be at w computer for a day or two to test it.
You need an on_trainer_load handler. Put this in the Overworld_EncounterModifiers script (you can find it easily by using ctrl+shift+F to search all scripts for
EventHandlers.add(:on_trainer_load,). You'll still need to fill out PBS data for the trainer with at least one Pokemon, so that the game has something to start with. But this code will replace that trainer's team with a copy of the player's team when the battle starts; any team that you fill out in the PBS will just be there as a placeholder.The only thing you need to fill in is the condition (third line of this). This will be called every time a trainer battle is started, so you have to make sure it aborts itself if it's not a battle you want to modify. If it's just a single trainer in the game, the easiest way would be to replace
[condition]withtrainer.trainer_type != :PICKPOCKET || trainer.name != "Kenneth"(replacing the trainer type and name with what you have in PBS).Or if you want it to be tied to a game switch, you could set it to
!$game_switches[50]so that it'll only trigger when game switch 50 is turned on (and you can, of course, change this to any other game switch you'd like). You can even make it automatically turn the switch off afterwards by adding$game_switches[50] = falseafter line 3, if you want.If you have a more complex condition in mind and know how to code, then please note that line 3 is a negative condition (ie, if this is true, cancel this modification), which is probably the opposite of how you'd naturally think to "phrase" it, so don't let that trip you up.
Finally, if you want to make any modifications to the opponent's team, like levels, then you can very easily slot them where I have it marked between the heal and calc_stats calls (technically calc_stats isn't needed for just what I have here, but I thought I'd include it in case you wanted to add anything else that would need it).
IMPORTANT EDIT: If you're using the first condition of specifying trainer type + trainer name, I had the incorrect value for the trainer's name before (it's just .name, not .trainer_name). It's fixed now, but if you saw this and copy+pasted it before this edit, make sure you fix that.
This is good, but if you don’t want to first define a dummy trainer in the pbs, you don’t need the event handler. You can create a NPCTrainer.new and fill its party, then just call TrainerBattle.start on that trainer.
Huh, I didn’t know that.
^ This was exactly the answer, worked first try. By adding some player gender checks to the NPC event, this is a fully functioning mimic trainer. Case closed everyone.
If this is possible, I'd love to know how as well but unfortunately I don't think it is.
The way I understand it, every Trainer's team has to be predefined in the trainers.txt PBS file.
You can create any dynamically, in my game I wanted the battle tower teams to be randomly generated so I created an array of pokemon for each trainer type and each trainer then gets a random 3 pokemon from that array. Made it so that my battle tower is always different 🙂
How do you set things to pick from a pool at random?
I don't have the exact code on me, but basically you set different arrays, each with multiple Pokemon. You create one of these for each trainer type you have and make a blank trainer for each. Then you have a method that randomly chooses 3 and assigns it to that trainer for battle.
The most difficult part was then figuring out how to also assign an overworld sprite.
The code is in my game if you'd like to look though 🙂
trainer = NPCTrainer.new(trainer_type, name) trainer.party = Marshal.load(Marshal.dump($player.party)) TrainerBattle.start(trainer)
Easy
I feel like I’ve seen it done in a fan game that I watched Voltsy play, but it may have been a custom script / plugin that’s not released to the public. It was a while back, though, and it could’ve been a rom hack instead.
I’m no expert, but maybe it has something to do with variables?
The really dumb way is 6 dittos lol
Until Ditto is only cloning your lead party member and none of the items on your team.