AI Patrol

From The DarkMod Wiki
Jump to navigationJump to search

Introduction

This article describes the ways how the mapper can get his/her AI's to move around in their map. Regardless of which method you use, you should understand basic Pathfinding. Read that article first.

There are several methods of getting your AI to move around your map.

  • Path_corners
  • Conversations
  • Scripting

Path_corners

The typical choice the mappers use path-corners. Using them is quite straight forward. Information how to set up path_corners is given here A - Z Beginner Full Guide Page 4 and here Path Nodes

Conversations

Conversation entities can be used to move AI too. See information in the Conversation article. Note that in TDM v1.03 the AI returns to the original place it was before the conversation, when the conversation end. This means that you can make the AI walk around, but it will not stay there where you sent it when the conversation ends.

Scripting

Scripting is a powerful tool to control all kinds of things. AI movement can be also controlled with scripting.

Example AI control

  • Place an AI in your map. Name it "ai".
  • Place a path_corner in your map. Name it "destination".
  • Place a atdm:target_callscriptfunction. Name it "call_ai_walk_script". Add spawnarg "call" "ai_walk_script"
  • Place a switch in your map, which targets the above atdm:target_callscriptfunction.
  • Create an ordinary textfile mymapname.script and place it in your /maps folder.
  • Put the following info in the script file:
void ai_walk_script() 
{
$ai.moveToEntity($destination);
}

When the player pulls the lever, the AI walks to the entity destination and stays there. You can add more levers which send the AI to different locations. Note: it was observed in TDM v1.03 that sometimes, if a script is called from a conversation, the AI will occasionally not move to the position even if the script is running. This can be fixed by adding a small delay in the beginning of the script (sys.wait(1);).

Mappers can also use $ai_name_here.moveToPosition("123,456,768"); and replace the coordinates where the AI should go. (Not tested.)

Other AI control commands exist, like $ai_name_here.turnToEntity(entityname);, which makes the AI to turn towards the specified entity.