5th dnd – Is it possible to prepare a spell just before the start of your next turn by making sure the trigger is an ally's attack?

This is valid according to the rules, but can be called as metagaming

As Token's answer covers adequately, what you have described is valid according to the rules of preparation for a spell. However, depending on the style of play at your table, your DM may forbid it because it is metagaming; that is, your character is based on knowledge outside the character. Here's what the rules say about rounds and turns in combat (emphasis added):

A typical combat encounter is a clash between two camps, a multitude of weapon strikes, feints, parries, footwork and spell casting. The game organizes the chaos of combat into a cycle of rounds and turns. A turn represents about 6 seconds in the game world. During a round, each participant in a battle plays his turn. The order of the rounds is determined at the beginning of a battle, when everyone launches the initiative. Once everyone has played his turn, the fight continues until the next turn if neither side has defeated the other.

Note the phrase that I highlighted in bold: in fiction, the characters in the battle are not really take over. They are all fighting simultaneously and continuously, but real-time combat simulation is not practical, we compromise realism in favor of simplicity and we do them all in turn in the order of 39; initiative. However, this means that the order of initiative is part of the game, not the game world, and therefore the order of initiative of the fight is an out of character knowledge, which means that using this knowledge to guide the actions of your character constitutes a metagaming.

So, if you try to use this "dual spell combination" in a table that values ​​role-playing in the character and frowns on Metagaming, you will likely be called for the choice of a trigger condition. which has nothing to do with your prepared action. You are actually trying to find a loophole that allows you to specify "after the target's turn" as a trigger to deny him an end-of-turn save. On the other hand, other tables are happy to join the turn-based game and treat the fight as a game of chess. They will congratulate you for the good trick you have found. You probably already have a pretty good idea of ​​the type of table you are playing on, but otherwise, you should ask your DM in advance before trying to pull this trick during a session.