I did it in my own fangame.
That said, implementing this is complicated on a Pokémon vanilla game. Not in terms of coding, but in terms of balancing and implementation. My own implementation is complex (it uses a second value in parallel to friendship: the dread) and there have been dozens of pages of game design written about it. (I would have liked to put the link, but it is only in French for the moment).
The first obstacle is the basic friendship: 70 in the vast majority of cases. Therefore, where to put the threshold of disobedience?
The second obstacle is punitiveness. It will be very annoying for the player if (almost) every new captured Pokémon disobeys him (the fault of the 70 of friendship at the beginning). Therefore, it is important to make sure that (with some exceptions) a freshly captured Pokémon does not disobey.
The third obstacle is the very conception of friendship: Game Freak wants its games to be accessible to the youngest age, so we must not frustrate the players! Thus, the friendship almost never drops, only increase. Fainting results in a negligible penalty and the only other method is bitter herbs that require an explicit action from the player.
Finally, it will be necessary to adjust the probability of disobedience to avoid threshold effects.
So we need to correct and rebalance the possible variations of friendship, as well as the starting friendship for all Pokémons.