Any person bringing a civil or criminal action against a member of the National Guard of this state for any act done while in discharge of his military duty shall give security for the costs and reasonable attorney's fees incurred by the state or defendant in defending the same, in the same manner and subject to the same regulations applicable in the case of a nonresident plaintiff, and, if the plaintiff fails to recover, such attorney's fees may be taxed with the costs and judgment therefor entered against him and his sureties on the bond.