;================================
; CNS File for Freeza Z2 by Balthazar, Cybaster, Websta, KoopaKoot, JMorphman and XGargoyle
; State -2 & State -3 files
;================================

;==========================================================
[Statedef -2]
;==========================================================

[State -2, Explod]
type = Explod
triggerall = roundstate=2
triggerall = !NumExplod(7777)
triggerall = movetype!=H
trigger1 = power>=2000
anim = 2430
ID = 7777
pos = 0,-50
postype = p1
removetime = -1
bindtime = -1
sprpriority = 10
removeongethit = 1

[State 0, RemoveExplod]
type = RemoveExplod
triggerall = NumExplod(7777)
trigger1 = power<2000
trigger2 = movetype=H
trigger3 = roundstate!=2
id = 7777
;ignorehitpause =
;persistent =

[State -2, Switch directions after collapse]
type = Turn
trigger1 = Anim = 5950
trigger1 = AnimElem = 6

[State -2, PosAdd after collapse]
type = PosAdd
trigger1 = Anim = 5950
trigger1 = AnimElem = 6
x = -36

[State -2,Lifeset]
type = null;lifeset
trigger1 = life >= 100
value = 100
ignorehitpause = 1

[State -2];Reset Crouch C Teleport
type = varset
trigger1= numenemy
trigger1= (enemynear,movetype!=H)
trigger2= !numenemy
var(28) = 0

[State -2, AirGuard];Don't airguard if you've dashed or moving forward
type = AssertSpecial
triggerall = var(10) = 1 || vel x >= 0.1
trigger1 = 1
flag = NoAirGuard
IgnoreHitPause = 1

; FIX Reverse commands
; revised version by JNP and XG
[State -2, Explod]
type = Explod
triggerall = !NumExplod(21)
triggerall = Pos Y >=-50 && Vel Y >0
trigger1 = facing = enemy,facing
trigger2 = P2MoveType = H
trigger2 = P2BodyDist X <0
anim = 9999
removetime = -1
ID = 21

[State -2, Explod]
type = Explod
triggerall = !NumExplod(20)
triggerall = Pos Y >-80 && Vel Y >0
trigger1 = StateType = A
trigger1 = !NumExplod(21)
trigger1 = facing = enemy,facing
trigger2 = NumExplod(21)
trigger2 = facing = enemy,facing
trigger2 = StateType = S
trigger3 = P2MoveType = H
trigger3 = P2BodyDist X <0
trigger4 = StateNo = 52 || (StateNo=[1400,1450]) ;<-- NEW
trigger4 = facing = enemy,facing ;<-- NEW
anim = 9999
removetime = -1
ID = 20

[State -2, Explod]
type = RemoveExplod
triggerall = StateType = S
trigger1 = facing != enemy,facing
trigger2 = MoveType = H
trigger3 = !NumExplod(21) ;<-- CHANGED
trigger4 = Vel X != 0;JNP
ID = 20

[State -2, Explod]
type = RemoveExplod
trigger1 = time = 6
trigger1 = StateType != A
trigger2 = StateNo != 52    ;<-- NEW
trigger2 = StateNo!=[1400,1450]
trigger2 = facing != enemy,facing  ;<-- NEW
ID = 21

;===============================================================================
; ------- Damage Dampener --------
;===============================================================================

[State -2, Counter Flag]
type = VarSet
trigger1 = NumEnemy
fvar(8) = (EnemyNear, MoveType = A)
ignoreHitPause = 1

;Damage Dampener Variable (by POTS)
[State -2, Hit Count]
type = VarAdd
trigger1 = !IsHelper
trigger1 = MoveHit = 1
trigger1 = !HitPauseTime
trigger1 = !(HitDefAttr = SCA, AT)
fvar(13) = 1

[State -2, Hit Count Reset]
type = VarSet
trigger1 = NumEnemy && fvar(13)
trigger1 = (EnemyNear, MoveType != H) && (EnemyNear, StateNo != 5300)
fvar(13) = 0
ignoreHitPause = 1

[State -2, Dampener]
type = VarSet
trigger1 = 1
fvar(10) = ifElse(fvar(13) < 3, 24, ifElse(fvar(13) >= 23, 1, 24 - fvar(13))) / 24.0
ignoreHitPause = 1

[State -2, Dampener Limit]
type = VarSet
trigger1 = fvar(10) < 0
fvar(10) = 0
ignoreHitPause = 1

[State -2, Root Dampener]
type = VarSet
trigger1 = 1
fvar(11) = fvar(10) * ifElse(fvar(8), 1.2, 1)
ignoreHitPause = 1


;===============================================================================
; ------- VarSets --------
;===============================================================================

;Slashing Chop
[State -2, Focus Attack meter reset when no longer charging]
type = VarSet
trigger1 = (stateno !=[1300,1301]) && ((stateno=[5000,5099]) && prevstateno != 1300)
trigger2 = stateno = [100,105]
fv = 9
value = 0

[State -2, OTG]
type= varset
trigger1= movecontact=1 && p2statetype!=L
var(6) = 0
ignorehitpause = 1
[State -2, Free Juggling]
type = assertspecial
trigger1 = var(6)=1
flag = nojugglecheck
ignorehitpause = 1

[State varset];a.HK juggle limiter
type = VarSet
trigger1= numenemy
trigger1= (enemynear,movetype=H) && var(6)>0
var(7) = 1
[State -2, Reset var when the opponent recovers]
type=varset
trigger1= numenemy
trigger1= (enemynear,movetype!=H)
trigger2= !numenemy
var(7)=0

[State -2, KO snd]
type = varset
trigger1 = alive && var(8) > 0
trigger2 = !alive && var(8) < 2
var(8) = ifelse(alive, 0, var(8) + 1)
ignorehitpause = 1

[State -2, Air dash reset var when Freeza lands]
type=varset
trigger1= statetype!=A
var(10) = 0

