[12349] Refactor code to check for scripted events

(based on commit [12246] - f4b7631)