Set aside a helper that checks opponent states when his parent is hit. Use a bunch of vars. Increment values in a different variable each time your parent is hit and the opponent state matches
For eg
type = varset
trigger1 = parent, movetype = H
trigger1 = parent, time = 1
trigger1 = var(0) = 0
v = 0
value = p2stateno
type = varadd
trigger1 = parent, movetype = H
trigger1 = parent, time = 1
trigger1 = p2stateno = var(0)
v = 1
value = 1
Use the helpers values to determine if an attack is being spammed and hitting. You can go smarter and detect whether you were hit crouching or what with more vars. Then use all of that to decide what countermeasures you want to take. Kamekaze does this sort of thing in his AI already, i've never had the patience for it.
If you want to get smarter you can hold all sorts in a single variable with bitwise shifting to determine what you were doing when you were attacked, whether you were in the air, attacking etc etc without using up multiple vars for a single move
I can't explain bitwise shifting, i know the logic, i've just never had a reason to use it. MFG has some threads on it though.