;EX Death Wave hit Variable
[State -2, Reset var when the opponent recovers]
type = varset
trigger1 = numenemy
trigger1 = (enemynear,movetype!=H)
trigger2 = !numenemy
var(12) = 0

[State -2, OTG]
type= varset
trigger1= movecontact=1 && p2statetype!=L
var(15) = 0
ignorehitpause = 1
[State -2, Free Juggling]
type = assertspecial
trigger1 = var(15)=1
flag = nojugglecheck
ignorehitpause = 1

[State varset];a.EX DW juggle limiter
type = VarSet
trigger1= numenemy
trigger1= (enemynear,movetype=H) && var(15)>0
var(16) = 1
[State -2, Reset var when the opponent recovers]
type=varset
trigger1= numenemy
trigger1= (enemynear,movetype!=H)
trigger2= !numenemy
var(16)=0

[State -2, Super Jump reset var when Freeza lands]
type=varset
trigger1= statetype!=A
var(22) = 0

[State -2, Dancing Elbow juggle limiter]
type=varset
trigger1 = numenemy
trigger1 = (enemynear,movetype!=H)
trigger2 = !numenemy
var(36) = 0
[State -2, Dancing Elbow juggle limiter]
type= varset
trigger1= movecontact=1 && p2statetype!=L
var(37) = 0
ignorehitpause = 1

[State -2, Throws Allowed]
type = VarSet
triggerall = numenemy
trigger1 = EnemyNear, MoveType != H
trigger1 = EnemyNear, StateNo != 140
trigger1 = (EnemyNear, ctrl && EnemyNear, Time >= 1) || (EnemyNear, Time >= 8)
trigger2 = EnemyNear, MoveType = A
trigger3 = (EnemyNear, StateNo != [0,52]) && (EnemyNear, StateNo != [120,155]) && (EnemyNear, StateNo != [5000,5120])
trigger4 = var(20) || var(21) || var(22)
var(38) = 0

[State -2, Throws Disallowed]
type = VarSet
triggerAll = NumEnemy
trigger1 = EnemyNear, StateNo = [150,155]
trigger2 = (EnemyNear, StateNo = 51 || EnemyNear, StateNo = 140) && (EnemyNear, PrevStateNo = [150, 155])
trigger3 = EnemyNear, MoveType = H && EnemyNear, StateType != A && !var(20) && !var(21) && !var(22)
trigger4 = (EnemyNear, StateNo = [5020,5040]) && EnemyNear, HitFall = 0
trigger5 = EnemyNear, StateNo = 40 && EnemyNear, PrevStateNo != 52 && (EnemyNear, Anim != [0, 29])
var(38) = 1
ignorehitpause = 1

[State -2, Followup checker timer]
type = VarAdd
trigger1 = var(26)=[1,30]
var(26) = 1
ignorehitpause = 1

[State -2, Followup checker off]
type = VarSet
trigger1 = var(26)>30
var(26) = 0
ignorehitpause = 1
;persistent =



;===============================================================================
; ------- FX Position Fix --------
;===============================================================================

; Focus Smash FX Position Fix
[State 1000]
type = modifyexplod
trigger1 = numexplod(1302)
ID = 1302
pos = 0,0
postype = p1

; Focus Smash FX remove
[State 1000]
type = removeexplod
trigger1 = stateno != 1302
ID = 1302

; EX Headcharge FX Position Fix
[State 1000]
type = modifyexplod
trigger1 = numexplod(1451)
ID = 1451
pos = 0,0
postype = p1

; Head Charge FX Position Fix
[State 1000]
type = modifyexplod
trigger1 = numexplod(1505)
ID = 1505
pos = 0,0
postype = p1

; Death Charge FX Position Fix
[State 1000]
type = modifyexplod
trigger1 = numexplod(2681)
ID = 2681
pos = 20,-15
postype = p1


;===============================================================================
; ------- Miscelaneous Stuff --------
;===============================================================================

[State -2, KO snd Japan]
type = playsnd
triggerall = var(55)=0		;Voice=Japan
trigger1 = !alive && var(8) = 1
trigger1 = var(8) := 2
value = 11, 1 ;+ (stateno = 5950)
ignorehitpause = 1
volume = 300

[State -2, KO snd English]
type = playsnd
triggerall = var(55)=1		;Voice=English
trigger1 = !alive && var(8) = 1
trigger1 = var(8) := 2
value = 11, 10 + (stateno = 5950)
ignorehitpause = 1
volume = 300

[State -2, ctrlset]
type = CtrlSet
trigger1 = roundstate=0 || roundstate=1
value = 0

[State -2, juggle]
type = Varset
triggerall = numenemy
trigger1 = enemy,stateno = 5300
var(35) = 60
[State -2, juggle]
type = Varadd
triggerall = numenemy
trigger1 = (enemy,stateno != 5300) && (var(35) > 0)
var(35) = -1

[State -2, Free juggle when opponent is dizzy]
type = AssertSpecial
trigger1 = var(35) > 0
flag = nojugglecheck

[State 1001, stop power charging sound]
type = stopsnd
trigger1 = stateno != 900	;Power Charge
channel = 3
persistent = 0

[State -2, Explod];State 5052 Twist FX
type = playsnd
trigger1 = anim=5052 && !(gametime%10) && animelemtime(4)>=0
value = 5052,0
volume = -100

[State -2, Explod];State 5052 Twist FX
type = Explod
triggerall = NumExplod(20152) = 0
trigger1 = anim=5052 && animelemtime(4)=0
anim = 20152
pos = 0,-50
postype = P1
removetime = -1
;supermovetime = 99999
sprpriority = 3
id = 20152
bindtime = -1
ownpal = 1
ignorehitpause = 1
pausemovetime = -1

