The 3rd Age

Men's Knives

Men's Knives

Good mod in BFME2?With more Factions? and its coming? It's MEN'S KNIVES!

Button for The 3rd AgeButton for The Dwarf HoldsButton for The Elven AllianceButton for Helm's Deep Last HopeButton for GothmogtheOrcButton for BFME+Button for The Four AgesButton for HDR HeadquartersButton for Middle Earth CenterButton for Project Perfect Mod

Become an affiliate!

   

Quick Lists

Top Rated Popular New Updated Last Comments Users

Register and log in to move these advertisements down

In-depth AI Coding

Avatar of Sulherokhh

Sulherokhh

Category: Code
Level: Expert
Created: Wednesday October 3, 2007 - 8:28
Updated: Friday August 27, 2010 - 21:26
Views: 21648
Summary: The beginning of a comprehensive guide to AI-modding for BfME2

Rating

Staff says

4.8

Members say

4.9

Average

4.9/5.0

20 votes

Page 1 2 3 4 5 6 7 8 9 10 11
B. Advanced AI modding (Object AI)

This section contains a lot of specialized modules, as well as a custom approach on implementing it for the AI (and NOT for the player). Knowledge of LUA-scripting, ModelConditions, the works of Upgrades and a general feel for all Object-code is a prerequisite.

I will start with the basic setup. After that i will give several examples on how to apply this basic principle with several different modules working in concert.


B1. The Basic Setup

The file 'object.ini' (location: data\default\object.ini)
This file contains the default settings that are applied to ANY kind of object, UNLESS overridden by the actual object code. I won't bother with most of it. Only the contents related to the AI matter are reprinted here for convenience. Best you open up the file yourself.

              
Code
Object DefaultThingTemplate
    ...
    InheritableModule
        ; This will farm out any experience we gain to nearby units.
        Behavior = ShareExperienceBehavior ModuleTag_DefaultShareExp
            Radius = 100.0
            ObjectFilter = ANY +HERO
            DropOff     = 1.0 ; Must be one or zero.
        End
    End
    ...
    InheritableModule
        Behavior = TemporarilyDefectUpdate ModuleTag_TemporarilyDefectUpdate
            ;**************** IMPORTANT *************************
            DefectDuration = 30000
            ; VERY VERY IMPORTANT, YOU MUST Make sure that DefectDuration
            ; is LESS than the ReloadTime of the special power(s) that trigger defection.
            ;**************** IMPORTANT *************************
        End
    End
    ...
    InheritableModule
        Behavior = AttributeModifierUpgrade ModuleTag_EasySoloBonus
            TriggeredBy = Upgrade_EasyAISinglePlayer
            AttributeModifier = EasyAISinglePlayer_Bonus
        End
    End
    ...
    InheritableModule
        Behavior = DamageFilteredCreateObjectDie ModuleTag_BecomeUndeadWhenKilled
            DamageTypeTriggersInstantly = BECOME_UNDEAD
            DamageTypeTriggersForDuration = BECOME_UNDEAD
            PostFilterTriggeredDuration = 10000
            CreationList = OCL_BecomeUndead
        End
    End
    ...
End


In detail:

              
Code
InheritableModule
End

  • This is the basic Module that lets anything inside it be inherited by EVERY SINGLE OBJECT in the game!!!


              
Code
Behavior = ShareExperienceBehavior ModuleTag_DefaultShareExp
End

  • This module lets experience collected by this object rub off to nearby objects. Only used for Heroes right now. Unimportant for AI but still interesting on it's own.


              
Code
Behavior = TemporarilyDefectUpdate ModuleTag_TemporarilyDefectUpdate
End

  • This module is needed so any kind of object can Defect when targeted by for example 'Dominate'.


              
Code
Behavior = DamageFilteredCreateObjectDie ModuleTag_BecomeUndeadWhenKilled
End

  • This behavior makes objects 'transform' into Wights when targeted by 'MorgulBlade'


              
Code
Behavior = AttributeModifierUpgrade ModuleTag_EasySoloBonus
End

  • This is the really juicy stuff. There are several of these in object.ini. Originally they were used to provide Cheats for different difficulty levels. The AttributeModifiers in these modules actually accomplish NOTHING at the moment. But you can change that of course. What is really interesting is that you can find here (almost) all the upgrades that ANY AIPlayer is born with.

