yikes, I wrote a lot more than I thought I did!
Personally for turn-based random encounters, I would do something like this:
Upon entering an area where combat is possible get a random number between X and X+some- this is how far the player can travel before combat is started. As the player moves, reduce this. When it hits 0, start combat:
In each combat-possible area, keep a list of monsters the player can fight. Pick a random set (lets say, up to 3) of these monsters and store their names in a global variable. You might want to add some randomizing to their HP and power, so even if the player fights the same set of monsters again it’ll be slightly different.
Add a new scene for combat (suspend, or save and remove, the main scene).
Add all the monsters and players, in the combat scene you probably want to have empties placed for where players go and empties for where monsters can be- then it’s just a matter of choosing which empty to place the unit on.
Decide initiative(that is, turn order: which unit goes first, who goes next, etc) personally I’d jsut give every unit a stat named “speed” and the higer speed goes sooner.
Make an empty list, and loop through all the units in turn order, appending them to the list.
You are now ready for actual combat.
Using a single script, you can control all the units- the first unit in the list is the one who’s turn it is. If the unit is controlled by the player, wait until the player chooses what to do- if it’s AI controlled, pick an action (generally attack, but you could add if the unit is at X% HP, there’s a chance it will flee, etc)
when the unit’s action is chosen, disable player input, and play whatever animations or graphics. When those have finished, use list.append(list.pop(0)) to move the unit from the first spot in line, to the last. The next unit will now be the first, and you can continue like this.
Make sure to leave a variable on the unit that changes based on where it is in the list- when a unit leaves combat (dies, flees, summoner runs out of mana, whatever) use list.pop(unitPosition) to remove it from the list, before actually deleting the object.
When all the units on one side are gone, you can end combat- if the player lost, end the scene and add a game over scene- if the player won, resume the main scene (or change to it and set the player position and whatnot to their correct places), and then get a new number to decide how long the player can move outside of combat.