Ai Helper
The Ai helper file in SOMA is script/helpers/helper_ai.hps.
AI helpers call entity components for movement, pathfinding, senses, voices and head tracking. Pathfinder_MoveToNode requires an entity with a Pathfinder component and broadcasts EndOfPath when its path completes.
Contents
Before you start
- Open the map script inside your own mod. Keep its generated includes,
cScrMap : iScrMapclass and callback structure. See Add your first script if you have not edited a map script yet. - Add the helper include shown below alongside the script’s other includes.
- Read the stock example before copying its calls: named entities, voice subjects, materials and callbacks must belong to the map or resources you are using.
Follow the stock example
#include "helpers/helper_ai.hps"
Pathfinder_MoveToNode
Moves an entity containing a Pathfinder component to a node. The entity message eLuxEntityMessage_EndOfPath is broadcasted when complete.
| Parameter | Meaning |
|---|---|
asEntityName |
name of the entity with the pathfinder. |
asNodeName |
name of the node to move to. |
asCallbackFunc |
The name of callback called when end is reach. Syntax: void Func(const tString& in asEntityName, bool abReachedEnd) |
afUpdateFreq |
The number of times per second that the path will be updated. O or below means never update. |
abExactStopAtEnd |
If the goal node should be hit exactly. |
asResultCallbackFunc |
The name of callback called when the pathfinding has been performed. Syntax: void Func(bool abSuccesful) |
In maps/chapter04/04_02_tau_inside/04_02_tau_inside.hps, SOMA calls Pathfinder_MoveToNode as follows.
Pathfinder_MoveToNode("Leviathan", "LeviathanTarget");
| Parameter | Value in this stock call |
|---|---|
asEntityName |
"Leviathan"
|
asNodeName |
"LeviathanTarget"
|
This is an excerpt from that stock script; its referenced names and variables belong to that script.
Pathfinder_Track_Add
Adds a track node to be followed.
| Parameter | Meaning |
|---|---|
asEntityName |
name of the entity with the pathfinder. |
asNodeName |
Name of the path node to be added. |
afMinWaitTime |
minimum time before the entity moves to the next node. |
afMaxWaitTime |
maximum time before the entity moves to the next node. If <0, then the value will be same as afMinWaitTime |
asAnimName |
animation played when at node, per entity. |
abLoopAnim |
if the animtion should be looped, per entity. |
In maps/chapter04/04_01_tau_outside/04_01_tau_outside.hps, SOMA calls Pathfinder_Track_Add as follows.
Pathfinder_Track_Add("LightBot","LightNode_"+i);
| Parameter | Value in this stock call |
|---|---|
asEntityName |
"LightBot"
|
asNodeName |
"LightNode_"+i
|
This is an excerpt from that stock script; its referenced names and variables belong to that script.
Pathfinder_Track_Start
Starts a track
| Parameter | Meaning |
|---|---|
asEntityName |
name of the entity with the pathfinder. |
abLoop |
if the path should loop |
afUpdateFreq |
the frequency at which the path is recculated |
asEndOfTrackCallback |
Callback called when path is over. Syntax: void MyFunc(const tString& in asEntityName) |
Check your change
Save the script and restart the map in development mode with F5. If the script fails, open F1 and use Show Error List or Show HPL Log. See the development loop for the launch and debugging steps.