[FONT="Times New Roman"]I was searching for PET AIs and came across this old guide from the Guru. Since Tolinar isn't here, I guess I'll post it.
*note* please don't rep me for this guide cause I only copied it and Tolinar has[SIZE="7"] all[/SIZE] credits for this guide.*

---------------------------------------


PET AI
The language is...

XML.


When you make a new AI you use the "NEW AI button.

The rules of compilation are:

1. Event
2. Condition
3. "Conduct selection"

With type 1, When the event occurs, your pet takes an action.
With type 2, under a specific condition, your pet takes an action.
Type 3 involves things walking, attacking etc. the action you want taken.

A completed AI file becomes an AI.XML that can be shared or moved around. When the client restarts it'll detect a new pet XML.

HERE IS THE PATTERN.

Code:
[PHP]
<rules>
<rule name="rule 1">
<conditions>
<condition name="Condition" Variable="Value" />
</conditions>
<pattern>
<param_decl />
<sequence>
<cmd name="Execute_me" Variable="value" />
</sequence>
</pattern>
<event name="Event" Variable="Value" />
</rule>
<rule name="rule 2">
.
.
.
</rule>
</rules>[/PHP]

Now then! Let's get down and dirty.
I'll explain what are the codes for access to your pet as I translate.


[SIZE="6"]THE BIG BIG TABLE OF EVENTS[/SIZE]


seek_target
This event happens when a pet is looking for an enemy to attack.
If the enemy has already been engaged, this event is not called.


RECOMMENDED USE
- Pre-emptive actions against a foe could be set up.
- When the foe is close, you could designate a melee attack.
- When the foe is far, set up a spell first, then melee attack

TIPS
- This may not be failsafe against 2:1 circumstances.
- Also, if the enemy engages your pet, it may not turn to attack if it chooses its own target.
- This is great for recklessly plowing through enemies, but involves risk
- Used once per opponent. After the battle ends, this happens again



now_targeting
Whether or not your pet is ready to fight, it notes that it has an enemy in target and can prepare...

RECOMMENDED USE

Note whether if enemy is running it is more likely to be physically attacking, and prepare according.
if it is walking, the odds are high it is defending. Try for smash.
If foe is stopped, good odds it is trying to counterattack, try a spell.

TIPS
Once the enemy is recognized, this event occurs frequently.




attack
This event happens when the pet makes an attack.

Parameters:
pet_attackable_skill This is the name of the attack that was used.

Down This is true if the foe was knocked down, otherwise false.

RECOMMENDED USE
Generally, after knocking the foe down, the pet can be instructed to use a magic attack or such for additional damage.
If the last attack was a spell, you can set up accordingly and so on.
Be careful not to configure spells for use when the foe might be too close.



targeted

This event is called when the pet realizes it is being targeted by the enemy

Parameters
targeting_type
If the enemy is merely aware of the pet, it is alert. If the enemy is agro, the state is attack

Event Rules
When the alert sign (!) appears, it can trigger this event
When the attack sign (!!) appears, it can also trigger this event

RECOMMENDED USE
Use the knowledge of whether the foe is alerted or aggressive to make smart combat decisions.
after going into alert, the monster will have a fixed period before becoming aggro, and you may have a chance to strike first. But when a monster can shift from Alert to Attack quickly, trying to attack in the between can be dangerous



aimed
The enemy of the pet is using a long rage skill...

RECOMMENDED USE
Generally, when your pet is being shot at, it will want to attack physically...
when a Magic spell is coming, or a Magnum shot attack, you may want to be more careful about that.



target_skill_prepare

The pet's enemy is preparing a close combat skill.

RECOMMENDED USE
If the enemy is running, the odds of a general attack or smash are high, and a spell might stop them.,
Walking means likely defense, so counter with a Smash.
And a Stop means Counterattack or windmill so prepare according.
Be cautious of foes that start running because they cancel their skill.



target_magic_prepare

