T4 Modules Howto Guide/AI
From Tales of Maj'Eyal
Your NPCs need an AI to act. Fortunately for you, the AI class already defines everything that is needed, see the table.
| Part | Explanation |
|---|---|
| name | the name that the self:runAI() function will call |
| function(self) | Where you put what the AI does |
Even better, your new AI can call another new AI (or one of the preexisting ones).
newAI("morale_flee", function(self)
if self.morale_life then
if self.life < self.morale_life then
if not self.energy.used then self:runAI("flee_dmap") end
end
end
end)
Now if you call self:runAI("morale_flee") - preferably in another AI definition such as "dumb_talented_simple" (or your "newfangled_AI") and NOT in NPC.lua - your creatures will flee if reduced below their morale_life value.
Go back to T4 Modules Howto Guide