The 3rd Age

The Battle for Numenor Mod

The Battle for Numenor Mod

This is one of the famous german mods for RotWK

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 - 6:28
Updated: Friday August 27, 2010 - 19:26
Views: 29239
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
A. Starting Simple (Object AI)

A1. 'AISpecialPowerUpdate'

The very first thing you can do, even as a beginner, is to implement a piece of code known as 'AISpecialPowerUpdate'.
There already is a tutorial on this subject by cahik_ which i will expand upon. You may want to read it first but it is not necessary.

Overview of 'AISpecialPowerUpdate' module.
Syntax (example):
              
Code
Behavior = AISpecialPowerUpdate SpecialWoundingArrow
    CommandButtonName = Command_SpecialAbilityWoundArrow
    SpecialPowerAIType = AI_SPECIAL_POWER_ENEMY_TYPE_KILLER
    SpecialPowerRange = 25
    SpecialPowerRadius = 50
    SpellMakesAStructure = Yes
    RandomizeTargetLocation = Yes
End



Now in detail:
              
Code
Behavior = AISpecialPowerUpdate SpecialWoundingArrow


As with all Behavior Code, the Behavior needs a tag ('SpecialWoundingArrow'), which can be anything you like but must be unique.
Something descriptive would be appropriate, but you can use 'XYZ' or whatever.

              
Code
CommandButtonName = Command_SpecialAbilityWoundArrow

  • This is the name of the CommandButton used, plain and simple.


              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_ENEMY_TYPE_KILLER

  • This is the kind of AI being used with the button. I will go into detail when and where to use each one later.


              
Code
SpecialPowerRange = 25

  • This is the range the AI looks for targets, if any. Usable if the CommandButton needs a single target.


              
Code
SpecialPowerRadius = 50

  • This is the range the AI looks for targets as well, Usable for powers that have an area effect rather than a single target.


              
Code
SpellMakesAStructure = Yes

  • This is possibly necessary for the AI to pick a suitable spot if the commandbutton creates a strucure (like the DwarvenCitadel Spell)


              
Code
RandomizeTargetLocation = Yes

  • This makes the AI not always pick the same spot/target when directing the SpecialPower ascociated with the used CommandButton



The use of 'AISpecialPowerUpdate' is limited though, for one by the limited number of unmodifiable 'SpecialPowerAIType' tags in the game. The other thing is that this Behavior overrides certain limitations that a normal human player would have when using that button.

  • The 'AISpecialPowerUpdate' does only check if the ascociated SpecialPower is unpaused. That's it.
  • If there are modelconditions defined in the CommandButton itself or in the SpecialPowerUpdate of the ascociated SpecialPower that usually restrict it's use, like for example 'ForbiddenConditions = MOUNTED', the AI completely ignores those restrictions/requirements and uses the CommandButton anyway. There are some tricks to get around this though. :P
  • Sometimes it seems as if the AI doesn't care if the unit in question even has the CommandButton in the CommandSet. As long as the CommandButton itself is defined somewhere and ascociated with a SpecialPower or WeaponSlot that the Object in question possesses, it WILL use the CommandButton, no matter if it is actually listed in the Object's Commandset! I cannot confirm when it happens, but it does.



Here is a list of usable 'SpecialPowerAIType's:


ToggleWeaponSets
              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_TOGGLE_MELEE_AND_RANGE

  • toggles weaponset when engaged in close combat, toggles back when melee is over and suitable infantry targets are available again

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_TOGGLE_SIEGE

  • toggles weaponset when engaged in close combat, often earlier than the Type above, especially if no Structures are in the vicinity; toggles back when melee is over and suitable Structure targets are available again



Activate Mount
              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_GOBLINKING_MOUNTED

  • toggles Mount Module ONCE, right after the unit's creation, if the SpecialPower is Unpaused.

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_TOGGLE_MOUNTED

  • seemingly does nothing



Activate FriendlyArmyAssist
              
Code
SpecialPowerAIType = AI_SPELLBOOK_ASSIST_BATTLE_BUFF

  • centers SpecialPower on own engaged hordes

              
Code
SpecialPowerAIType = AI_SPELLBOOK_BUFFTERRAIN

  • centers Taint/ElvenWoodSpecialPower on own engaged hordes

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_LEGOLAS_TRAINARCHERS

  • centers SpecialPower on own archer hordes

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_GIVEXP_AOE

  • centers SpecialPower on own hordes

              