Thats:
              
Code
Upgrade_EasyAISinglePlayer
Upgrade_MediumAISinglePlayer
Upgrade_HardAISinglePlayer
Upgrade_EasyAIMultiPlayer
Upgrade_MediumAIMultiPlayer
Upgrade_HardAIMultiPlayer


Now, go into 'upgrade.ini' and add the following two PLAYER-upgrades to the list. They are used by the 'BrutalAI' but you need to list them so you can use them too:
              
Code
Upgrade_BrutalAISinglePlayer
Upgrade_BrutalAIMultiPlayer


And now comes the Juicy part. You will want to have a single Object-Upgrade that always signifies that this particular Object is controlled by the AI.
So, define an appropriate OBJECT-upgrade (like Upgrade_ObjectUnderAIControl) and insert the following module inside 'object.ini':

              
Code
InheritableModule
    Behavior = ObjectCreationUpgrade ModuleTag_IamAI
        TriggeredBy = Upgrade_EasyAISinglePlayer Upgrade_EasyAIMultiPlayer Upgrade_MediumAISinglePlayer Upgrade_MediumAIMultiPlayer Upgrade_HardAISinglePlayer Upgrade_HardAIMultiPlayer Upgrade_BrutalAISinglePlayer Upgrade_BrutalAIMultiPlayer            
        Delay = 500
        GrantUpgrade = Upgrade_ObjectUnderAIControl
    End    
End


This way EVERY SINGLE OBJECT in the game, if used by an AI-Player, will have this OBJECT-Upgrade.
It will be used as a trigger for things that you just don't want triggered automatically for a HUMAN-Player!



Now let's put this new AI-upgrade to good use! Read on!

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

Comments

Display order: Newest first | Page: 1, 2

Prolong - Thursday July 29, 2010 - 11:21

Very nice guide, even though it never got finished there is still a ton of great information here.

Elrond99 - Sunday February 15, 2009 - 8:52

Thanks for updating the Tutorial
It´s great to hear that it´s possible to make a new AI from scratch

Can´t wait for section F, custom AI scripts, that sounds really interesting
Especially since I know D and E already ;)

Sulherokhh (Team Chamber Member) - Saturday February 14, 2009 - 22:19

After 'D. The Faction Base and Fortress', i guess.
If you are asking for a date, you are asking the wrong guy. I don't have one. I work on modding related stuff mostly when i find the time and the mood strikes me. It's supposed to be fun, right? :)

Edit: But i might do it before the fortress and base setup. Depends on, well, which kind of work is going to be most interesting to me at the time. Scripts should be easier to do then the Basebuilding stuff, but a bit more to write as well, at least if i am going to do it right. I am starting to ramble... :O

jakonic - Saturday February 14, 2009 - 13:05

when will be finished Spell Purchase Scripts???please answer

Sulherokhh (Team Chamber Member) - Thursday November 29, 2007 - 18:26

I sure will...

Edit: Do you have any particular requests? If i have done it already, it shouldn't be hard to post a solution here. If it's not, chances are that i was going to look into it anyway. Except for the general skirmishsetup and bases, since those will require extesive explanations which i was planning to do anyway when i find the time.

So shoot! :)

Rob38 (Team Chamber Member) - Thursday November 29, 2007 - 12:00

This is by far one of my favorite tutorials on T3A! Please continue to add more :)

Sulherokhh (Team Chamber Member) - Thursday October 4, 2007 - 1:07

I am glad you can put it to use, Rob! Your feedback means a lot to me. :D

Rob38 (Team Chamber Member) - Thursday October 4, 2007 - 0:27

Amazing! I also found a way to recognize if a player is controlled by the AI, but this looks to be a much easier method to use. Thank you for all your wonderful knowledge as there is some really cool stuff in here.

Sulherokhh (Team Chamber Member) - Wednesday October 3, 2007 - 21:18

I'll split it up. Let's see what would be a good way. - Edit: Done. I hope you like it.

Crashdoc - Wednesday October 3, 2007 - 18:48

Nice findings and interesting ways to use them. Thanks for sharing the knowledge!

Go to top

 

"One site to rule them all, one site to find them,
one site to host them all, and on the network bind them."

 
0:05:51