Added logic for scripted behaviors, emotions, and some bug fixes