Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to: script Artificial Intelligence
#1
Silva's latest holy blessing gives us the power to write our own special moves AI (and with SomeoneElse on boat even the basic AI). I will try to give an overview here as to what this means exactly and how to do it. And I hope to update this as Silva progresses with adding features and I learn more tricks to abuse this (from you?). So please comment to make this a good reference for anyone to create some AI.

The whole thing works without editing the lf2.exe and will instead read your AI scripts at start up (and auto reload them if you are using the debug version, so there is no need to restart for changes to apply).To just play with custom AI from others, download the release version here. Drop the dll into your lf2 directory and also create a folder called AI to put the scripts into.To get started with creating your own AI, download the debug version here. Paste that dll into your lf2 directory. Starting your lf2.exe now will open up a console as well, giving you information about the running AI scripts. Now you can also create a folder called AI inside your lf2 directory which will contain your AI scripts. The scripts are written in Angel Script, which uses basic C syntax. All parts we need from it here are really easy. Also angel scripts are basically text files except their file ending is ".as", so you can edit and create them with any text editor you want. They should be named with the number of the id they shall be used for.

Every AI script will need to contain at least one of these functions:
The id() function - this replaces all the characters AI and gives you control over everything it does.
The ego() function - this function will be called by the original basic AI in case you do not use an id() function.

Obviously if you just want to make a melee character that simply uses certain special move inputs in a smart way you will only use the ego() function. Here is an example of a really simple AI script:
    AI-Code:
int ego(){
 if (self.hp < 400){
  DdJ();
 }
 return 0;
}
This code could be useful for John as he will try to heal himself whenever his hp is below 400. But the AI for real attacks will require a little more complex conditions to be executed at the right time. Note that the ego() function is not the main AI function of your character and thus needs to 'report back' to the function it has been called from. This is done with return 0;. The 0 will give the control back to the basic AI (the id() function). If you write return 1; you can retain control in the ego() function. If you create your own functions later on they may return other values depending on their purpose.

So here is everything you will need and more:
CONDITIONS (Click to View)
OPERATORS (Click to View)
VARIABLES (Click to View)
This is as far as you will need to read for creating simple AI scripts, if you already have something working and want to create more complex things: read on. If you have trouble with your script: read the error and debugging section.
FUNCTIONS (Click to View)
DEBUGGING (Click to View)
TARGET LOADING (Click to View)
Reply


Messages In This Thread
How to: script Artificial Intelligence - by YinYin - 06-11-2012, 01:42 PM



Users browsing this thread: 1 Guest(s)