# brainAI DOCUMENTATION

Version 5, codename "Krang", by Austin Heilman.

## Script Types

The following scripts are used by the brain core.
Combat
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_ENGAGED and SYSEVENT_DAMAGED
Explanation
This nerve operates while the NPC is in combat and should control all combat related activities.
Config Settings
- This nerve's 'AIScripts' keyword is 'CombatScript' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/combat.src'
CycleScript
npc, settings, scripts
Script Type (Priority)
Critical
Trigger
This script is run every time the brain core makes a tick (loop).
Explanation
The cycle script is used if you want to have the NPC perform an action every time it ticks. Note that this script will not be run if the NPC is in sleep mode.
Config Settings
- This nerve's 'AIScripts' keyword is 'CycleScript' - This nerve type does not have any AISettings used in the brain core.
Example
See '/complete/exampleNPC/cycleScript.src'
DblClick
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_DOUBLECLICKED
Explanation
This nerve operates when the NPC has been double clicked by a player.
Config Settings
- This nerve's 'AIScripts' keyword is 'DblClick' - This nerve uses an 'AISetting' entry called 'DblClickRange'
Example
See '/complete/exampleNPC/DblClick.src'
Disengaged
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_DISENGAGED
Explanation
This nerve operates when another mobile stops targetting the NPC for combat.
Config Settings
- This nerve's 'AIScripts' keyword is 'Disengaged' - This nerve type does not have any AISettings used in the brain core.
Example
See '/complete/exampleNPC/disengaged.src'
EnterArea
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_ENTEREDAREA
Explanation
This nerve operates when another mobile has entered the NPC's area.
Config Settings
- This nerve's 'AIScripts' keyword is 'EnterArea' - This nerve uses an 'AISetting' entry called 'AreaSize'
Example
See '/complete/exampleNPC/enteredArea.src'
GoneCriminal
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_GONE_CRIMINAL
Explanation
This nerve operates when another mobile has become either a criminal or a murderer inside of the NPC's area.
Config Settings
- This nerve's 'AIScripts' keyword is 'GoneCriminal' - This nerve uses an 'AISetting' entry called 'AreaSize'
Example
See '/complete/exampleNPC/goneCriminal.src'
Init
npc, settings, scripts
Script Type (Priority)
Critical
Trigger
Runs when the NPC is created.
Explanation
This script is responsible for initializing an NPC. This includes the name, equipment, etc.
Config Settings
- This script's 'AIScripts' keyword is 'Init' - This script type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/init.src'
ItemGiven
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_ITEM_GIVEN
Explanation
This nerve operates when a player has dragged an item onto the NPC.
Config Settings
- This nerve's 'AIScripts' keyword is 'ItemGiven' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/itemGiven.src'
LeftArea
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_LEFTAREA
Explanation
This nerve operates when another mobile has left the NPC's area.
Config Settings
- This nerve's 'AIScripts' keyword is 'LeftArea' - This nerve uses an 'AISetting' entry called 'AreaSize'
Example
See '/complete/exampleNPC/leftArea.src'
LookAround
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
This nerve begins running after the NPC's init script has run. The nerve is automatically started again when the NPC leaves sleep mode.
Explanation
This script is used to maintain a list of mobiles / items that the NPC is watching. This nerve communicates with npcWatchList.inc. This nerve should handle all List*() POL core function calls. If this nerve is running, the NPC will not be allowed to enter sleep mode.
Config Settings
- This nerve's 'AIScripts' keyword is 'LookAround' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/lookAround.src'
Listen
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_SPEECH and SYSEVENT_GHOST_SPEECH
Explanation
This nerve operates when another mobile has spoken.
Config Settings
- This nerve's 'AIScripts' keyword is 'Listen' - This nerve uses an 'AISettings' entry called 'HearSpeech'. If enabled it will accept normal speech events. - This nerve uses an 'AISettings' entry called 'HearGhosts'. If enabled it will accept ghost speech events.
Example
See '/complete/exampleNPC/listen.src'
Merchant
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
SYSEVENT_MERCHANT_BOUGHT and SYSEVENT_MERCHANT_SOLD
Explanation
This nerve operates after the NPC has made a sale or purchase using the POL core Send(Sell/Buy)Window() function.
Config Settings
- This nerve's 'AIScripts' keyword is 'Merchant' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/merchant.src'
Restart
npc, settings, scripts
Script Type (Priority)
Critical
Trigger
POL startup POL core function Restart()
Explanation
This script is run on the NPC when POL starts up or the POL core function Restart() was used on the NPC. This script needs to be used with npcNerves.inc to stop all nerves.
Config Settings
- This script's 'AIScripts' keyword is 'Restart' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/restart.src'
Sleep
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
No events have been received after a certain number of ticks (loops).
Explanation
This nerve operates if the NPC has gone over a certain number of ticks and has either: 1. Not received any POL core SYSEVENT_* events. 2. Not received any NPCEVENT_* that have WAKEUP set to true. This nerve will run until the above conditions have been met. It is the responsibility of the sleep script to stop other nerve scripts that no longer need to run. This nerve should loop and handle various things such as wandering with a high delay on the loop. This nerve should send minimal commands to the brain to reduce shard load.
Config Settings
- This nerve's 'AIScripts' keyword is 'Sleep' - This nerve uses an 'AISettings' entry called 'IdleTicks'.
Example
See '/complete/exampleNPC/sleep.src'
ShouldWatch
npc, mobile, settings
Script Type (Priority)
Critical
Trigger
When called in another brain script with NPC_ShouldWatch() in npcWatchList.inc
Explanation
This script is not directly used by the brain. This script works as a hook to determine if a mobile should be added to the NPC's watch list and if its presence should bring the NPC out of sleep mode in its 'EnterArea' nerve. This script should return 1 if the NPC should watch the mobile and 0 if not. If the NPC has no 'ShouldWatch' script then it is assumed the mobile should be watched.
Config Settings
- This script's 'AIScripts' keyword is 'ShouldWatch' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/ShouldWatch.src'
Virtual
npc, nerve_name, event, settings, scripts
Script Type (Priority)
Nerve Script
Trigger
The NPC has received an event that no other nerve types handle.
Explanation
The virtual nerve handles any events sent to the NPC that no other nerve types handle. This is used as an extension to the brain core's eventParser.inc file.
Config Settings
- This script's 'AIScripts' keyword is 'Virtual' - This nerve type does not have any 'AISettings' used in the brain core.
Example
See '/complete/exampleNPC/virtual.src'