1: In the update method of the HUD window, check if $game_player.x and $game_player.y is between self.x, self.y, self.width, and self.height. After which, decrease the contents_opactiy like so:
self.contents_opacity -= 5 if self.contents_opacity > 160 # Decrease
self.contents_opacity += 5 if self.contents_opacity < 255 # Increase
2: Because you can't have a logic followed directly by an operator. You need to have the variale again, like so:
elsif $game_party.gold <= 21 and $game_party.gold <= 40
end