[state 17100, Flip KO FX]
type=explod
trigger1 = Anim=5937 && !numexplod(59370) && animelemtime(3)=0
anim = 5938
id = 5938
pos = 0,-50
postype = P1
sprpriority = 3
ownpal = 1
;supermovetime = -1
removetime = -1
persistent = 0
bindtime = -1
ignorehitpause = 1

[State 810, 2] ;P2 Hit Ground Spark (front)
type = Explod
triggerall = numtarget
trigger1 = target,StateNo=652 && !NumExplod(8400)
persistent = 0
ID = 8400
anim = 8400
postype = p2
pos = -4, -3
velocity = 0, 0
accel = 0, 0
removetime = -2
sprpriority = 3
ignorehitpause = 1
[State 810, 3] ;P2 Hit Ground Spark (back)
type = Explod
triggerall = numtarget;;
trigger1 = target,StateNo=652 && !NumExplod(8401)
persistent = 0
ID = 8401
anim = 8401
postype = p2
pos = -4, -3
velocity = 0, 0
accel = 0, 0
removetime = -2
sprpriority = -3
ignorehitpause = 1

[State -2, Hitting wall sound effect]
type = PlaySnd
triggerall = NumTarget
triggerall = target, StateNo = 652
trigger1 = target, Time = 1
value = 15000, 2
channel	= 20

[state 17100, Shocked FX]
type=explod
trigger1 = (Anim=7696 || anim=9010) && !numexplod(9011)
anim = 9011
id = 9011
pos = 0,0
postype = P1
sprpriority = -5
ownpal = 1
removetime = -1
persistent = 0
bindtime = -1
ignorehitpause = 1

[state 17100, Shocked FX]
type = removeexplod
trigger1 = (Anim != 7696 && anim != 9010) && numexplod(9011)
ID = 9011

; Test Statetype
[State -3, Wrong StateType]
type = Null ;superpause
trigger1 = pos y!=0 && statetype!=A && statetype!=L
time = 99999
ignorehitpause = 1

;===============================================================================
; ------- Chou Kamehameha Fatality - WTF --------
;===============================================================================

[State 10000, Explod]; White BG
type = Explod
;trigger1 = WinKO && MatchOver
triggerall = numenemy;;
triggerall = enemy,movetype=H
trigger1 = (enemy,stateno=5943 || enemy,stateno=5944 || enemy,stateno=5946) && NumExplod(5943)=0
anim = 2763
id = 5943
pos =  160,120
postype = left
sprpriority = 6
bindtime = -1
ownpal = 1
removetime = -2
pausemovetime = 999999
supermovetime = 999999
supermove = 1
scale = 1.50,1.50
ignorehitpause = 1
persistent = 0

[State 10000, Explod]; White BG front holes
type = Explod
triggerall = numenemy
;triggerall = WinKO && MatchOver
triggerall = enemy,movetype=H
trigger1 = enemy,stateno=5943 && NumExplod(5944)=0
trigger2 = enemy,stateno=2487 && NumExplod(5944)=0
anim = 5944
id = 5944
postype = p2
pos =  0, ceil(((enemy,const(size.head.pos.Y))+(enemy,const(size.mid.pos.Y)))/2)
sprpriority = 8
bindtime = -1
ownpal = 1
removetime = -2
pausemovetime = 999999
supermovetime = 999999
supermove = 1
scale = 1,1
ignorehitpause = 1
persistent = 0
facing = -1

[State 10000, Explod]; White BG front holes tall chars
type = Explod
triggerall = numenemy
;triggerall = WinKO && MatchOver
triggerall = enemy,movetype=H
trigger1 = enemy,stateno=5943 && NumExplod(59440)=0
trigger2 = enemy,stateno=2487 && NumExplod(59440)=0
anim = 5944
id = 59440
postype = p2
pos =  0, ceil(((enemy,const(size.head.pos.Y))+(enemy,const(size.mid.pos.Y)))/2)-170
sprpriority = 8
bindtime = -1
ownpal = 1
removetime = -2
pausemovetime = 999999
supermovetime = 999999
supermove = 1
scale = 1,1
ignorehitpause = 1
persistent = 0
facing = -1

[State 10000, Explod]; White BG front holes VERY tall chars
type = Explod
;triggerall = WinKO && MatchOver
triggerall = numenemy
triggerall = enemy,movetype=H
trigger1 = enemy,stateno=5943 && NumExplod(59441)=0
trigger2 = enemy,stateno=2487 && NumExplod(59441)=0
anim = 5944
id = 59441
postype = p2
pos =  0, ceil(((enemy,const(size.head.pos.Y))+(enemy,const(size.mid.pos.Y)))/2)+170
sprpriority = 8
bindtime = -1
ownpal = 1
removetime = -2
pausemovetime = 999999
supermovetime = 999999
supermove = 1
scale = 1,1
ignorehitpause = 1
persistent = 0
facing = -1

; White BG front holes - DIAGONAL FATALITY UP
[State -2, Explod Helper]
type = helper
;trigger1 = WinKO && MatchOver
triggerall = numenemy;;
triggerall = enemy,movetype=H
trigger1 = enemy,stateno=5944 && NumHelper(5945)=0
ID = 5945
postype = p2
pos =  0, ceil(((enemy,const(size.head.pos.Y))+(enemy,const(size.mid.pos.Y)))/2)
stateno = 5945
helpertype = normal
name = "white_fg"
pausemovetime = 999999
supermovetime = 999999
sprpriority = 8
ownpal = 1
keyctrl = 0
ignorehitpause = 1
persistent = 0
facing = 1

