YesNoOk
avatar

How do I make AI charge up? (Read 6219 times)

Started by Capn_Zed, August 11, 2017, 08:45:03 am
Share this topic:
How do I make AI charge up?
#1  August 11, 2017, 08:45:03 am
  • *
    • Jamaica
I'm having problems in terms of coding the AI such that it charges up to full power. It's able to charge but not consistently. It charges for about 1 second (which doesn't really garner any chakra/energy) then stops. It does this about 3 times in a row then rushes in to attack. What I want is for the AI to charge consistently until either the power is max or the distance parameter has stopped being met. I am using mugen version 1.0 and the character is Onoki from Naruto.

His AI portion for his charge looks like this:
Code:
[State -1, Power Charge]
type = changestate
triggerall = var (59) = 0
triggerall = RoundState = 2 && ailevel > 0
triggerall = power < 3000
triggerall = StateType = S
triggerall = (p2statetype = S) || (p2statetype = C)|| (p2statetype = A)
triggerall = Ctrl
triggerall = P2BodyDist X >= 100
trigger1 = power < 1000 && Random = [600,800]
trigger2 = power < 2000 && power > 1000 && Random = [300,500]
trigger3 = power < 3000 && power > 2000 && Random = [100,200]
value = 500

The Normal CNS portion looks like this:
Code:
; Power Charge:
;-------------------------------------------------------------------------------
; Power Charge - Start
[Statedef 500]
type    = S
movetype= I
physics = S
juggle  = 1
velset = 0,0
ctrl = 0
anim = 500
sprpriority = 2

[State 0, Explod]
type = Explod
trigger1 = time = 0
anim = 7014
ID = 550
pos = -1,0
postype = p1
facing = 1
vfacing = 1
bindtime = -1
removetime = -1
scale = .3,.3
sprpriority = 1
ontop = 0
ownpal = 1
removeongethit = 1
ignorehitpause = 1

[State 0, Explod]
type = Explod
trigger1 = time = 0
anim = 7014
ID = 550
pos = -1,0
postype = p1
facing = 1
vfacing = 1
bindtime = -1
removetime = -1
scale = .5,.5
sprpriority = 1
ontop = 0
ownpal = 1
removeongethit = 1
ignorehitpause = 1

[State 0, EnvShake]
type = EnvShake
trigger1 = time%5 = 0
time = 5
ampl = 2

[State 0, PowerAdd]
type = PowerAdd
trigger1 = 1
value = 10

[State 0, PlaySnd]
type = PlaySnd
trigger1 = time = 0||time = 100||time = 200
value = S5,27
volume = 20
channel = 1

[State 0, PlaySnd]
type = PlaySnd
trigger1 = time = 0
value = S0,26
volume = 999
channel = 2

[State 200, End]
type = ChangeState
triggerall = var (59) = 0
triggerall = RoundState = 2 && ailevel > 0
triggerall = time >= 6
trigger1 = time = 100+random%900
trigger2 = power = 3000
trigger3 = p2bodydist x >= 50
value = 501

[State 200, End]
type = ChangeState
Triggerall = var(9) = 0
triggerall = time >= 6
trigger1 = command != "hold_s"
trigger2 = power = 3000
value = 501

I'd like to know what I am missing or what wasn't done properly. Any help is greatly appreciated.

Var(9) = 0 indeed represents AI lvl. And I've tried adjusting the body distance. While he does charge from further away, he still does it intermittently in the fashion described at the beginning and not consistently. I tried looking at another char who charges properly and noticed some helper string in their AI code looking like this : trigger4 = numhelper(1120) = 1           Should thee be a helper string added to get smooth consistent charging?
Last Edit: August 11, 2017, 05:09:49 pm by Capn_Zed
Re: How do I make AI charge up?
#2  August 11, 2017, 03:15:39 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
[State 200, End]
type = ChangeState
Triggerall = var(9) = 0
triggerall = time >= 6
trigger1 = command != "hold_s"
trigger2 = power = 3000
value = 501

Does var(9) represent AILevel?  If not, then you need to add a trigger like
trigger1 = ailevel = 1

Otherwise maybe you have the p2bodydist x reversed... it's currently triggered to stop charging if the enemy is greater than 50 pixels away.
I would expect the opposite?
trigger3 = p2bodydist x <= 50

Re: How do I make AI charge up?
#3  August 12, 2017, 10:34:06 am
  • *
    • Jamaica
[State 200, End]
type = ChangeState
Triggerall = var(9) = 0
triggerall = time >= 6
trigger1 = command != "hold_s"
trigger2 = power = 3000
value = 501

Does var(9) represent AILevel?  If not, then you need to add a trigger like
trigger1 = ailevel = 1

Otherwise maybe you have the p2bodydist x reversed... it's currently triggered to stop charging if the enemy is greater than 50 pixels away.
I would expect the opposite?
trigger3 = p2bodydist x <= 50

Var(9) = 0 indeed represents AI lvl. And I've tried adjusting the body distance. While he does charge from further away, he still does it intermittently in the fashion described at the beginning and not consistently. I tried looking at another char who charges properly and noticed some helper string in their AI code looking like this : trigger4 = numhelper(1120) = 1           Should thee be a helper string added to get smooth consistent charging?
Re: How do I make AI charge up?
#4  August 12, 2017, 10:51:51 am
  • *****
  • Shame on you!
    • USA
I must be missing something because that changestate with the AI check would never let the AI stop charging.
But then you have var 59 and var 9 for AI. Which you might want to consider just using one variable. Anything over 0 and AI is active, and var 59 = 4 would be level 4 or how ever you have var 9 operating.

You could always duplicate the state and not let the player have access to it. Then the AI would be forced to do whatever that custom power charge state says.
vVv Ryuko718 Updated 10/31/22 vVv
Re: How do I make AI charge up?
#5  August 12, 2017, 07:40:03 pm
  • ****
    • USA
    • twitter.com/inktrebuchet
The problem would be at the end of your state 500. Try replacing the last two blocks with this.

Code:
 
[State 200, End]
type = ChangeState
triggerall = Ailevel > 0
;triggerall = var(59) = 0
triggerall = RoundState = 2
triggerall = time >= 6
trigger1 = time = 100+random%900
trigger2 = power = 3000
trigger3 = p2bodydist x >= 50
value = 501
 
[State 200, End]
type = ChangeState
Triggerall = Ailevel = 0
Triggerall = var(9) = 0
triggerall = time >= 6
trigger1 = command != "hold_s"
trigger2 = power = 3000
value = 501

Fairly sure your var(59) and var(9) were not doing what you thought they were suppose to do.
Re: How do I make AI charge up?
#6  August 13, 2017, 01:39:24 am
  • *
    • Jamaica
The problem would be at the end of your state 500. Try replacing the last two blocks with this.

Code:
 
[State 200, End]
type = ChangeState
triggerall = Ailevel > 0
;triggerall = var(59) = 0
triggerall = RoundState = 2
triggerall = time >= 6
trigger1 = time = 100+random%900
trigger2 = power = 3000
trigger3 = p2bodydist x >= 50
value = 501
 
[State 200, End]
type = ChangeState
Triggerall = Ailevel = 0
Triggerall = var(9) = 0
triggerall = time >= 6
trigger1 = command != "hold_s"
trigger2 = power = 3000
value = 501

Fairly sure your var(59) and var(9) were not doing what you thought they were suppose to do.

Well I've tried everything suggested so far and no dice. I'll give you all the coding that pertains to this issue.
 
First, the AI Activation and variable declaration:
Code:
; Activar IA
;-------------------------------------------------------------------------------
[State -2, Activar IA]
type = VarSet
triggerall = var (59) != 1
trigger1 = (command = "AI1") ||(Command = "AI2") || (Command = "AI3") || (Command = "AI4") || (Command = "AI5")
trigger2 = (Command = "AI6") || (Command = "AI7") || (Command = "AI8") || (Command = "AI9") || (Command = "AI10")
trigger4 = (Command = "AI11") || (Command = "AI12") || (Command = "AI13") || (Command = "AI14")
v = 59
value = 0

;AI
;---------------------------------------------------------------------------
[State -2, AI on]
type = VarSet
triggerall = Var(59) < 1
triggerall = RoundState = 2
trigger1 = AILevel > 0
v = 10
value = 1
Ignorehitpause = 1

[State -2, AI OFF]
type = VarSet
trigger1 = var(59) > 0
trigger1 = RoundState != 2
trigger2 = AILevel = 0
v = 10
value = 0
Ignorehitpause = 1


Now the AI portion of the power charge:
Code:
[State -1, Power Charge]
type = changestate
triggerall = var (59) = 0
triggerall = RoundState = 2 && ailevel > 0
triggerall = power < 3000
triggerall = StateType = S
triggerall = (p2statetype = S) || (p2statetype = C)|| (p2statetype = A)
triggerall = Ctrl
triggerall = P2BodyDist X >= 100
trigger1 = power < 1000 && Random = [600,800]
trigger2 = power < 2000 && power > 1000 && Random = [300,500]
trigger3 = power < 3000 && power > 2000 && Random = [100,200]
trigger4 = numhelper(1120) = 1
value = 500

And now the End of state 500 in the .cns that I have changed. :

Code:
[State 200, End]
type = ChangeState
triggerall = var (59) = 0
triggerall = RoundState = 2 && ailevel > 0
triggerall = time >= 6
trigger1 = time = 100+random%900
trigger2 = power = 3000
trigger3 = p2bodydist x >= 100
value = 501

[State 200, End]
type = ChangeState
trigger1 = var(59) > 0
trigger1 = RoundState != 2
triggerall = time >= 6
trigger1 = command != "hold_s"
trigger2 = power = 3000
value = 501

If you need more info about the character then I could email you their entire folder. I just want this fixed and there's no where online that shows how.
Re: How do I make AI charge up?
#7  August 13, 2017, 02:39:55 am
  • ****
    • USA
    • twitter.com/inktrebuchet
Based off what I'm seeing here Var(59) will always = 0 because there's nothing that ever sets it to 1. Which is why the second [statedef 200, end] keeps triggering when you don't want it to.
Re: How do I make AI charge up?
#8  August 13, 2017, 08:54:00 am
  • *
    • Jamaica
I must be missing something because that changestate with the AI check would never let the AI stop charging.
But then you have var 59 and var 9 for AI. Which you might want to consider just using one variable. Anything over 0 and AI is active, and var 59 = 4 would be level 4 or how ever you have var 9 operating.

You could always duplicate the state and not let the player have access to it. Then the AI would be forced to do whatever that custom power charge state says.

If by duplicate the state you mean do copy the first End over the second, then I tired and it didn't work. If not then could you elaborate? Also I could send you an email of the char file so that you can have a good look at it and fix what I can't. It'd probably be simpler that way. I don't like posting in my own thread so many times.
Re: How do I make AI charge up?
#9  August 13, 2017, 10:26:49 am
  • *****
  • Shame on you!
    • USA
The posting is good. If someone in the future has the same problem, they'll read it and see how it's solved. So the more details the better.

But what I mean is you copy the entire state. Statedef to changestate. Then you give it a new number. In your CMD, the player never gets to enter it. Only the AI gets to enter the state.

I have a feeling the main problem may be in your CMD. If your AI code for ANY move is allowed to trigger while stuck in the power charge state, No matter what you do in that state wont matter. The CMD will just change states.
You can try some kind of test to see. I'd say comment out the changestate completely. Test it and see if YOU can enter the state and get out of it. Once you know you can't exit the state, activate AI. Press ctrl+1 or ctrl+2 if you're fighting against yourself. If the AI can exit the state, then you know you need to really investigate the cmd file.
vVv Ryuko718 Updated 10/31/22 vVv
Re: How do I make AI charge up?
#10  August 13, 2017, 09:42:04 pm
  • *
    • Jamaica
The posting is good. If someone in the future has the same problem, they'll read it and see how it's solved. So the more details the better.

But what I mean is you copy the entire state. Statedef to changestate. Then you give it a new number. In your CMD, the player never gets to enter it. Only the AI gets to enter the state.

I have a feeling the main problem may be in your CMD. If your AI code for ANY move is allowed to trigger while stuck in the power charge state, No matter what you do in that state wont matter. The CMD will just change states.
You can try some kind of test to see. I'd say comment out the changestate completely. Test it and see if YOU can enter the state and get out of it. Once you know you can't exit the state, activate AI. Press ctrl+1 or ctrl+2 if you're fighting against yourself. If the AI can exit the state, then you know you need to really investigate the cmd file.

By removing the changestates entirely (both for player and AI) from the cns, Neither the Player(me) nor the AI could exit the charging statedef unless they were hit. This also resulted in the AI initiating and staying in the charge statedef. So the problem is solved to an extent. I tried adding the changestate for the AI only but that caused the previous problem to resurface. This is the changestate that was added to the cns after both the player's and ai's were removed:

Code:
[State 200, End]
type = ChangeState
triggerall = var (59) = 0
triggerall = RoundState = 2 && ailevel > 0
triggerall = time >= 6
trigger1 = time = 100+random%900
trigger2 = power = 3000
trigger3 = p2bodydist x >= 100
value = 501


Ok I changed that changestate to this:
Code:
[State 200, End]
type = ChangeState
triggerall = var (59) = 0
triggerall = RoundState = 2 && ailevel > 0
triggerall = time >= 6
trigger1 = time = 100+random%900
trigger2 = power = 3000
trigger3 = p2bodydist x <= 50
value = 501

And it worked properly. Thanks for all the help. All you have to do is Remove both changestates and add the changestate for ai.
Last Edit: August 13, 2017, 09:58:57 pm by Capn_Zed
Re: How do I make AI charge up?
#11  August 14, 2017, 12:31:22 am
  • *****
  • Shame on you!
    • USA
Dont forget to use the solve button at the bottom left.
I was going to suggest using DisplaytoClipboard to watch your var(59) and Var(9) to see if they were being set properly if it hadnt worked. You might want to look into that for future debugging use.
vVv Ryuko718 Updated 10/31/22 vVv