I think you could do either
IF
See(NearestEnemyOfType(OGRE))
THEN
Or
IF
See([ENEMY.0.OGRE])
Range(LastSeenBy(Myself),#)
THEN
With the range being optional if you need it. But in either case I can't make it universal for whatever favored enemy the player has chosen by accessing the HATEDRACE stat.
I've moved over to using STATS from STATE to improve scripting efficiency. For example, some spells:
// 2120 WIZARD_REFLECTED_IMAGE
// 2212 WIZARD_MIRROR_IMAGE
// 2607 WIZARD_MISLEAD
// 2703 WIZARD_PROJECT_IMAGE
// 2804 WIZARD_SIMULACRUM
Have a similar function. You can tell if one is already active:
!StateCheck(Myself,STATE_MIRRORIMAGE)
!StateCheck(Myself,STATE_INVISIBLE)
!StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
!CheckStat(Myself,1,PUPPETMASTERTYPE)
!CheckStat(Myself,2,PUPPETMASTERTYPE)
!CheckStat(Myself,3,PUPPETMASTERTYPE)
// 1 = Mislead, 2 = Project Image, 3 = Simulacrum
So if the player chooses to memorize multiple variations they won't overlap and will get used in sequence instead.
I wish I could do this for Protection from Evil and Petrification. There don't seem to be states or stats for them.