; White BG front holes - DIAGONAL FATALITY DOWN
[State -2, Explod Helper]
type = helper
;trigger1 = WinKO && MatchOver
triggerall = numenemy;;
triggerall = enemy,movetype=H
trigger1 = enemy,stateno=5946 && NumHelper(5947)=0
ID = 5947
postype = p2
pos =  0, ceil(((enemy,const(size.head.pos.Y))+(enemy,const(size.mid.pos.Y)))/2)
stateno = 5947
helpertype = normal
name = "white_fg"
pausemovetime = 999999
supermovetime = 999999
sprpriority = 8
ownpal = 1
keyctrl = 0
ignorehitpause = 1
persistent = 0
facing = 1

[State 10000, Explod]; White BG for Genkidama
type = Explod
;trigger1 = WinKO && MatchOver
triggerall = numenemy
triggerall = enemy,movetype=H
trigger1 = (enemy,stateno=2990) && NumExplod(2995)=0
anim = 2995
id = 2995
pos =  160,120
postype = left
sprpriority = 6
bindtime = -1
ownpal = 1
removetime = -2
pausemovetime = 999999
supermovetime = 999999
supermove = 1
scale = 1.50,1.50
ignorehitpause = 1
persistent = 0

; White BG front holes - GENKIDAMA
[State -2, Explod Helper]
type = helper
triggerall = numenemy
triggerall = enemy,movetype=H
trigger1 = enemy,stateno=2990 && NumHelper(2991)=0
ID = 2991
stateno = 2991
postype = p2
pos =  0, ceil(((enemy,const(size.head.pos.Y))+(enemy,const(size.mid.pos.Y)))/2)
helpertype = normal
name = "white_fg"
pausemovetime = 999999
supermovetime = 999999
sprpriority = 8
ownpal = 1
keyctrl = 0
ignorehitpause = 1
persistent = 0
facing = -1

;===============================================================================
; ------- Compatibility with V.Akiha by Kohaku --------
;===============================================================================

[State -2, LifeAdd]
type = LifeAdd
triggerall = NumEnemy
triggerall = Enemy,AuthorName = "Kohaku" && Enemy,Name = "VAkiha_K"
trigger1 = Enemy,Var(30) = 1
value = -5
kill = 0

[State -2, PowerAdd]
type = PowerAdd
triggerall = NumEnemy
triggerall = Enemy,AuthorName = "Kohaku" && Enemy,Name = "VAkiha_K"
trigger1 = Enemy,Var(30) = 1
value = -26

;===============================================================================
; ------- Compatibility with Warachia by Rajaaboy --------
;===============================================================================

[state -2,RajaaBoy:_Warachia]
type = lifeadd
trigger1 = numenemy
trigger1 = enemy,authorname="RajaaBoy"
trigger1 = enemy,name="RajaaWarachia"
trigger1 = enemy,var(32)=1||enemy,var(33)=1||enemy,var(34)=1
value = (-14*enemy,var(32))+(-21*enemy,var(33))+(-28*enemy,var(34))
kill = 0
ignorehitpause = 1

[state -2,RajaaBoy:_Warachia]
type = poweradd
trigger1 = numenemy
trigger1 = enemy,authorname="RajaaBoy"
trigger1 = enemy,name="RajaaWarachia"
trigger1 = enemy,var(32)=1||enemy,var(33)=1||enemy,var(34)=1
value = 10
ignorehitpause = 1

;===============================================================================
; ------- Super Background Helper Triggers --------
;===============================================================================

; SUPER BG HELPER
[State -2, Hyper Kill bg]
type = helper
triggerall = winKO && !NumHelper(19875)
triggerall = var(13) < 2
trigger1 = NumHelper(2015)								;Death Beam
trigger1 = helper(2015),movecontact
trigger2 = NumHelper(2115)								;Death Beam Lv2
trigger2 = helper(2115),movecontact
trigger3 = NumHelper(2205)								;Death Ball 25%/50%/75%
trigger3 = helper(2205),movecontact
trigger4 = NumHelper(2310)								;Death Saw
trigger4 = helper(2310),movecontact
trigger5 = NumHelper(2210)								;Death Ball Sinking
trigger5 = helper(2210),movecontact
trigger6 = stateno=2500 && movecontact					;Tail Press Nightmare
trigger7 = stateno=2681 && movecontact					;Death Charge
trigger8 = NumHelper(2810)								;Death Beam Barrage (finisher 1)
trigger8 = helper(2810),movecontact
trigger9 = stateno=2902 && roundno=1					;Wave Cut (finisher 2, no fatality)
ID = 19875
pos = 20-20*(var(13)=0),-250+250*(var(13)=0)
postype = left
stateno = 19875 + 25*var(13)
helpertype = normal
name = "superbackground"
pausemovetime = 999999
supermovetime = 999999
sprpriority = -5
ownpal = 1
keyctrl = 0
ignorehitpause = 1

; SUPER BG HELPER - Super DBZ Physic
[State -2, Hyper Kill bg]
type = helper
triggerall = winKO && !NumHelper(19875)
triggerall = var(13) = 2
trigger1 = stateno=2500 && movecontact					;Tail Press Nightmare
trigger2 = stateno=2681 && movecontact					;Death Charge
ID = 19875
pos = 0,0
postype = left
stateno = 19885
helpertype = normal
name = "superbackground"
pausemovetime = 999999
supermovetime = 999999
sprpriority = -5
ownpal = 1
keyctrl = 0
ignorehitpause = 1
persistent = 0

; SUPER BG HELPER - Super DBZ Ki
[State -2, Hyper Kill bg]
type = helper
triggerall = winKO && !NumHelper(19875)
triggerall = var(13) = 2
trigger1 = NumHelper(2015)								;Death Beam
trigger1 = helper(2015),movecontact
trigger2 = NumHelper(2115)								;Death Beam Lv2
trigger2 = helper(2115),movecontact
trigger3 = NumHelper(2205)								;Death Ball 25%/50%/75%
trigger3 = helper(2205),movecontact
trigger4 = NumHelper(2310)								;Death Saw
trigger4 = helper(2310),movecontact
trigger5 = NumHelper(2210)								;Death Ball Sinking
trigger5 = helper(2210),movecontact
trigger6 = NumHelper(2810)								;Death Beam Barrage (Fatality 1)
trigger6 = helper(2810),movecontact
trigger7 = stateno=2902 && roundno=1					;Wave Cut (finisher 2, no fatality)
ID = 19875
pos =  0,0
postype = left
stateno = 19892
helpertype = normal
name = "superbackground"
pausemovetime = 999999
supermovetime = 999999
sprpriority = -5
ownpal = 1
keyctrl = 0
ignorehitpause = 1
persistent = 0

