Tutorial Animals Scripting Zoo Tycoon 2 Archived

Behavior Editing Tutorial

Z

by Zooasaurus

Published
14/11/2026
History
History
Reading time
5 min read
Views
0 views
Comments
0 comments
Like
Originally published by Zooasaurus on ZT2 Designing Centre in December 2007.
On this page

Zooasaurus’ Behavior editing tutorial.

For advanced coders.

This is a tutorial designed for those that already have the basic coding down, and wish to know more.

In this tutorial, you will find out how to add and subtract behaviors from animals. It will include everything from pack hunting behaviors to swimming underwater.

Types of Behaviors

Now, behaviors are controlled through the .beh and .tsk files under ai.

There are two basic types of behaviors.

  • Type 1 includes such behaviors as interbreeding and herding, among others. These behaviors are only controlled in the ai, and don’t need anything else for them to work.
  • Type 2 behaviors are behaviors like swimming, climbing, laying eggs, play fighting, etc . These required more advanced coding, from other areas, like the bfms and xmls under entities/units/animals/ai.

Coding Type 1 Behaviors

I’ll first teach you how to code the type 1 behaviors.

The .beh File

This is an example of a behavior. This particular one is taken from the Bengal Tiger.

It’s from the .beh file.

<Sleep>
    <subjects>
        <TigerBengal/>
    </subjects>
    <behaviors>
        <BFBehRandomSet>
            <randomSets>
                <SleepSide weight="50"/>
                <SleepPaws weight="50"/>
            </randomSets>
        </BFBehRandomSet>
    </behaviors>
</Sleep>

It has the starting code <Sleep> and closing code </Sleep>, the behaviors name.

It’s type 1 because there is no animation reference.

The following behavior is type 2.

<SleepSide>
    <subjects>
        <TigerBengal/>
    </subjects>
    <behaviors>
        <BFBehAnimate targetAnim="Sleep_Idle" playTime="20"/>
    </behaviors>
</SleepSide>

It has an animation, “Sleep_Idle” which is in the bfm.

The .tsk File

Codes in the .tsk files are abit different though. The code for sleep is:

<BFAITaskTemplate Name="Sleep" UniqueID="TigerBengal:Sleep">
    <BFAICreateData>
        <Subjects>
            <TigerBengal/>
            <Qualifiers_AND onLand="true" isSwimming="false"/>
        </Subjects>
        <Targets>
            <self/>
        </Targets>
        <Objects/>
    </BFAICreateData>
    <BFAIEvalData>
        <BFAIAttributeFloatMap rest="-35"/>
    </BFAIEvalData>
    <BFBehExecTask>
        <ZTBehViewEvent viewKey="Pos_1"/>
        <ZTBehFeedback>
            <ZTFeedbackData>
                <ZTActionInfo locID="animalactions:Sleeping"/>
            </ZTFeedbackData>
        </ZTBehFeedback>
        <BFBehPlaySet behSet="Sleep"/>
    </BFBehExecTask>
    <BFAICompletionData>
        <BFAIAttributeFloatMap rest="-100"/>
        <BFAITokenList>
            <BFAIToken Name="t_Stretch" GiveTo="subject" Timeout="5"/>
        </BFAITokenList>
        <BFBehExecTask>
            <ZTBehFeedback>
                <ZTFeedbackData>
                    <ZTEmoticonInfo emoticonName="EmoteAnimalRestVeryGood"/>
                </ZTFeedbackData>
            </ZTBehFeedback>
        </BFBehExecTask>
    </BFAICompletionData>
</BFAITaskTemplate>

Everyone of these codes starts with <BFAITaskTemplate> and ends with </BFAITaskTemplate>.

From what I know, where it says UniqueID= the resulting code is a reference to a beahvior in the .beh.

Adding Behaviors

To add one of these behaviors, simply add the code in the right place. it dosen’t matter where in the file you add it, but the codes have to match. And you need to add the corresponding code in the .tsk file for it to work.

Note

Not all .beh codes have a .tsk code, so don’t worry if you can’t find one.

Coding Type 2 Behaviors

Type 2 codes are more difficult, as you’ll require multiple files and an understanding of what animations are used.

These are the codes required for the Deinosuchus to swim underwater:

.beh file:

<Surface_Submerge>
    <subjects>
        <Deinosuchus/>
    </subjects>
    <behaviors>
        <BFBehLocoSwitchSet switch="false">
            <behaviorTable>
                <water behSet="Submerge"/>
                <underwater behSet="Surface"/>
            </behaviorTable>
        </BFBehLocoSwitchSet>
    </behaviors>
</Surface_Submerge>

<Submerge>
    <subjects>
        <Deinosuchus/>
    </subjects>
    <behaviors>
        <ZTBehFeedback>
            <ZTFeedbackData>
                <ZTActionInfo locID="animalactions:Submerging"/>
            </ZTFeedbackData>
        </ZTBehFeedback>
        <BFBehWander minPlayTime="7" maxPlayTime="15" avoidLand="true" minDepth="2" maxDepth="10" avoidEntityRadius="8">
            <avoidEntityTypes>
                <TrainingArea/>
            </avoidEntityTypes>
        </BFBehWander>
    </behaviors>
