Riolu first met Yinsen a couple months before they were captured by the Ten Rings. She had lost her home and family in an attack, and Yinsen, who had been traveling and tending to the injured, found her and took her under his wing. Together they journeyed until finally they went back to Yinsens home in Gulmira. Due incredibly unfortunate timing though, the Ten Rings chose that moment to descend upon the village as they had heard from word of mouth that Yinsen had some knowledge of engineering. At that time, they were looking for any men that could possibly replicate the Stark weapons.
Yinsen refused, but after they threatened to shoot Riolu dead, he agreed without a fight (at this point his family was already dead, having died in an earlier cross-fire between Razas gang and various soldiers).
Riolu, heart heavy with guilt for being the reason Yinsen agreed to aiding the people he so disagreed with, tried to make up for it by being the most diligent aid she could be to her friend. Yinsen never held it against her, but was thankful nevertheless for the help.
When Tony was brought in dying, Yinsen was called in to patch him as he was the only proficient doctor on the premise. Together with some help from Riolu, they saved Tonys life with a car battery. Though distrustful of Tony at first simply because most of the humans she had ever met were quite cruel, Riolu slowly warmed up to him and learnt that Tonys way of talking was generally not meant to be taken very seriously, and that he seemed to be quite kind and friendly under his sarcastic demeanor and sharp wit.
For two months (at least I think it was two months) the three of them supported each in the oppressive cave before finally Tony and Yinsen finished the Mark I armor. At that moment though, Razas men came in and demanded to see what was going on, but was blown away by the bomb on the door. Yinsen, sensing that he had to buy time, but couldnt let either Tony nor Riolu come with him as it was clearly a suicide mission, forcibly put Riolu into a Pokeball and left Tony in the armor to finish downloading.
Enraged at being forced away, Riolu fought against the constraints of the Pokeball before managing to break free around the same time Tonys armor became ready to move. She ran off without him though, heart spiking in fear at the possibility that Yinsen could be dead. Tony followed quickly behind, but both were too late as Yinsen laid bleeding on the floor. On his last breath, Yinsen asked Tony to take care of Riolu because he could no longer, and asked the same of Riolu to watch over Tony. Riolu was crushed, having lost her family not even a year ago and to lose her dearest friend so soon afterwards was too much. Tony pulled Riolu away from Yinsens body, much to her protest, and together they escaped the burning compound to possible freedom.
Said freedom was a crash into the middle of nowhere, where Tony had to carry an unconscious Riolu for some hours. When Riolu awoke though, she lashed out at Tony, her grief taking the form of anger for not being able to save Yinsen. Tony took her angry scratches and yowling with a bowed head, as he too felt the heavy guilt for having failed the doctor after he had saved Tonys life.
For a day Riolu split ways with Tony in the desert, quite sure she wouldnt be able to stand his presence. But as the hours passed, Riolu remembered the promise Yinsen asked her to keep, and the days the three of them spent together to keep each other from being crushed by their cruel living conditions, and knew that and the two months they were together, Tony had become as dear of a friend as Yinsen had been. Heart clenched with guilt, she hurried back after Tony, using all her senses to track down her friend in the endless desert.
Once reunited, they promised to stick by one another and to uphold Yinsens wishes. And so together they traveled until finally they were rescued by Rhodey.
-
Riolu evolved into Lucario during Tonys battle with Obadiah, her determination to save Tonys life triggering the change.
Gallade actually has a bit of crush on Lucario as he finds her to be quite cool and mysterious. Lucario is rather oblivious to this.