At the time and place fixed for the hearing of plaintiff's motion for a writ of restitution, the defendant, or any person in possession or claiming possession of the property, may answer, orally or in writing, and assert any legal or equitable defense or set-off arising out of the tenancy. If the answer is oral the substance thereof shall be endorsed on the complaint by the court. The court shall examine the parties and witnesses orally to ascertain the merits of the complaint and answer, and if it shall appear that the plaintiff has the right to be restored to possession of the property, the court shall enter an order directing the issuance of a writ of restitution, returnable ten days after its date, restoring to the plaintiff possession of the property and if it shall appear to the court that there is no substantial issue of material fact of the right of the plaintiff to be granted other relief as prayed for in the complaint and provided for in this chapter, the court may enter an order and judgment granting so much of such relief as may be sustained by the proof, and the court may grant such other relief as may be prayed for in the plaintiff's complaint and provided for in this chapter, then the court shall enter an order denying any relief sought by the plaintiff for which the court has determined that the plaintiff has no right as a matter of law: PROVIDED, That within three days after the service of the writ of restitution issued prior to final judgment, the defendant, or person in possession of the property, may, in any action for the recovery of possession of the property for failure to pay rent, stay the execution of the writ pending final judgment by paying into court or to the plaintiff, as the court directs, all rent found to be due, and in addition by paying, on a monthly basis pending final judgment, an amount equal to the monthly rent called for by the lease or rental agreement at the time the complaint was filed: PROVIDED FURTHER, That before any writ shall issue prior to final judgment the plaintiff shall execute to the defendant and file in the court a bond in such sum as the court may order, with sufficient surety to be approved by the clerk, conditioned that the plaintiff will prosecute his or her action without delay, and will pay all costs that may be adjudged to the defendant, and all damages which he or she may sustain by reason of the writ of restitution having been issued, should the same be wrongfully sued out. The court shall also enter an order directing the parties to proceed to trial on the complaint and answer in the usual manner.
If it appears to the court that the plaintiff should not be restored to possession of the property, the court shall deny plaintiff's motion for a writ of restitution and enter an order directing the parties to proceed to trial within thirty days on the complaint and answer. If it appears to the court that there is a substantial issue of material fact as to whether or not the plaintiff is entitled to other relief as is prayed for in plaintiff's complaint and provided for in this chapter, or that there is a genuine issue of a material fact pertaining to a legal or equitable defense or set-off raised in the defendant's answer, the court shall grant or deny so much of plaintiff's other relief sought and so much of defendant's defenses or set-off claimed, as may be proper.