scripts: use state machine at jac script