scripting: disable events in StateMachine::deactivate() and add mutex protection to StateMachine::activate()

Signed-off-by: Johannes Meyer <johannes@intermodalics.eu>