</Submerge>

<Surface>
    <subjects>
        <Deinosuchus/>
    </subjects>
    <behaviors>
        <ZTBehFeedback>
            <ZTFeedbackData>
                <ZTActionInfo locID="animalactions:Surfacing"/>
            </ZTFeedbackData>
        </ZTBehFeedback>
        <BFBehWander minPlayTime="7" maxPlayTime="15" avoidLand="true" minDepth="0" maxDepth="0" avoidEntityRadius="8">
            <avoidEntityTypes>
                <TrainingArea/>
            </avoidEntityTypes>
        </BFBehWander>
    </behaviors>
</Surface>

.tsk file:

<BFAITaskTemplate Name="Surface_Submerge" TaskDelayMin="30" TaskDelayMax="60" distanceInfluenced="false" UniqueID="Deinosuchus:Surface_Submerge">
    <BFAICreateData>
        <Subjects>
            <Deinosuchus/>
            <Qualifiers isSwimming="true"/>
        </Subjects>
        <Targets>
            <water/>
        </Targets>
        <Objects/>
    </BFAICreateData>
    <BFAIEvalData fixedScore=".002"/>
    <BFBehExecTask>
        <BFBehPlaySet behSet="Surface_Submerge"/>
    </BFBehExecTask>
    <BFAICompletionData/>
    <BFAIFailureData>
        <BFBehExecTask>
            <BFBehPlaySet behSet="FailureSet"/>
        </BFBehExecTask>
    </BFAIFailureData>
</BFAITaskTemplate>

The Main AI XML File

Although an animation is not referenced, many are used to make this work. There is also a section in the main Deinosuchus main ai .xml file required for the behavior.

Important

You’ll have to add this to your animal in order for the animation to work.

This is the code:

<BFNamedBinder binderName="underwater" required="1">
    <instance>
        <BFLocoAnimate version="1">
            <stop name="TreadWaterSub" />
            <slow name="SwimSub" >
                <anim name="Swim_2SwimSub" yaw="1.0" />
                <anim name="SwimSub_Ahead" yaw="1.0" pitch="0.5" />
            </slow>
            <medium name="SwimSub" >
                <anim name="Swim_2SwimSub" yaw="1.0" />
                <anim name="SwimSub_Ahead" yaw="1.0" pitch="0.5" />
            </medium>
            <fast name="SwimSub" >
                <anim name="Swim_2SwimSub" yaw="1.0" />
                <anim name="SwimSub_Ahead" yaw="1.0" pitch="0.5" />
            </fast>
            <stalk name="SwimSub" >
                <anim name="Swim_2SwimSub" yaw="1.0" />
                <anim name="SwimSub_Ahead" yaw="1.0" pitch="0.5" />
            </stalk>
            <evade name="SwimSub" >
                <anim name="Swim_2SwimSub" yaw="1.0" />
                <anim name="SwimSub_Ahead" yaw="1.0" pitch="0.5" />
            </evade>
            <glide name="SwimSub" minAnimSpeed="0.5" maxAnimSpeed="1.5" >
                <anim name="Swim_2SwimSub" yaw="1.0" pitch="0.5" acceleration="-0.1" />
                <anim name="SwimSub_Ahead" yaw="1.0" pitch="0.5" />
            </glide>
            <attack name="SwimSub" >
                <anim name="Swim_2SwimSub" yaw="1.0" />
                <anim name="SwimSub_Bite" yaw="1.0" pitch="0.5" />
            </attack>
        </BFLocoAnimate>
    </instance>
</BFNamedBinder>
</binder>
</BFBinder>

It’s connected to other codes, but this is the only neccessary part.

Note

All major locomotion behaviors require similar codes.

The BFM File

The final step to making this work is add the actions from the animal your taking the behaviors from bfm and adding them your animal’s bfm.

Important

If the animal your using isn’t similar. You’ll have to replace the animation used with one your animal uses.

If you have any questions, feel free to pm me at Zt2 Desigining Center, Zoo Tycoon Volcano, ZooMania, or any other site you know I’m on.

Comments 0

Log in to join the conversation.

No comments yet.

Loading the history…
Tutorial Archived

The How To's of Gift Making

by MarineManiac

This tutorial teaches how to use only cart based animals, but can be applied to shops.

  • Zoo Tycoon 2
  • Objects & Scenery
  • Scripting
Reading time
6 min
Comments
0
Tutorial Archived

Path Tutorial

by ShenTirag

Learn how to create your own paths for Zoo Tycoon 2!

  • Zoo Tycoon 2
  • Objects & Scenery
  • Scripting
Reading time
5 min
Comments
0

Modal Title