No categories assigned

AI:BrainTutorialLua

Revision as of 17:53, 29 August 2013 by Jabantiz (talk | contribs) (Created page with "Creating a new brain in lua will allow you to override the default AI, it will not allow you to extend the default AI however. You can change the script and reload it without ha...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Creating a new brain in lua will allow you to override the default AI, it will not allow you to extend the default AI however. You can change the script and reload it without having to recompile and restart the server however. In this tutorial I will show you how to create a lua AI that will duplicate the default AI code in the server core.

Set Up the Spawn Script

First thing you need to do is tell the spawn to use the AI defined in the lua script, this is done by calling SetLuaBrain(), you can also tell the script how often the AI code needs to run with SetBrainTick()

function spawn(NPC)
	SetLuaBrain(NPC)
	SetBrainTick(NPC, 200)
end

You will also want to make sure the brain is set when they respawn

function respawn(NPC)
	spawn(NPC)
end

Finally you need to add the "Think" function, this will be called every time the AI code needs to be run. The server will pass 2 parameters to this function, the first is the NPC this spawn script is attached to, the second is the NPC's current target.

function Think(NPC, Target)

end

We are now ready to program the AI.

Programing The New Brain