YesNoOk
avatar

Help with AI throw selection (from 800) (Read 983 times)

Started by Momotaro, November 30, 2020, 01:18:57 am
Share this topic:
Help with AI throw selection (from 800)
#1  November 30, 2020, 01:18:57 am
  • *****
  • A.K.A. NED
  • I like to draw fighting game characters...
I paste the code of throw attempt

The state define if player hit punch command or kick command, so it can select the throw with var

It also detects if forward or backward is hold so it can go to switching sides states.

805 is switching sides state transition (P1)
806 is switching sides state transition (P1)

810 is punch throw
860 is kick throw

Now I would like the AI to be able to do any of these variations randomly

25% each of them
-punch throw with switching sides
-kick throw with switching sides
-punch throw without switching sides
-kick throw without switching sides

I don't know how to do it effectively
With this main trigger
"triggerAll = AILevel"

Code:
;---------------------
; Throw Attempt
[Statedef 800]
type    = S
movetype= A
physics = S
juggle  = 0
velset = 0,0
ctrl = 0
anim = 800
facep2 = 1

[State 800, Button Detect]
type = VarSet
trigger1 = !Time
var(10) = (helper(10371), var(3)) && (helper(10371), var(4)) || (helper(10371), var(4)) && (helper(10371), var(5)) || (helper(10371), var(3)) && (helper(10371), var(5))

[State 800, Throw Escape Reset]
type = VarSet
trigger1 = 1
var(19) = 0

[State 800, Escape]
type = VarSet
trigger1 = NumEnemy
trigger1 = (EnemyNear, StateNo = [0,899]) && (EnemyNear, StateNo != [100,104]) && (EnemyNear, StateNo != [600,799])
var(19) = 7

[State 800, AttackDist]
type = AttackDist
trigger1 = 1
value = 0

[State 800, Throw 1]
type = Hitdef
trigger1 = AnimElem = 2
trigger1 = !var(38)
attr = S, NT
priority = 3,Miss
getpower = 35 * !var(20)
givepower = 35,35
hitflag = M-
numhits = 0
sparkno = -1
p1stateno = ifelse(command = "holdfwd",810,805)
hitsound = s800, 0
fall = 1
fall.recover = 0

[State 800, Throw 2]
type = Hitdef
trigger1 = AnimElem = 2 && var(10)
trigger1 = !var(38)
attr = S, NT
priority = 3,Miss
getpower = 35 * !var(20)
givepower = 35,35
hitflag = M-
numhits = 0
sparkno = -1
p1stateno = ifelse (command = "holdfwd",805,860)
hitsound = s800, 0
fall = 1
fall.recover = 0

[State 800, Miss Voice]
type = PlaySnd
trigger1 = AnimElem = 3
value = 0,10
channel = 0

[State 800, Swing Snd]
type = PlaySnd
trigger1 = AnimElem = 2
value = 1,0
channel = 1

[State 800, StateTypeSet: Idle]
type = StateTypeSet
trigger1 = AnimElemTime(3) >= 0
moveType = I

[State 800, End]
type = ChangeState
trigger1 = !AnimTime
value = 0
ctrl = 1

Thanks
Last Edit: November 30, 2020, 11:35:17 am by Nedflandeurse
Re: Help with AI throw selection (from 800)
#2  November 30, 2020, 05:49:46 am
  • avatar
  • **
    • USA
I've never actually tried this.  You got that crazy buffering thing going on, so I'm going to try something clever and let you see if it works.  Or someone else can tell me I'm a dumbass.

Code:
[State 800, Throw 1]
type = Hitdef
triggerall = !AILevel  ;; we need to make the AI not use this
trigger1 = AnimElem = 2
trigger1 = !var(38)
attr = S, NT
priority = 3,Miss
getpower = 35 * !var(20)
givepower = 35,35
hitflag = M-
numhits = 0
sparkno = -1
p1stateno = ifelse(command = "holdfwd",810,805)
hitsound = s800, 0
fall = 1
fall.recover = 0
 
[State 800, Throw 2]
type = Hitdef
triggerall = !AILevel  ;; we need to make the AI not use this
trigger1 = AnimElem = 2 && var(10)
trigger1 = !var(38)
attr = S, NT
priority = 3,Miss
getpower = 35 * !var(20)
givepower = 35,35
hitflag = M-
numhits = 0
sparkno = -1
p1stateno = ifelse (command = "holdfwd",806,860)  ;; I think you made a typo here.
hitsound = s800, 0
fall = 1
fall.recover = 0

[State 800, AI Only]
type = Hitdef
triggerall = AILevel  ;; Here you go, AI.  Use this.
trigger1 = AnimElem = 2
trigger1 = !var(38)
trigger1 = fvar(38) := random  ;; I just need an available variable real quick.  You might already have a random variable for this?
attr = S, NT
priority = 3,Miss
getpower = 35 * !var(20)
givepower = 35,35
hitflag = M-
numhits = 0
sparkno = -1
p1stateno = ifelse(fvar(38) <= 249, 810, (ifelse(fvar(38) <= 499, 805, (ifelse(fvar(38) <= 749, 806,860)))))
hitsound = s800, 0
fall = 1
fall.recover = 0
Re: Help with AI throw selection (from 800)
#3  November 30, 2020, 10:45:17 am
  • *****
  • A.K.A. NED
  • I like to draw fighting game characters...