;===============================================================================
; ------- Display To Clipboard --------
;===============================================================================

[State -2, DisplayToClipboard]
type = DisplayToClipboard
trigger1 = (authorname="Team Z2")
text = "PrevStateno=%d, AI=%d, pos=%f, v4=%d, damage=%d, v5=%d\n"
params = PrevStateNo, AIlevel, pos X, var(4), gethitvar(damage), var(5) ;-40-((time-120.0)*(160.0-40)/32.0)
ignorehitpause = 1

[State -2, Debug]
type = appendtoclipboard
trigger1 = (authorname="Team Z2")
text = "by Balthazar, Cybaster, Websta, KoopaKoot, JMorphman and XGargoyle - http://www.mugenguild.com/cybaster"
ignorehitpause = 1

[State -2, VS Thieves]
type = DisplayToClipboard
trigger1 = (authorname="Team Z2") = 0
text = "This character was created by Balthazar, Cybaster, Websta, KoopaKoot, JMorphman and XGargoyle. Don't even try to deny\nit thief! Original version available at http://www.mugenguild.com/cybaster\n"
ignorehitpause = 1

;===============================================================================
; ------- Challenge/Trial Mode Stuff --------
;===============================================================================
; Dummy controls and ChangeStates

[State no control]
type = VarSet
triggerall = NumEnemy
triggerall = enemy,name = "Goku Z2" && enemy,authorname = "Team Z2"
triggerall = teamside = 2
trigger1 = enemy,NumHelper(20000) && roundstate=2
var(59) = 1

[State recover]
type = ChangeState
triggerall = NumEnemy
triggerall = enemy,name = "Goku Z2" && enemy,authorname = "Team Z2"
triggerall = teamside = 2
trigger1 = enemy,NumHelper(20000)
trigger1 = Vel Y > -1
trigger1 = CanRecover && stateno=5050
value = ifelse((pos Y>=-20), 5200, 5210)

[State kicking]
type = ChangeState
triggerall = NumEnemy
triggerall = enemy,name = "Goku Z2" && enemy,authorname = "Team Z2"
triggerall = teamside = 2
trigger1 = enemy,NumHelper(20000)
trigger1 = enemy,var(51)=1
trigger1 = (stateno!=250) && ctrl && (statetype=S)
value = 250

[State jumping]
type = ChangeState
triggerall = NumEnemy
triggerall = enemy,name = "Goku Z2" && enemy,authorname = "Team Z2"
triggerall = teamside = 2
trigger1 = enemy,NumHelper(20000)
trigger1 = enemy,var(51)>=2
trigger1 = (stateno!=40) && ctrl && (statetype != A)
value = 40

[State kicking in air]
type = ChangeState
triggerall = NumEnemy
triggerall = enemy,name = "Goku Z2" && enemy,authorname = "Team Z2"
triggerall = teamside = 2
trigger1 = enemy,NumHelper(20000)
trigger1 = enemy,var(51)=3
trigger1 = (stateno!=650) && ctrl && (statetype=A)
value = 650