The enemy is obviously getting a spell ready and your pet has become aware.


RECOMMENDED USE
If you are near the foe, wail on them.
If they are far away, you might try returning fire with magic, then attack.
If the enemy is chain casting, your pet just might suffer from leprosy (?? xD Somethign is getting lost in the translation)



defence

This event happens when the pet successfully blocks an attack.
Parameters

Defence_enable_skill

When the pet defends an attack skill, the name of that attack goes here.


RECOMMENDED USE
After defending a long range physical attack or a close range combat skill, respond according.
Be aware that if your pet just tried to block a smash, it got owned and probably needs a heal.



attacked

This event happens when the pet is being attacked.
Parameters

master_skill
The name of the move or skill that just hit your pet.

down if your pet got knocked down, this is true, otherwise false.

RECOMMENDED USE
If your pet got wailed on, and the enemy is far, you might as well put back a potion or heal.
Remember to analyze what the enemy is doing so you know if you can heal at all.




master_targeted

This event happens when you, the PET OWNER< is targeted.

Parameters
targeting_type alert or attack.

NOTES
This will respond whenever something is targeting you.
Though I am not sure if it will change your pet's target.

Example: Your pet is facing down Spider A, and Spider A is preparing a skill.
So your pet is ready to counterattack.

Then it notices you are targeted by Spider B.
You have it set to attack relentlessly when master is targeted ...
so your pet wigs out and charges Spider A.

Be cautious when using this logic rule.



master_aimed

This skill triggers when an enemy is aiming at you.
Just like aimed, but for you.

Watch what the pet is attacking.



master_target_skill_prepare

When your target is preparing a skill, this event happens.
Just like target_skill_prepare.

If you can keep your pet on your target, you can make some great tag team attacks by watching these states.




master_target_magic_prepare
Someone is aiming magic at you. Just like target_magic_prepare.



master_defence

Parameters
defence_enable_skill

When you block an attack, your pet gets this event.



master_attacked
Master got attacked, angry pet.

Parameters
master_skill
What you got hit with.

down
Did you get knocked down?

RECOMMENDATIONS
if you ate the dirt, this might be a good moment for some pet healing.
IMPORTANT NOTE: Master_skill="all" can cause full responses to any attack.



master_skill_prepare

The master is noted to be readying a skill... hmmm

Parameters
event_skill
The name of the skill in use.

RECOMMENDATIONS AND NOTES
When "preparation completes" this skill triggers.
Hm, you could have your opponent use a recovery skill or item right after you use a skill...
It could be very convenient...
Or you can show off your well trained pet with some synchronous attacks?



master_attack

When you attack a foe, this happens.

Parameters
master_skill
The name of the skill you used.

RECOMMENDATIONS
If your pet is close in, you can gang up on the monster!
Or when you are getting ready for melee, a little pet magic to disrupt them is a wonderful thing.
Just watch the target closely.

[SIZE="6"]THE BIG BIG TABLE OF CONDITIONS[/SIZE]

Conditions go inside your rules to make logical decisions.
You must get them EXACTLY right for your pet to make sound logical choices!

TRANSLATION ATTEMPT
When you decribe multiple conditions of the same type, it becomes an OR type condition.
When you describe several conditions of DIFFERENT types, it becomes an AND condition.

Clear as mud. I know. Fix later.


target_state
The current state of the the targeted enemy, it has one parameter...

state
The state of the enemy.
I THINK the valid state options are...

walk
run
stop
blowaway
shoved
hit

But not 100%
This rule I do not fully understand, but it applies to detecting the current state of the the foe.



target_distance

This critical condition lets you test how far away the monster is.
Parameters.
minimum_distance
and maximum_distance

to try and recognize targets within a cetain range.

This is in centimeters.
RECOMMENDED USE
People in Japan say -- 4 -- M, is safe distance to use a skill from.
When the distance is under 4, odds are the skill gets interrupted.
When dealing with maximum range, skills generally can't be used past -- 12 -- M.
When range is above 12M (excluding magic) the odds for hitting is poor.