Wow! Thanks a lot.
Seems like there is more diversity now.

I fixed a small error (line 48)

p1stateno = ifelse(fvar(38) <= 249, 810, (ifelse(fvar(38) <= 499, 805, (ifelse(fvar(38) <= 749, 806,860)))))

Now it works.
But still I have the feeling AI use more "punch throw"
Perhaps it's just my feeling.

But if you're sure about how the random values works here, I'm keeping it.



Also, I try to do the same with air throw.
This time no need for transition states.
Only a throw attempt and Punch throw success 50% and Kick throw success 50%

The fact there is both p1stateno and p2stateno that have to "match", I'm not sure how to do it with the random stuff.

player version

Code:
[State 900, Button Detect]
type = VarSet
trigger1 = !Time
var(10) = (helper(10371), var(3)) && (helper(10371), var(4)) || (helper(10371), var(4)) && (helper(10371), var(5)) || (helper(10371), var(3)) && (helper(10371), var(5))

[State 900, Throw 1]
type = HitDef
triggerall = !AILevel  ;; we need to make the AI not use this
trigger1 = AnimElem = 1
attr = A,NT
hitFlag = AF
priority = 3,Miss
getPower = 35 * !var(20)
givePower = 35,35
numhits = 0
sparkno = -1
p1facing = 1
p2facing = 1
p1stateno = 910
p2stateno = 920
p2getp1state = 1
hitsound = s800, 0
fall = 1
fall.recover = 0

[State 900, Throw 2]
type = HitDef
triggerall = !AILevel  ;; we need to make the AI not use this
trigger1 = AnimElem = 1 && var(10)
attr = A,NT
hitFlag = AF
priority = 3,Miss
getPower = 35 * !var(20)
givePower = 35,35
numhits = 0
sparkno = -1
p1facing = 1
p2facing = 1
p1stateno = 930
p2stateno = 940
p2getp1state = 1
hitsound = s800, 0
fall = 1
fall.recover = 0

AI version (WIP)

[State 900, AI Only]
type = HitDef
triggerall = AILevel  ;; Here you go, AI.  Use this.
trigger1 = AnimElem = 1 && var(10)
attr = A,NT
hitFlag = AF
priority = 3,Miss
getPower = 35 * !var(20)
givePower = 35,35
numhits = 0
sparkno = -1
p1facing = 1
p2facing = 1
p1stateno = 930;------I don't know how to set this part
p2stateno = 940;------I don't know how to set this part
p2getp1state = 1
hitsound = s800, 0
fall = 1
fall.recover = 0

I'm thinking if using some random var would make it...
Something based on that...

Code:
[State 800, Button Detect (AI)]
type = VarSet
trigger1 = !Time && AILevel
var(10) = (Random < 500)

OK this one seems to work well. (air throw)
I did it this way.

Code:
[State 900, AI Only throw 1]
type = HitDef
triggerall = AILevel  ;; Here you go, AI.  Use this.
trigger1 = AnimElem = 1
attr = A,NT
hitFlag = AF
priority = 3,Miss
getPower = 35 * !var(20)
givePower = 35,35
numhits = 0
sparkno = -1
p1facing = 1
p2facing = 1
p1stateno = 910
p2stateno = 920
p2getp1state = 1
hitsound = s800, 0
fall = 1
fall.recover = 0

[State 900, AI Only throw 2]
type = HitDef
triggerall = AILevel  ;; Here you go, AI.  Use this.
trigger1 = AnimElem = 1 && var(10)
attr = A,NT
hitFlag = AF
priority = 3,Miss
getPower = 35 * !var(20)
givePower = 35,35
numhits = 0
sparkno = -1
p1facing = 1
p2facing = 1
p1stateno = 930
p2stateno = 940
p2getp1state = 1
hitsound = s800, 0
fall = 1
fall.recover = 0
Last Edit: November 30, 2020, 11:13:11 am by Nedflandeurse
Re: Help with AI throw selection (from 800)
#4  November 30, 2020, 11:34:45 am
  • *****
  • A.K.A. NED
  • I like to draw fighting game characters...
I also solved the part where AI tends to use only PUNCH throw after switching sides states.

I needed to add something in switching sides state to decide if AI will choose P or K


;AI décide si après le switching sides (805) on va vers P throw ou K throw.
[State 800, Button Detect (AI)]
type = VarSet
trigger1 = !Time && AILevel
var(10) = (Random < 500)

[State 805, End];Avec AI
type = ChangeState
triggerall = AILevel  ;; Here you go, AI.  Use this.
trigger1 = AnimElemTime(4) >= 0
value = ifElse(var(10), 860, 810)

Thnaks for the help from the beginning.
It "unlocked" some old skills from myself, I feel a bit less rusty now ^^;
Re: Help with AI throw selection (from 800)
#5  November 30, 2020, 08:25:07 pm
  • avatar
  • **
    • USA
I figured you just needed an idea.  I'm glad you got it to work!  ^_^

Normally, I would use different CMD states for this type of thing, but you have that buffering system, so the AI has to be controlled from inside the attack.  It's a lot different.