Code
SpecialPowerAIType = AI_SPELLBOOK_ENSHROUDINGMIST

  • SHOULD center SpecialPower on own hordes, but seems to accomplish nothing



Activate EnemyArmyAttack
              
Code
SpecialPowerAIType = AI_SPELLBOOK_ASSIST_BATTLE_DEBUFF

  • centers on enemy horde

              
Code
SpecialPowerAIType = AI_SPELLBOOK_ARMY_BREAKER

  • centers on large enemy hordes

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_GOBLINKING_CALLOFTHEDEEP

  • centers SUMMON on enemy horde

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_LEGOLAS_ARROWWIND

  • centers AOE attack on enemy horde

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_TARGETAOE_SUMMON

  • centers SUMMON on enemy horde

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_GANDALF_WIZARD_BLAST

  • centers WizardBlast Style AOE attack on enemy horde

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_ELENDIL

  • seems to do NOTHING

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_RANGED_AOE_ATTACK

  • centers AOE attack on enemy horde



Activate SpecialTargetAttacks ;mostly Heroes
              
Code
SpecialPowerAIType = AI_SPELLBOOK_CITADEL

  • centers SUMMON on enemy horde

              
Code
SpecialPowerAIType = AI_SPELLBOOK_STRUCTURE_BASEKILL

  • centers SUMMON on enemy fortress

              
Code
SpecialPowerAIType = AI_SPELLBOOK_STRUCTURE_BREAKER_PREF_WALLS

  • centers SUMMON on enemy structures/walls

              
Code
SpecialPowerAIType = AI_SPELLBOOK_STRUCTURE_BREAKER

  • centers SUMMON on enemy structures

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_ENEMY_TYPE_KILLER_STRUCTURES

  • single attack on enemy structures

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_ENEMY_TYPE_KILLER_RANGED

  • single attack on enemy heroes, machines or monsters

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_ENEMY_TYPE_KILLER

  • single attack on enemy heroes, machines or monsters



Activate when damaged
              
Code
SpecialPowerAIType = AI_SPELLBOOK_HEAL

  • centers AOE healing on damaged own hordes

              
Code
SpecialPowerAIType = AI_SPELLBOOK_REBUILD

  • centers AOE healing on damaged own structures

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_BASIC_SELF_BUFF

  • activated when damaged

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_SELFAOEHEALHEROS

  • activated when surrounding Heroes are damaged

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_HEAL_AOE

  • SUPPOSED to activate when surrounding units are damaged



Activate SpecialTargetSpells
              
Code
SpecialPowerAIType = AI_SPELLBOOK_SHROUD_REVEAL

  • centers on enemy fortress position

              
Code
SpecialPowerAIType = AI_SPELLBOOK_TREE_KILLER

  • centers on trees

              
Code
SpecialPowerAIType = AI_SPELLBOOK_CAPTURE_CREEP

  • centers on Creep Structures

              
Code
SpecialPowerAIType = AI_SPELLBOOK_CALLTHEHORDE

  • seems to do NOTHING

              
Code
SpecialPowerAIType = AI_SPELLBOOK_BUFFECONOMYBUILDING

  • centers on own economy buildings

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_CAPTURE_BUILDING

  • targets objects that are CAPTURABLE

              
Code
SpecialPowerAIType = AI_SPELLBOOK_ALWAYS_FIRE

  • always fires. Seems to only work for SpellBook powers though.



Activate GeneralTargetAttacks ;units
              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_CHARGE

  • activates and targets enemies when near.

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_GOBLINKING_BATTLEFRENZY

  • seems not to achieve anything



Stances
              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_STANCEAGGRESSIVE

  • activates when object that is part of a team is instructed to attack/attackmove

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_STANCEHOLDGROUND

  • activates when object is instructed to defend. Mostly when BadlyDamaged.

              
Code
SpecialPowerAIType = AI_SPECIAL_POWER_STANCEBATTLE

  • activates when none of the above is triggered.



Another different module follows on the next page.
------------------------------------------------------------------------------------------------------------------------------

Comments

Display order: Newest first | Page: 1, 2

Prolong - Thursday July 29, 2010 - 9:21

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

Elrond99 - Sunday February 15, 2009 - 7: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 - 21: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 - 12:05

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

Sulherokhh (Team Chamber Member) - Thursday November 29, 2007 - 17: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 - 11:00

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

Sulherokhh (Team Chamber Member) - Wednesday October 3, 2007 - 23:07

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

Rob38 (Team Chamber Member) - Wednesday October 3, 2007 - 22: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 - 19: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 - 16: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:29:09