skill_preparable
An important rule that lets you make sure a skill can be prepared before you try,
parameter:

pet_skill
The skill your pet is checking if it can prepare or not.

The decision takes into account if the skill is max-charged, no more MP or stamina, and if the pet is still recovering on a cooldown skill.



master_damaged_life_greater

Parameter: life

This checks your HP that can be recovered, to see if the damage is greater than (Life).
It does not account for wounds! That is to say, you can be seriously wounded, but since a HP potion would not help you this condition will not be met.



And that's.. all that's listed. There may be more. But not here.

[SIZE="6"]The BIG BIG table of patterns[/SIZE]

this is where the ACTIONS of your pet are actually chosen.

<pattern>
<param_decl>
<sequence>
<cmd />
</sequence>
</pattern>

Looks kinda like that. Fun huh.



wait
Your pet stops and waits.

Parameters:
min and max. Both in milliseconds (1000ths of a second)

Your pet waits for an amount of time between the minimum and the maximum. Use the same value for both and it waits the same time every time.


move_against

Your pet avoids the monster, moving away from it.
Parameters

distance
How far you want the pet to go
run
Over the bridge! FLY! or walk, if false.
timeout
Milliseconds (1000ths) - how many before the pet stops retreating.

Your pet is able to move about 3m every 1 second.
Once it gets to a suitable retreat distance, it will not take action until its retreat goes past timeout.




chase
Go little pet! Sick'em.


Parameters
chase_target
Your pet chases either the enemy or master.
timeout
Your pet will chase for this many milliseconds.
run
Walk or Run, your choice. True or false.



move_around

it's circular excercise time - Strafe that enemy!


Parameters
clockwise
it's either true or false.
radius
This is the distance you want your pet to maintain.
run
True or false.
timeout
Stop circling the foe in this many milliseconds.




melee_attack
Your pet charges into a vicious 3 hit combo.


Parameters
timeout
How long to attempt the attack.



stackmagic_attack

Your pet prepares a little spell ... >:3

Parameters

stack_magic
This is the spell you want to have prepared
charge
The number of charges preferred?
timeout
Stop trying to charge magic after this long



prepare_skill
Time to get skilled on that monster.

Parameters

pet_skill
The name of the skill to use.

timeout
Try to skill for this long.



stack_skill
Stack up a skill for use

Parameters
stack_magic
The name of the magic to stack
charge
The charge to stack up to




process_skill

Launch the stacked skill.

Parameters
target
Options include enemy,
me which refers to the PET
master which refers to the PLAYER
pas_toward_target for use on close enemies I think
target_pos to drop the spell on the enemy
and my_pos for my own position.

timeout
Only try for this long, in milliseconds.




cancel_skill
Whatever your pet was trying to do, gets canceled at once.

Crafty pets can use this to best even PLAYERS.




skill_relax

This makes your pet REST.
It has one parameter,
on
is either true or false.

That'll do, pet. That'll do.



say_to_all

One parameter:
text

Well, a horse is a horse, of course, of course.



gift_item

The pet searches for an item, then returns it to master.
Only some pets have this enabled, because only they have that talent.




pet_pickup_item
Your pet grabs an item off the ground.
Only some pets have this enabled, because only they have that talent.



Note these options can be used for skill names throughout these documents.
all
basic
defence
smash
counter
windmill
lightningbolt
firebolt
icebolt
thunder
firstaid
ranged_attack
magnum_shot
finalhit
fireball
icespace
support_shot
arrow_revolver
mirage_missile
[SIZE="6"]
PUTTING IT ALL TOGETHER[/SIZE]

OK! So you know everything you need to make a pet AI!

... What do you mean it makes no sense. =/

OK, let's do two samples.


<rules>
<rule name="RULE 1">
<event name="now_targeting"/>
<conditions/>
<pattern>
<param_decl/>
<sequence>
<cmd name="wait" min="1000" max="1000"/>
</sequence>
</pattern>
</rule>
</rules>

