I made a stun system a while ago for my game, it didn't have a bar but is very easy to add it after you get the system working.
For my game, I implemented the stun in a helper, and in the player, which means, this is for you to get stunned, not to make the opponent get stunned. I think it is easier this way. If you want to use this in the character rather than in a helper, just remove all Root redirects, and place everything in -2.
I used 3 vars here, but you can use only 2, the decider is optional.
; var(46):= Stun Points Decider
; var(47):= Stun Points
; var(48):= Stun Timer
This goes in the character's statedef -2:
[State 0, ChangeState] ;Stun/Dizzy
type = ChangeState
trigger1 = (StateNo != [1115310,1115316]) && StateNo != 1115300
trigger1 = NumHelper(696969) && MoveType = H && !GetHitVar(Guarded)
trigger1 = Helper(696969), var(47) >= 75
trigger1 = Alive
value = 1115310
ignorehitpause = 1
Then you need to create the stun states and animations.
I'll post mine, is a bit long, so I'll hide it in spoilers.
Spoiler, click to toggle visibilty
;========================<STUNNED>========================
;----- Air get-hit (Shaking) -----
[Statedef 1115310]
type = A
movetype= H
physics = N
velset = 0, 0
[State 1115310, NHB]
type = null;nothitby
trigger1 = 1
value = SCA
[State 1115310]
type = HitFallSet
trigger1 = 1
value = 1
ignorehitpause = 1
[State 1115310, Anim]
type = ChangeAnim
trigger1 = Time = 0
value = 5030
[State 1115310, Anim]
type = ChangeAnim
trigger1 = Time > 0
value = anim
[State 1115310, Shake]
type = offset
trigger1 = 1
x = ifelse((gametime % 2), -1, 1)
[State 1115310, 5]
type = ChangeState
trigger1 = HitShakeOver
value = 1115311
;----- Knocked away -----
[Statedef 1115311]
type = A
physics = N
movetype = H
ctrl = 0
[State 1115311, NHB]
type = null;nothitby
trigger1 = 1
value = sca
[State 1115311, Accel]
type = veladd
trigger1 = Time > 0
x = ifelse(p2dist x < 0, -0.045, 0.045)
y = 0.58;yaccel
[State 1115311, Vel]
type = velset
trigger1 = !time
x = ifelse(p2dist x < 0, 4, -4)
y = -8.25
[State 1115311, Anim]
type = changeanim
trigger1 = anim != [5000, 5199]
trigger1 = selfanimexist(5030)
value = 5030
[State 1115311, Anim]
type = changeanim
trigger1 = !animtime
trigger1 = anim < 5035
trigger1 = selfanimexist(5035)
value = 5035
[State 1115311, Anim]
type = changeanim
trigger1 = !animtime
trigger1 = anim = 5035
value = 5050
[State 1115311, End]
type = changestate
trigger1 = vel y > 0
trigger1 = pos y >= ifelse(anim = 5052, 0, const(movement.air.gethit.groundlevel))
value = 1115313
;----- Thrown -----
[Statedef 1115312]
type = A
movetype= H
physics = N
ctrl = 0
[State 1115312, NHB]
type = null;nothitby
trigger1 = 1
value = SCA
[State 1115312, Accel]
type = VelAdd
trigger1 = Time > 0
x = ifelse(p2dist x < 0, -0.045, 0.045)
y = 0.58;yaccel
[State 1115312, Anim]
type = changeanim
trigger1 = !animtime
trigger1 = selfanimexist(5035)
trigger1 = anim = [5000, 5030]
value = 5035
[State 1115312, Anim]
type = changeanim
triggerall = !animtime
trigger1 = anim = 5035
trigger2 = anim < 5050
trigger2 = !selfanimexist(5035)
value = 5050
[State 1115312, Up Type]
type = changeanim
trigger1 = anim = [5050,5059]
trigger1 = vel y > 0
trigger1 = selfanimexist(anim + 10)
value = anim + 10
persistent = 0
[State 1115312, End]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= Const(movement.air.gethit.groundlevel)
value = 1115313
;----- hit ground from fall -----
[Statedef 1115313]
type = L
movetype= H
physics = N
[State 1115313, NHB]
type = nothitby
trigger1 = 1
value = SCA
[State 1115313, EnvShake]
type = FallEnvShake
trigger1 = Time = 0
[State 1115313, EnvShake]
type = EnvShake
trigger1 = Time = 0
time = 14
ampl = 4
freq = 120
[State 1115313, Var] ;Save fall velocity
type = VarSet
trigger1 = Time = 0
sysvar(1) = floor(vel y)
[State 1115313, 2] ;Hit ground anim (normal)
type = ChangeAnim
triggerall = time = 0
trigger1 = (anim != [5051,5059]) && (anim != [5061,5069])
trigger2 = !SelfAnimExist(5100 + (anim % 10))
value = 5100
[State 1115313, 3] ;Hit ground anim (for hit up)
type = ChangeAnim
trigger1 = time = 0
trigger1 = (anim = [5051,5059]) || (anim = [5061,5069])
trigger1 = SelfAnimExist(5100 + (anim % 10))
value = 5100 + (anim % 10)
[State 1115313, 4]
type = PosSet
trigger1 = Time = 0
y = 0
[State 1115313, 5]
type = velset
trigger1 = Time = 0
y = 0
[State 1115313, 6] ;Reduce speed
type = VelMul
trigger1 = Time = 0
x = 0.75
[State 1115313, 7]
type = ChangeState
trigger1 = Time = 0
trigger1 = GetHitVar(fall.yvel) = 0
value = 1115315 ;Downed get-hit (lying down)
[State 1115313, 8]
type = Explod
trigger1 = Time = 1
anim = F(60 + (sysvar(1) > Const720p(20)) + (sysvar(1) > Const720p(56)))
pos = 0, 0
sprpriority = ifelse (sysvar(1) <= Const720p(56), -10, 10)
[State 1115313, 9]
type = HitFallDamage
trigger1 = Time = 3
[State 1115313, 10]
type = PlaySnd
trigger1 = Time = 1
value = F7, (sysvar(1) > Const720p(20)) + (sysvar(1) > Const720p(56))
[State 1115313, 11]
type = PosFreeze
trigger1 = 1
[State 1115313, 12]
type = ChangeState
trigger1 = AnimTime = 0
value = 1115314 ;Downed get-hit (bounce off ground)
[State 1115313, 13]
type = ForceFeedback
trigger1 = Time = 0
waveform = sinesquare
ampl = 128,-3,-.2,.005
time = 20
;----- bounce off ground -----
[Statedef 1115314]
type = L
movetype= H
physics = N
[State 1115314, NHB]
type = nothitby
trigger1 = 1
value = SCA
[State 1115314, 1] ;Coming hit ground anim (normal)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim != [5101,5109]
trigger2 = !SelfAnimExist(5160 + (anim % 10))
value = 5160
[State 1115314, 2] ;Coming hit ground anim (for hit up)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim = [5101,5109]
trigger1 = SelfAnimExist(5160 + (anim % 10))
value = 5160 + (anim % 10)
[State 1115314, 3]
type = HitFallVel
trigger1 = Time = 0
[State 1115314, 4]
type = PosSet
trigger1 = Time = 0
y = Const(movement.down.bounce.offset.y)
[State 1115314, 5]
type = PosAdd
trigger1 = Time = 0
x = Const(movement.down.bounce.offset.x)
[State 1115314, 6] ;Acceleration
type = VelAdd
trigger1 = 1
y = Const(movement.down.bounce.yaccel)
[State 1115314, 7] ;Hit ground
trigger1 = Vel Y > 0
trigger1 = Pos Y >= Const(movement.down.bounce.groundlevel)
type = ChangeState
value = 1115315
;----- lying down -----
[Statedef 1115315]
type = L
movetype= H
physics = N
[State 1115315, NHB]
type = nothitby
trigger1 = 1
value = SCA
[State 1115315, EnvShake]
type = FallEnvShake
trigger1 = Time = 0
[State 1115315, 1] ;For hit up/up-diag type (from state 5081)
type = ChangeAnim
persistent = 0
trigger1 = SelfAnimExist(5110 + (anim % 10))
trigger1 = anim = [5081,5089]
value = 5110 + (anim % 10)
[State 1115315, 2] ;Hit ground anim (normal)
type = ChangeAnim
triggerall = time = 0
triggerall = anim != [5110,5119] ;Not already changed anim
trigger1 = anim != [5161,5169]
trigger2 = !SelfAnimExist(5170 + (anim % 10))
value = 5170
[State 1115315, 3] ;Hit ground anim (for hit up)
type = ChangeAnim
triggerall = time = 0
triggerall = anim != [5110,5119] ;Not already changed anim
trigger1 = anim = [5161,5169]
trigger1 = SelfAnimExist(5170 + (anim % 10))
value = 5170 + (anim % 10)
[State 1115315, 5]
type = PosSet
trigger1 = Time = 0
y = 0
[State 1115315, Var] ;Get fall velocity
type = VarSet
trigger1 = Time = 0
trigger1 = GetHitVar(fall.yvel) != 0
sysvar(1) = floor(vel y)
[State 1115315, 6]
type = PlaySnd
trigger1 = Time = 0
trigger1 = !SysVar(0)
value = F7, (sysvar(1) > Const720p(20)) + (sysvar(1) > Const720p(56))
[State 1115315, 7]
type = Explod
trigger1 = Time = 0
trigger1 = !SysVar(0)
anim = F(60 + (sysvar(1) > Const720p(20)) + (sysvar(1) > Const720p(56)))
pos = 0, 0
sprpriority = ifelse (sysvar(1) <= Const720p(56), -10, 10)
[State 1115315, 8]
type = velset
trigger1 = Time = 0
y = 0
[State 1115315, Up type]
type = ChangeAnim
persistent = 0
triggerall = anim = [5171,5179]
triggerall = SelfAnimExist(5110 + (anim % 10))
trigger1 = AnimTime = 0
trigger2 = SysVar(0) ;SysVar(0) = 1 avoids hit ground anim
value = 5110 + (anim % 10)
[State 1115315, 10] ;For normal
type = ChangeAnim
persistent = 0
triggerall = Anim != [5111,5119]
trigger1 = AnimTime = 0
trigger2 = SysVar(0) ;SysVar(0) = 1 avoids hit ground frame
value = 5110
[State 1115315, 11]
type = changestate
trigger1 = alive
trigger1 = time >= 10
value = 1115316
[State 1115315, KO]
type = selfState
triggerall = !alive
trigger1 = AnimTime = 0
trigger2 = SysVar(0) ;SysVar(0) = 1 avoids hit ground frame
trigger3 = Anim = [5110,5119]
value = 5150
[State 1115315, 12]
type = VarSet
trigger1 = SysVar(0)
trigger1 = Time = 0
sysvar(0) = 0
[State 1115315, 13]
type = VelMul
trigger1 = 1
x = 0.85
[State 1115315, 14]
type = velset
trigger1 = abs(Vel x) < Const(movement.down.friction.threshold)
persistent = 0
x = 0
;----- getting up -----
[Statedef 1115316]
type = L
movetype= H
physics = N
[State 1115316, NHB]
type = nothitby
trigger1 = 1
value = SCA
[State 1115316, 1a] ;Get up anim (normal)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim != [5111,5119]
trigger2 = !SelfAnimExist(5120 + (anim % 10))
value = 5120
[State 1115316, 1b] ;Get up anim (for hit up/diag-up)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim = [5111,5119]
trigger1 = SelfAnimExist(5120 + (anim % 10))
value = 5120 + (anim % 10)
[State 1115316, 2]
type = velset
trigger1 = Time = 0
x = 0
[State 1115316, 4]
type = HitFallSet
trigger1 = 1
value = 0
[State 1115316, 7]
type = ChangeState
trigger1 = !animtime
trigger2 = time >= 60
value = 1115300
;--- Dizzy ---
[Statedef 1115300]
type = S
physics = S
movetype = I
velset = 0, 0
anim = 5300
[State 0, PlaySnd]
type = PlaySnd
trigger1 = !Time
value = F5300, 0
[State 1115300, Simul]
type = statetypeset
trigger1 = numenemy > 1
trigger1 = enemynear(0), hitdefattr = SCA, AT
movetype = I
[State 1115300, Hitfall]
type = hitfallset
trigger1 = 1
value = 0
[State 1115300, Max Timer]
type = varset
trigger1 = !time
sysfvar(2) = 120
[State 1115300, Max Timer]
type = varset
triggerAll = !Time; && AILevel
trigger1 = Name = "Akuma" && var(40) != 1
trigger2 = (Name = "Rugal" || Name = "Rugal Bernstein") && var(40) != 1
trigger3 = Name = "Vega" && (AuthorName = "Froz" || AuthorName = "Phantom.of.the.Server")
trigger4 = Name = "Geese" || Name = "Geese Howard"
trigger5 = Name = "Gill"
trigger6 = Name = "Mr.Karate" || Name = "Mr. Karate" || Name = "MrKarate" || Name = "Mr Karate"
trigger7 = Name = "Kain"
sysfvar(2) = 60
[State 1115300, Max Timer]
type = varset
triggerAll = !Time; && AILevel
trigger1 = Name = "Akuma" && var(40) = 1 || Name = "Shin Akuma"
trigger2 = (Name = "Rugal" || Name = "Rugal Bernstein") && var(40) = 1 || Name = "God Rugal"
sysfvar(2) = 0
[State 1115300, Timer]
type = varadd
trigger1 = time
sysfvar(2) = -1
[State 1115300, Timer]
type = varadd
trigger1 = command = "up" || command = "down" || command = "back" || command = "fwd"
sysfvar(2) = -2
[State 1115300, Timer]
type = varadd
trigger1 = command = "x" || command = "y" || command = "z" || command = "a" || command = "b" || command = "c"
sysfvar(2) = -1
[State 1115300, Signal]
type = palfx
trigger1 = command = "up" || command = "down" || command = "back" || command = "fwd"
trigger2 = command = "x" || command = "y" || command = "z" || command = "a" || command = "b" || command = "c"
time = 1
add = 32, 32, 32
[State 1115300, Skip]
type = varset
trigger1 = !time
sysfvar(3) = 0
[State 1115300, Skip]
type = varadd
trigger1 = command = "up" || command = "down" || command = "back" || command = "fwd"
trigger2 = command = "a" || command = "b" || command = "c" || command = "x" || command = "y" || command = "z"
sysfvar(3) = 1
[State 1115300, Skip]
type = changeanim
trigger1 = animelemtime(animelemno(0)) > 0 && animelemtime(animelemno(0) + 1) < 0
trigger1 = animelemtime(animelemno(0) + 1) >= -sysfvar(3)
value = 5300
elem = animelemno(0) + 1
[State 1115300, Skip]
type = varset
trigger1 = animelemtime(1) >= 0 && !animelemtime(animelemno(0))
sysfvar(3) = 0
[State 1115300, End]
type = varset
trigger1 = sysfvar(2) < 0
sysfvar(2) = 0
[State 1115300, End]
type = selfstate
trigger1 = sysfvar(2) <= 0 || time >= 120 || roundstate != 2
value = 0
ctrl = 1
;------------------------------
;Dizzy Stars / Birds
[StateDef 1115369]
type = A
Anim = 696969
physics = N
[State 0, Pos]
type = posset
trigger1 = numenemy
x = Root, Pos X
y = (Root, Pos Y) + (Root, Const(size.head.pos.y)) - 16
[State 0, Star]
type = explod
trigger1 = !numexplod(1)
anim = F5300 + Random%2
ID = 1
postype = p1
pos = 0, 0
sprpriority = 5
bindtime = -1
removetime = -1
[State 0, Star]
type = explod
trigger1 = !numexplod(2)
anim = F5300 + Random%2
ID = 2
postype = p1
pos = 0, 0
sprpriority = 5
bindtime = -1
removetime = -1
[State 8970, Star]
type = explod
trigger1 = !numexplod(3)
anim = F5300 + Random%2
ID = 3
postype = p1
pos = 0, 0
sprpriority = 5
bindtime = -1
removetime = -1
[State 8970, Star]
type = explod
trigger1 = !numexplod(4)
anim = F5300 + Random%2
ID = 4
postype = p1
pos = 0, 0
sprpriority = 5
bindtime = -1
removetime = -1
[State 8970, Circle around]
type = modifyexplod
trigger1 = numexplod(1)
ID = 1
postype = p1
pos = ceil(32 * cos((gametime + 0) / 32.0 * pi)), ceil(6 * sin((gametime + 0) / 32.0 * pi))
scale = 0.375 + 0.125 * sin((gametime + 0) / 32.0 * pi), 0.375 + 0.125 * sin((gametime + 0) / 32.0 * pi)
sprpriority = ifelse(sin((gametime + 0) / 32.0 * pi) >= 0, 5, -5)
angle = Time * 1.5
[State 8970, Circle around]
type = modifyexplod
trigger1 = numexplod(2)
ID = 2
postype = p1
pos = ceil(32 * cos((gametime + 32) / 32.0 * pi)), ceil(8 * sin((gametime + 32) / 32.0 * pi))
scale = 0.375 + 0.125 * sin((gametime + 32) / 32.0 * pi), 0.375 + 0.125 * sin((gametime + 32) / 32.0 * pi)
sprpriority = ifelse(sin((gametime + 32) / 32.0 * pi) >= 0, 5, -5)
angle = 90 + Time * 1.5
[State 8970, Circle around]
type = modifyexplod
trigger1 = numexplod(3)
ID = 3
postype = p1
pos = ceil(32 * cos((gametime + 16) / 32.0 * pi)), ceil(8 * sin((gametime + 16) / 32.0 * pi))
scale = 0.375 + 0.125 * sin((gametime + 16) / 32.0 * pi), 0.375 + 0.125 * sin((gametime + 16) / 32.0 * pi)
sprpriority = ifelse(sin((gametime + 16) / 32.0 * pi) >= 0, 5, -5)
angle = 180 + Time * 1.5
[State 8970, Circle around]
type = modifyexplod
trigger1 = numexplod(4)
ID = 4
postype = p1
pos = ceil(32 * cos((gametime + 48) / 32.0 * pi)), ceil(8 * sin((gametime + 48) / 32.0 * pi))
scale = 0.375 + 0.125 * sin((gametime + 48) / 32.0 * pi), 0.375 + 0.125 * sin((gametime + 48) / 32.0 * pi)
sprpriority = ifelse(sin((gametime + 48) / 32.0 * pi) >= 0, 5, -5)
angle = 270 + Time * 1.5
[State 8970, End]
type = removeexplod
trigger1 = Root, StateNo != [1115300, 1115319]
[State 8970, End]
type = destroyself
trigger1 = !NumExplod
Now for the system.
Everytime you see var(20), it is for Custom Combo, you can delete these if your characters doesn't have it.
;Stun/Dizzy System
; Reset the decider whenever the opponent is not attacking
[State 0, Stun Points Decider Reset]
type = VarSet
triggerAll = var(46) > 0 && NumEnemy
trigger1 = EnemyNear, MoveType != A && (EnemyNear, StateNo != [200,4999])
trigger2 = EnemyNear, var(20)
var(46) = 0
ignorehitpause = 1
; Decide how many points to add to the stun
[State 0, Stun Points Decider]
type = Null
triggerAll = NumEnemy
triggerAll = EnemyNear, MoveType = A && !EnemyNear, var(20) && var(46) = 0
trigger1 = (EnemyNear, StateNo = [200,209]) || (EnemyNear, StateNo = [230,239]) || (EnemyNear, StateNo = [400,409]) || (EnemyNear, StateNo = [430,439]) || (EnemyNear, StateNo = [600,609]) || (EnemyNear, StateNo = [630,639])
trigger1 = var(46) := 3 + (Random%2)
trigger2 = (EnemyNear, StateNo = [210,219]) || (EnemyNear, StateNo = [240,249]) || (EnemyNear, StateNo = [410,419]) || (EnemyNear, StateNo = [440,449]) || (EnemyNear, StateNo = [610,619]) || (EnemyNear, StateNo = [640,649])
trigger2 = var(46) := 8 + (Random%2)
trigger3 = (EnemyNear, StateNo = [220,229]) || (EnemyNear, StateNo = [250,259]) || (EnemyNear, StateNo = [420,429]) || (EnemyNear, StateNo = [450,459]) || (EnemyNear, StateNo = [620,629]) || (EnemyNear, StateNo = [650,659])
trigger3 = var(46) := 12 + (Random%2)
trigger4 = EnemyNear, StateNo = [1000,2999]
trigger4 = var(46) := 16 + (Random%3)
trigger5 = EnemyNear, StateNo = [3000,4999]
trigger5 = var(46) := 18 + (Random%3)
ignorehitpause = 1
; Reset stun points when you're not being hit or if stun is activated
[State 0, Stun Points Reset]
type = Null
trigger1 = (Root, StateNo = 1115300) && var(47) >= 75
trigger1 = var(47):= -25
trigger2 = var(48) = 0
trigger2 = var(47):= 0
ignorehitpause = 1
; Actually adds the stun points
[State 0, Stun Points Add]
type = VarAdd
trigger1 = var(47) < 75 && NumEnemy
trigger1 = !EnemyNear, var(20)
trigger1 = var(3) = 1
var(47) = Ceil(var(46) / ifElse((Root, GetHitVar(HitCount) > 1), (Root, GetHitVar(HitCount) * 2), 1))
ignorehitpause = 1
; Set timer once you're stunned
[State 0, Stun Points Timer Set]
type = VarSet
trigger1 = Root, MoveType = H
var(48) = 180
ignorehitpause = 1
; Decrease timer
[State 0, Stun Points Timer Count]
type = VarAdd
trigger1 = var(48) > 0 && Root, MoveType != H
var(48) = -1
ignorehitpause = 1
; Helper animation (like stars floating over the head) when char is stunned
[State 0, Helper]
type = Helper
trigger1 = !NumHelper(1115369) && RoundState = 2
trigger1 = (Root, StateNo = [1115310,1115316])
helpertype = normal
name = "Stars Birds"
ID = 1115369
stateno = 1115369
postype = p1
ignorehitpause = 1
To add a bar, just make explods and scale one of them according to var(47)
You can check this thread wich explains it better:
https://mugenguild.com/forum/topics/custom-bars-141757.0.html