;=======================================================================
; External coding for Hyper Pause Fixes (Fighting SyN'S Characters only)
;=======================================================================
[State -2, Camera focus on player for Hyper Pause]
type = ScreenBound
triggerall = NumEnemy
triggerall = enemynear,authorname = "ImmortaL -SyN-"
trigger1 = enemynear,numhelper(4999)
value = 1

;[State -2] ;DEAD CAMERA IGNORE
;type = ScreenBound
;trigger1 = (life <= 0) && (roundstate >= 3)
;value = 0
;movecamera = 0,0
;ignorehitpause = 1


;===============================================================================
; ------- Sadism Mode Gauge --------
;===============================================================================

; SADISM MODE GAUGE P1
[State -2, Sadism Gauge]
type = helper
triggerall = !NumHelper(2650) && teamside = 1
trigger1 =  1 ;var(50) > 0
ID = 2650
stateno = 2650
pos = 20, 0
postype = left
helpertype = normal
name = "sadism1"
pausemovetime = 999999
supermovetime = 999999
sprpriority = 7
ownpal = 1
keyctrl = 0
ignorehitpause = 1
size.xscale = 0.5
size.yscale = 0.5

; SADISM MODE GAUGE P2
[State -2, sadism Gauge]
type = helper
triggerall = !NumHelper(2660) && teamside = 2
trigger1 = 1 ;var(50) > 0
ID = 2660
stateno = 2660
pos = 20, 0
postype = left
helpertype = normal
name = "sadism2"
pausemovetime = 999999
supermovetime = 999999
sprpriority = 7
ownpal = 1
keyctrl = 0
ignorehitpause = 1
size.xscale = 0.5
size.yscale = 0.5

[State -2, sadism Gauge] ;don't go below 0
type = varset
trigger1 = var(50)<1
var(50) = 1
ignorehitpause = 1

; SADISM MODE GAUGE - Fill it !!!
[State -2, sadism Gauge] ;fill
type = varadd
triggerall = numenemy
trigger1 = var(50)>0 && var(50)<900
var(50) = ifelse (var(50) + ceil(1.25*(enemynear,gethitvar(damage))) > 900, 900-var(50), ceil(1.25*(enemynear,gethitvar(damage))) )
ignorehitpause = 1

[State -2, sadism Gauge] ;buffer
type = varset
triggerall = movetype=H && !time
trigger1 = var(50)>0 && var(50)<900
var(51) = ifelse (var(50) + ceil(1.25*(gethitvar(damage))) > 900, -1*(900-var(50)), -ceil(1.25*(gethitvar(damage))) )
ignorehitpause = 1

[State -2, sadism Gauge] ;deplete
type = varset
triggerall = movetype=H && !time
trigger1 = var(50)>0 && var(50)<900
var(50) = ifelse ((var(50)+var(51)<=0),var(50)-var(50)+1,(var(50)+var(51)))
ignorehitpause = 1




;===============================================================================
; ------- Remove various explods --------
;===============================================================================

[state -2, remove Flip KO FX]
type = removeexplod
trigger1 = anim!=5937
id = 5938
[state -2, remove Twist KO FX]
type = removeexplod
trigger1 = anim!=5052
id = 20152

[State 1902, Remove power charge mouth]
type = RemoveExplod
trigger1 = stateno != [900,901]
ID = 902

[State 1902, Remove power charge front]
type = RemoveExplod
trigger1 = stateno != [900,901]
ID = 907

[state -2, remove charge dust]
type = removeexplod
trigger1 = stateno != 900		;Power Charge
trigger1 = stateno != 901		;Power Charge
trigger1 = stateno != 2300		;Sonic Rush
trigger1 = stateno != 192		;HD Intro
trigger1 = stateno != 193		;SSJ transform Intro
trigger1 = stateno != 188
trigger1 = stateno != 183
trigger1 = stateno != 2745		;Justice mode activation
id = 908

[state -2, remove EX Headcharge FX]
type = removeexplod
trigger1 = stateno != 1450 && anim!=1400
id = 1451

[State 1902, Death Charge energy FX]
type = RemoveExplod
trigger1 = anim != 2680
ID = 2682

[state -2, remove EX Headcharge FX]
type = removeexplod
trigger1 = stateno != [1550,1565]
id = 1505

;===============================================================================
; COUNTER HIT (Taken from Vans, who based his on Sander's Method)
;===============================================================================

[State -2, VarSet];Checks if opponent is in attack state
type = VarSet
triggerall = numenemy
trigger1 = enemy, movetype = A
var(56) = 1
ignorehitpause = 1

[State -2, VarSet];This resets the condition if counter not succesful and succesful
type = VarSet
triggerall = numenemy
trigger1 = enemy, movetype = I || var(57) >= 1  ;Enemy is Idle | Counter was Succesful
trigger2 = var(57) > 10 && enemy, movetype = H  ;10 ticks passed & enemy is on gethit state
var(56) = 0
ignorehitpause = 1

[State -2, VarSet];Counter Hit Succesful
type = VarSet
trigger1 = var(56) = 1 && movehit ;Counter Check Ok, Move Hit Succesfully.
trigger1 = stateno != [190,199] ;Does not activate during intros.
trigger1 = stateno != [800,825] ;Does not activate during throws.
trigger1 = stateno != [950,951] ;Don't activate during throws.
trigger2 = var(56) = 1 && projhit = 1  ;Counter Check Ok, Projectile Hit Succesfully.
var(57) = 1
ignorehitpause = 1

[State -2, VarAdd];Counter Hit Timer
type = VarAdd
trigger1 = var(57) >= 1 ;Counter was succesful
var(57) = 1
ignorehitpause = 1

[State -2, VarSet];Counter Hit Reset
type = VarSet
trigger1 = var(57) >= 22 && movehit ;Reset if 22 ticks passed and move hit
trigger2 = p2movetype != H ;Reset if P2 is no longer in gethit state
trigger3 = movetype = H ;Reset if P1 is getting hit
trigger4 = var(57) >= 22 && projhit = 1 ;Reset if 22 ticks passed and projectile hit
var(57) = 0
ignorehitpause = 1

[State -2, AssertSpecial];This will award free juggles for Counter Hit.
type = AssertSpecial
trigger1 = var(57) > 0
flag = nojugglecheck

[State -2, EnvColor];This will produce a flash a la KOF2K2
type = EnvColor
triggerall = numenemy
triggerall = stateno != [190,199] ;Does not activate during intros.
triggerall = stateno != [800,825] ;Does not activate during throws.
triggerall = stateno != [950,951] ;Don't activate during throws.
triggerall = enemy, movetype = h ;Enemy was indeed HIT, otherwise this'd be retarded.
trigger1 = var(56) = 1 && movehit  ;Move hit, Ok
trigger2 = var(56) = 1 && projhit = 1 ;Projectile hit, Ok
value = 255,255,255
time = 1
under = 1
ignorehitpause = 1
persistent = 0

[State -2, Explod];Counter Explod for P1 Side.
type = Explod
triggerall = numenemy
triggerall = var(56) = 1 && numexplod(13000) = 0 && teamside = 1 ;Counter Ok, Explod has not played, P1 Side
triggerall = enemy, movetype = h ;Enemy was indeed HIT, otherwise this'd be retarded.
triggerall = stateno != [800,825] ;Does not activate during throws.
triggerall = stateno != [950,951] ;Don't activate during throws.
trigger1 = movehit ;Move hits
trigger2 = projhit = 1 ;Projectile Hits
anim = 13000
pos = 10,100
postype = left  ;p2,front,back,left,right
removetime = -2
supermove = 1
;scale = 0.5,0.5
sprpriority = 0
id = 13000
bindtime = -1
ontop = 1
ownpal = 1
ignorehitpause = 1
pausemovetime = -1

[State -2, Explod];Counter Explod for P2 Side.
type = Explod
triggerall = numenemy
triggerall = var(56) = 1 && numexplod(13000) = 0 && teamside = 2 ;Counter Ok, Explod has not played, P2 Side
triggerall = enemy, movetype = h ;Enemy was indeed HIT, otherwise this'd be retarded.
triggerall = stateno != [800,825] ;Does not activate during throws.
triggerall = stateno != [950,951] ;Don't activate during throws.
trigger1 = movehit ;Move hits
trigger2 = projhit = 1 ;Projectile Hits
anim = 13001
pos = -82, 100 ;-1,100
postype = right  ;p2,front,back,left,right
removetime = -2
supermove = 1
;scale = 0.5,0.5
sprpriority = 0
id = 13000
bindtime = -1
ontop = 1
ownpal = 1
ignorehitpause = 1
pausemovetime = -1

;===============================================================================
; FIRST ATTACK NOTIFICATION
;===============================================================================

[State -2, First Attack]
type = VarSet
triggerall = Var(27) = 0
triggerall = RoundState = 2
trigger1 = p2stateno = [5000,5199]
trigger1 = p2movetype = H
v = 27
value = 1
ignorehitpause = 1

[State -2, First Attack - in F1 is pressed]
type = VarSet
triggerall = Var(27) = 0
triggerall = RoundState = [0,1]
trigger1 = p2stateno = [5000,5199]
trigger1 = p2movetype = H
v = 27
value = 2
ignorehitpause = 1

[State -2, Explod];P1 Side.
type = Explod
trigger1 = var(27)= 1 && numexplod(13100)=0 && teamside = 1
anim = 13100
pos = 10,ifelse(numexplod(13000),80,100)
postype = left  ;p2,front,back,left,right
removetime = -2
supermove = 1
;scale = 0.5,0.5
sprpriority = 0
id = 13100
bindtime = -1
ontop = 1
ownpal = 1
ignorehitpause = 1
pausemovetime = -1
persistent = 0

[State -2, Explod];P2 Side.
type = Explod
trigger1 = var(27)= 1 && numexplod(13100)=0 && teamside = 2
anim = 13101
pos = -117,ifelse(numexplod(13000),80,100) ;-48,ifelse(numexplod(13000),80,100)
postype = right  ;p2,front,back,left,right
removetime = -2
supermove = 1
;scale = 0.5,0.5
sprpriority = 0
id = 13100
bindtime = -1
ontop = 1
ownpal = 1
ignorehitpause = 1
pausemovetime = -1
persistent = 0

[State -2, Powaa !!!]
type = PowerAdd
trigger1 = Var(27) = 1
value = 200
persistent = 0

[State -2, First Attack]
type = VarSet
trigger1 = Var(27) = 1
trigger2 = movetype = H && Var(27) = 0 && stateno != [150,159]
v = 27
value = 2

;==========================================================
[Statedef -3]
;==========================================================

; AI Combo Breaker
[State -1, AI Combo Breaker]
type = ChangeState
triggerall = roundstate = 2
triggerall = power >= 500
triggerall = numenemy
triggerall = ctrl=0
triggerall = gethitvar(hitcount)>=6
triggerall = random<(50*gethitvar(hitcount)*((AILevel+1)**2/64.0))
trigger1 = movetype=H && stateno!=[120,155]
trigger2 = stateno=[5000,5999]
value = 1750
ignorehitpause= 1

[State -3, Prevent Underground Juggles]
type= targetbind
trigger1= movehit=1
trigger1= numtarget=1 && numenemy
trigger1= (target,time<=1) && (target,ID=enemynear,ID); this is just to prevent Simul issues as usual
trigger1= !(target,hitshakeover) && (target, hitfall) && (target, pos y>0)
pos= ceil(p2dist x), ceil(-pos y); keeps P2 at the same horizontal distance, but resets his Y position
ignorehitpause= 1

;This controller plays a sound everytime the player lands from a jump, or from a back-dash.
[State -3, Landing Sound]
type = PlaySnd
triggerall = Time = 1
trigger1 = stateno = 52 ;Jump land
trigger2 = stateno = 106 && prevstateno != 107 ;back dash land and no flik flak
trigger3 = stateno=0 && prevstateno=5120
trigger4 = stateno = 5201
value = 40, 0

[state 52, Land FX]
type = helper
triggerall = Time = 1
trigger1 = stateno = 52
trigger2 = stateno = 106 && prevstateno != 107
trigger3 = stateno = 5201
name = "LandFX"
helpertype = normal
stateno = 17100
id = 17100
postype = P1
ownpal = 1
keyctrl = 0
supermovetime = 99999
pausemovetime = 99999

[State 0, ]
type = Helper
triggerall = !numhelper(52100)
trigger1 = stateno = 5201
helpertype = normal
name = "recoverpulser"
ID = 52100
stateno = 52100
ownpal = 1
supermovetime = 99999
pausemovetime = 99999

;--------------------------------------

[State -3, GetHitSnd Light]
type = playsnd
triggerall = var(55)=0		;Voice=Japan
triggerall = alive && (time = 1)
triggerall = stateno=5000||stateno=5010||stateno=5020||stateno=5070||stateno=5080
trigger1 = numenemy > 0
trigger1 = enemynear,hitdefattr = SCA,SA,HA
trigger2 = gethitvar(animtype)=0 && random<250
value = s5000,random%3
channel = 0
ignorehitpause = 1
persistent = 0
volume = 200

[State -3, GetHitSnd Medium]
type = playsnd
triggerall = var(55)=0		;Voice=Japan
triggerall = alive && (time = 1)
triggerall = stateno=5000||stateno=5010||stateno=5020||stateno=5070||stateno=5080
trigger1 = numenemy > 0
trigger1 = enemynear,hitdefattr = SCA,SA,HA
trigger2 = gethitvar(animtype)=1 && random<375
value = s5000,10+random%5
channel = 0
ignorehitpause = 1
persistent = 0
volume = 200

[State -3, GetHitSnd Hard]
type = playsnd
triggerall = var(55)=0		;Voice=Japan
triggerall = alive && (time = 1)
triggerall = stateno=5000||stateno=5010||stateno=5020||stateno=5070||stateno=5080
trigger1 = numenemy > 0
trigger1 = enemynear,hitdefattr = SCA,SA,HA
trigger2 = gethitvar(animtype)>=2 && random<500
value = s5000,20+random%4
channel = 0
ignorehitpause = 1
persistent = 0
volume = 200
;--------------------------------------
[State -3, GetHitSnd Light]
type = playsnd
triggerall = var(55)=1		;Voice=English Shockdingo
triggerall = alive && (time = 1)
triggerall = stateno=5000||stateno=5010||stateno=5020||stateno=5070||stateno=5080
trigger1 = numenemy > 0
trigger1 = enemynear,hitdefattr = SCA,SA,HA
trigger2 = gethitvar(animtype)=0 && random<250
value = s5000,100+random%5
channel = 0
ignorehitpause = 1
persistent = 0
volume = 200

[State -3, GetHitSnd Medium]
type = playsnd
triggerall = var(55)=1		;Voice=English Shockdingo
triggerall = alive && (time = 1)
triggerall = stateno=5000||stateno=5010||stateno=5020||stateno=5070||stateno=5080
trigger1 = numenemy > 0
trigger1 = enemynear,hitdefattr = SCA,SA,HA
trigger2 = gethitvar(animtype)=1 && random<375
value = s5000,110+random%8
channel = 0
ignorehitpause = 1
persistent = 0
volume = 200

[State -3, GetHitSnd Hard]
type = playsnd
triggerall = var(55)=1		;Voice=English Shockdingo
triggerall = alive && (time = 1)
triggerall = stateno=5000||stateno=5010||stateno=5020||stateno=5070||stateno=5080
trigger1 = numenemy > 0
trigger1 = enemynear,hitdefattr = SCA,SA,HA
trigger2 = gethitvar(animtype)>=2 && random<500
value = s5000,120+random%10
channel = 0
ignorehitpause = 1
persistent = 0
volume = 200
;--------------------------------------

[state -3, remove afterimage]
type = afterimagetime
trigger1 = Movetype = H
trigger2 = stateno != [10230,10233]	;Super Jump
trigger2 = stateno != [110,115]  	;air dash
trigger2 = stateno != 50
trigger2 = stateno != 1150 			;EX Death Wave
trigger2 = stateno != 1250 			;EX Air Death Wave
trigger2 = stateno != 1450 			;EX Air Headbutt
trigger2 = stateno != [1550,1570]	;EX Ground Headbutt
trigger2 = stateno != 1650	;EX Dancing Elbow
trigger2 = stateno != 2500	;Tail Press Nightmare
time = 0

[State -3, Prevent Crossup]
type = width
triggerall = numenemy
trigger1 = movetype != H
trigger1 = facing != enemynear, facing
edge = 4, 0
ignorehitpause = 1

[State -3, No walk during turning animation]
type = VelSet
trigger1 = anim=5
x = 0

[State -3, stopsnd if skip intro]
type = stopsnd
triggerall = stateno=0
trigger1 = prevstateno=[191,194]
trigger2 = prevstateno=[19400,19450]
trigger3 = prevstateno = [711,715]
channel = 8

[State -3, stopsnd if skip Transform intro]
type = stopsnd
triggerall = stateno=0 && !time
trigger1 = prevstateno=194
trigger2 = prevstateno=[19400,19450]
trigger3 = prevstateno = [711,715]
channel = -1

[State -3, stopsnd if not power charging]
type = stopsnd
trigger1 = stateno!=[900,901]
channel = 4

;===============================================================================
; Slashing Chop / Saving Strike code (Part B)
;===============================================================================
[state -3, animelem set frame 1]
type = varset
trigger1 = stateno = 1300 && time = 1
var(23) = 1
 
[state -3, animelem set frame 2]
type = varset
trigger1 = stateno = 1300 && animelem = 2
var(23) = 2

[state -3, animelem set frame 3]
type = varset
trigger1 = stateno = 1300 && animelem = 3
var(23) = 3
 
[State -3, Change to second state]
type = HitOverride
trigger1 = stateno = 1300
attr = SCA,NA,SA,HA,NP,SP,HP
slot = 0
stateno = 1301
time = 1
forceair = 0
ignorehitpause = 1
persistent = 1
 
[state -3, varset for first state]
type = varset
trigger1 = stateno = 1300
var(20) = 1
 
[state -3, varset for second state]
type = varset
trigger1 = stateno = 1301
var(20) = 0

[State -3, health removal in second state]
type = LifeAdd
trigger1 = stateno = 1301
value = -(gethitvar(damage))
kill = 1

;===============================================================================
; ------- Cheap K.O. system By Warusaki3 & POTS --------
;===============================================================================
;[State -2, 3]
;type = ChangeState
;trigger1 = !Alive
;trigger1 = PrevStateNo = 130 || PrevStateNo = 131 || PrevStateNo = [150,153]
;trigger1 = Stateno = [5000,5050]
;value = 5950

[State -3, Cheap KO]
type = changestate
trigger1 = !alive && (stateno = [5000, 5010])
trigger1 = (prevstateno = [130, 131]) || (prevstateno = [140, 141]) || (prevstateno = [150, 153])
value = 5950
ignorehitpause = 1

[State -2,KO]
type = Varset
triggerall = StateNo = [120,159]
trigger1 = StateType = S
ignorehitpause = 1
fvar(1) = 0

[State -2,KO]
type = Varset
triggerall = StateNo = [120,159]
trigger1 = StateType = C
ignorehitpause = 1
fvar(1) = 1

[State -2,KO]
type = Varset
triggerall = StateNo = [120,159]
trigger1 = StateType = A
ignorehitpause = 1
fvar(1) = 2