Here we have a rule.
The rule is rule 1, it happens when the pet is targeting an enemy.
There are no other conditions.
The critter waits 1000 milliseconds (1 second) and that's all it does.

Super pet it is NOT.
But you can see how to structure the basic file.

It starts with <RULES>
Then each rule is defined in a <RULE name="______">
Each rule has an <event name="____" params = "XXXX"/>
This says what the event is, that will cause this rule to be followed.

Note the <conditions/> bracket
The slash at the end? it means there are NO conditions.

SOME conditions would look like this
<conditions>
--- condition 1 ---
--- condition 2 ---
</conditions>

Then comes the ACTION PATTERN
<pattern>

Declare parameters -
<param_decl/>
oh, that is short.

This is the literal sequence of actions we want to have taken.
<sequence>
<cmd name="wait" min="1000" max="1000"/>
</sequence>
Your orders are to wait. Between 1000 and 1000 milliseconds.
In other words, stand there for 1 second. Capice'?

</pattern>

End instruction pattern!

</rule>

End that rule!

</rules>

and end all rules, file done.



Now let's look at one that DOES something.

<rules>
<rule name="RULE 1">
<event name="attack" pet_attackable_skill="smash" down="true"/>
<conditions/>
<pattern>
<param_decl/>
<sequence>
<cmd name="stackmagic_attack" stack_magic="icebolt" charge="1" timeout="5000"/>
</sequence>
</pattern>
</rule>

---------
Rule 1 happens on an attack event...
with a couple restrictions -- it's when the pet attacks, the enemy is down, and the skill used was a smash.
It's a very specific event.

There's only one command in the sequence. Stack a magic icebolt attack, 1 charge, and timeout after 5 seconds (just in case something blindsides us)

That's the rule! If we smash something and knock it down, get an icebolt ready!
---------


<rule name="RULE 2">
<event name="attack" pet_attackable_skill="icebolt" down="false"/>
<conditions/>
<pattern>
<param_decl/>
<sequence>
<cmd name="prepare_skill" pet_skill="counter" try_cnt="0" timeout="5000"/>
</sequence>
</pattern>
</rule>

-----
Rule 2. It's another attack event.
After we attack, with an icebolt (enemy not downed), we follow this rule.

No conditions.
Prepare the skill Counter. Timeout after 5000 milliseconds.

That's rule 2! After we hit with icebolt, we get Counter ready!

----
<rule name="RULE 3">
<event name="attack" pet_attackable_skill="counter" down="true"/>
<conditions>
<condition name="target_state" state="blowaway"/>
</conditions>
<pattern>
<param_decl/>
<sequence>
<cmd name="stackmagic_attack" stack_magic="icebolt" charge="1" timeout="5000"/>
</sequence>
</pattern>
</rule>
</rules>
------
Rule 3 is another attack event.
After we attack with Counter, and the enemy IS downed, we do this rule.

There's a condition.
We only want to do this, if the enemy is in the Blow-Away state! If they aren't, then it's not the time for this rule.

Just one instruction. Stack an icebolt, 1 charge, and time out after 5 seconds just in case.

That's rule 3!

===========


So all that code boils down to three rules.


1. After the pet hits with a Smash and knocks the enemy down, it gets an icebolt ready.
2. After the pet hits with an icebolt(and the enemy is not knocked down), it gets a Counter ready.
3. After the pet hits with a Counter and knocks the enemy down, IF the enemy is blown back, it gets another icebolt ready.


This kind of pet will alternate rules 2 and 3!
It will go :

Smash attack -> Ice bolt -> Counter -> Ice bolt -> Counter... that's almost as good as some players! =P

You can make pets MUCH, much smarter and teach them to do all sorts of cool things... I may add good pet scripts to this guide later.

But for now, it's all hearsay and conjecture! Enjoy your early planning.

~Tolinar[/FONT]