========================================================
AI Implementation Code (With bonus auto-taunt technique)
========================================================
Created by K3nShiN
Based on VK and Deuce's AI coding technique

AI = Stands for Artificial Intelligence; Historically implemented on every game ever created!
An AI code basically guides the CPU on what to do on certain events/situations giving gameplay
a much more challenging factor.

There are 2 basic methods of triggering this AI code, one is the use of Variables and the other is
through pallette tracking through specific pallette numbers in the .Def file of the character.

Let's go through triggering AI with the use of variables first...

1.) Open your character's CMD file with any text editor of your preference.
2.) Next, create a list of humanly impossible commands right ABOVE the [Statedef -1] state definition.
     It should look a lot like this:

; -| CPU Commands |-------------------------------------------------------------

[Command]
name = "CPU1"
command = D, D, U, U, D, U
time = 1

[Command]
name = "CPU2"
command = D, U, U, D, D, U
time = 1

[Command]
name = "CPU3"
command = D, D, D, U, U, U
time = 1

and so on....

Tip: The more CPU commands you make, the better. As the CPU always picks out a random command inside
       the CMD file and execute it instantly. The CPU will only need to pick one of these commands and the AI 
       will be triggered. Explained more later.

let's continue...

3.) Set the variable that will be used to detect CPU control and create a list of triggers that would correspond 
     to each CPU command that you set up earlier. Place it UNDERNEATH the [Statedef -1] state definition.
It should look like this:

[Statedef -1]

[State -1, Activate AI]
type = VarSet
trigger1  = command = "CPU1"
trigger2  = command = "CPU2"
trigger3  = command = "CPU3"
v = 20   ;You can change this to any number provided that it doesn't collide with other variables you've already set.
value = 1  

The previous code basically means "set variable 20's value to 1 if either of the previous commands were executed."
This value will reset back to "0" before and after each round, that's why you need to make more commands. The sooner it gets executed, the better.

Now let's implement what we've learned so far and try to get your character to do a simple AI command shall we? ^_^x
I'm gonna use mvsc type Guy as a reference...

; ============================
; AI Auto taunt
; ============================
[State -1,AutoTaunt]
type = ChangeState
value =  195  ;Guy's taunt stateno (state number). You can change this to your character's taunt stateno.
triggerall = var(20) = 1  ;It executes if it detects CPU control. In plain terms, "If Variable 20 is equal to 1".
triggerall = statetype != A  ;This prevents the mistake of the CPU taunting in mid-air! O_o
triggerall = movetype != H  ;This prevents the mistake of the CPU taunting while currently being hit! O_o
triggerall = statetype != L  ;This prevents the mistake of the CPU taunting while currently lying down! O_o
triggerall = P2life != 0  ;This prevents the mistake of the CPU taunting when the enemy is already dead! O_o
trigger1 = (P2statetype = L) && (ctrl = 1) && (random <= 500)
persistent = 0

The chunk of code above basically means "Automatically execute the taunt when the enemy is down and character is able to move at 50% probability, but not when Player 1 is in the air, being hit, lying down or enemy is out of commission." 
For a much more optimized version of the code, look below... it does exactly the same but with a much more
cleaner layout...

; ============================
; AI Auto taunt
; ============================
[State -1,AutoTaunt]
type = ChangeState
value =  195
triggerall = (var(20) = 1) && (statetype != A) && (movetype != H) && (statetype != L) && (P2life != 0)
trigger1 = (P2statetype = L) && (ctrl = 1) && (random <= 500)
persistent = 0

Reminder: All of the previous codes are to be placed inside the CMD file only!!!!

That concludes our Basic AI Implementation tutorial. Watch out for more tutorial and tips at Zero Gravity Studios.
http://www.zgstudios.net
