If you're the one activating the action node with a script you can just add to the if statement.
if IsButtonBeingPressed(3,0) and not PedIsValid(PedGetTargetPed(gPlayer)) then
PedSetActionNode(...)
end
IsButtonBeingPressed(3,0) I assume you know
not PedIsValid(PedGetTargetPed(gPlayer)) insures that there is no valid ped being targeted (meaning you're not locking onto anyone)
I don't know how you can do the part where you only want it to work in front of an enemy, you can use the ped's heading maybe but since you can't target your enemy, how do you know which ped to check the heading of?