==============================
Move Interrupt Bonus (Counter)
==============================
Created by SorrowEdge

;---------------------------------------------------------------------------
Move Interrupt -- SNK came up with this great concept, and it has been copied 
in some form or another in  almost every fighting game thereafter. 
;---------------------------------------------------------------------------
First, some prerequistes:
Write down the state numbers for any attack that puts 
p2 in a custom state.

Now, put this in Statedef -2. It's a hack-around for 
p2prevmovetype(the trigger doesn't exist).

[state -2, A]
type = VarSet
trigger1 = var(2) = 0
ignorehitpause = 1
var(13) = ifelse(p2movetype = A, 1, 0)

[state -2, B]
type = VarSet
trigger1 = var(2) = 1
ignorehitpause = 1
var(1) = ifelse(p2movetype = A, 1, 0)

[state -2, C]
type = VarSet
trigger1 = 1
var(2) = ifelse(var(2) = 1, 0, 1)
ignorehitpause = 1

Then, in state -3(remember to put the state nums you wrote down as exclusions here):

[state -3, TargetState]
type = TargetState
trigger1 = (numtarget > 0) && (ifelse(var(2), var(0), var(1))) && (target, stateno != 9000)
;trigger1 = stateno != 1000
;trigger1 = stateno != [4020, 4045] 
;trigger1 = stateno != [500,510] ;hitdefattr != SCA, NT, ST, HT
value = 9000
ignorehitpause = 1

What it does is it puts p2 in a custom state if p2's previous movetype was attack, 
unless p2 is already in the custom state, or p1 is throwing p2. If anyone can 
improve the throw detection here, I'd greatly appreciate it(hitdefattr doesn't 
work for some reason).

Finally, the custom state itself:

;-----------------------
;Counter!
[Statedef 9000]
movetype = H

[State 9000, LifeAdd]
type = LifeAdd
trigger1 = time = 0
value = - floor(gethitvar(damage) / 2)
ignorehitpause = 1
absolute = 0

[State 9000, Envcolor]
type = Envcolor
trigger1 = time = 0
ignorehitpause = 1
time = 1
value = 255,0,0

[state 9000, 5]
type = SelfState
trigger1 = time = 0
ignorehitpause = 1
value = prevstateno

Now, for customization. If you want to give an extra hit or let p2 stagger longer like in 
KOF or that pause thingy in SFA3, just add some custom states and send p2 there in the 
above state. For displaying the words "counter" or other effects, I guess you'll need a 
var to trigger it.