(a) A setoff may be pleaded in any action for the recovery of money and may be a cause of action arising either upon contract or tort.
(b) In suits by executors or administrators, debts existing against their testators or intestates and owing to the defendant at the time of the death of the testator or intestate may be set off by the defendant in the same manner as if the action had been brought by and in the name of the deceased.
(c) Judgments, bills, bonds, notes, or other writings assigned to the defendant after suit has been commenced against him or her shall not be allowed to be set off against the demands of the plaintiff.
(d) When any plaintiff shall be indebted to a defendant in any bond, bill, note, contract, book account, or other liquidated demand and the defendant fails to set off the debt against the plaintiff's demand, the defendant shall be forever barred from recovering costs in any suit which he or she may thereafter institute upon any such bond, bill, note, contract, book account, or other liquidated demand.
(e) Where it appears that a new party is necessary to a final decision upon the setoff, the court shall permit the new party to be made, if it also appears that, owing to the insolvency or nonresidence of the plaintiff or other cause, the defendant will be in danger of losing his or her claim unless permitted to use it as a setoff.