In order to check if they have the required gym badge, all you need to do is after they have beaten the gym leader and have been given the badge, turn on the switch "Defeated Gym X". Then for the person in front of the cave, just use a conditional branch to check ifthe switch is on. if it is then set up the event in the conditional branch. if not, put what you want to happen otherwise under the :Else.
switches are like light switches, they turn things on and off. you can turn them on to activate things, and off to stop them. you can use conditional branches to check to see if they are on or off. also, you can have different parts of the even only happen by setting the event condition to a certain switch. so only if the switch has been turned on, then the event will activate.
and for the scientist to 'notice' the player, just put events where they have to walk with the trigger event touch, and have that/those events move the player to the scientist, have the dialogue, etc etc and when it's over, just have one of the self switches turn on. self switches are nice because they don't use up standard switches. and for other reasons. but self switches are almost just like switches except they don't work globally. just for that event.