[2.2]Programmable AI via scripting - Boop - 06-08-2012
Go to this thread for updates: https://www.lf-empire.de/forum/showthread.php?tid=10945
Quick Steps! (Thanks to Azriel)
Quote:quick steps:
1. put the dll in the lf2 folder (i.e. /lf2/ddraw.dll).
2. make a folder "ai" in the lf2 folder (i.e. /lf2/ai)
3. in this ai folder, any [id].as files ([id] being the id of ur char) will be used as an ai script for ur char, so you'll have 13.as for an id 13: char.
4. start coding.
2.2:
2.1:
2.0:
Another big update. Here's Someone Else's post:
(06-30-2012, 01:36 PM)Someone else Wrote: Time for an update:
Presenting version 2.0:
-
- Now using AngelScript, this means more syntax and more speed.
-
- Scripts are now compiled. This doesn't mean much, but if you plan on modifying scripts, while you are running LF2, this only works in the debug version.
- You now use preprocessor directives, #include and #if-#endif.
- The script files now have a ".as" extension instead of the previous ".chai" extension.
- Actually useful error messages.
- You can define global, functions, variables and classes, within your scripts. They can help you speed things up.
- Functions are now defined as '<return-type> <function-name>([<parameter-type> <parameter-name>,...]){<function body>};'.
- If a function doesn't return a value, you can use 'void' as a return type.
- It is no longer enough to define variables as 'var <variable-name>[ = <initial-value>]'. You must define them as '<variable-type> <variable-name>[ = <initial-value>]'.
- Classes are defined as '<class-name> {<functions-and-variables>};'.
- Build in types are, void, bool, int8, int16, int/int32, int64, int8, uint16, uint/uint32, uint64, float, double and string.
-
- up, down, A, J, D now have the same parameters as left and right had.
- There are now two main functions, the ego and the id.
-
- ego is defined as 'int ego()', and is basically what we had.
- id is defined as 'void id()', and is the most basic AI. You will have to do everything yourself.
- If you define id, the game will not call ego. You can either keep all functionality within id, or call ego from within id.
- When you are using id, you will have to "release" a key, using for example 'J(0,0);'. Otherwise the AI will keep holding/pressing it.
Download: http://www.mediafire.com/?pxd026nqoqgw0
Release, is the version you should use, when you actually play the game. Debug is for when you are writing your code.
The source code is available too. You'll need Visual C++ Express 2010, directX SDK 2007 and AngelScript 2.23.1.
Depending on where you install them you might have to change some of the paths in the project.
AngelScript should be compiled with the same code generation options as the DLL.
Lot's of things changed, performance is awesome now. I tested it with 100 bandits and in all of them had a for loop and had 0 lag  . Wait for YinYin to update things.
1.2:
- Fixed vrest for yinyin (i guess more people as well)
- added type
- made self and target global so they can be accessed via fucntions without lots of weird hacks (looking at you azriel) (might not work)
- Changed left and right. Now its left(int holding, int left) (same for right). Figure out how it works, or wait for YinYin. If you just want the old functionality back then just use left(1,0); and it'll be just like before.
- added reserve. Might be useful for someone
Download:
[attachment=2863]
To lazy to make a release one, console isn't that annoying. Live with it  . I've given Someone Else the source so he can play around with it and maybe implement anglescript(or not, don't blame him if he doesn't  ).
1.1:
1.1
Updates: - Added velocities (x_velocity, y_velocity, z_velocity)
- Added clone, -1 if not clone, some other random number if it is (2 or 3 usually but not always)
- Fixed loadTarget always returning -1
- Added vrest and arest. YinYin says vrest is buggy for him - Works fine for me... Need more testers =]
The velocities are doubles, I'd recommend avoid using them if you can because floating point arithmetic is slow.
Download:
Debug: [attachment=2855]
Debug only for now until vrest/arest are confirmed 100% working  1.0:
1.0 Release
We are finally here! The 1.0 release is here, this breaks all backwards compatibility (again) - hopefully for the last time. All performance issues have been fixed. Changes to the syntax are as follows:
- You must put a { and } at the start and end of your file.
- self_ and target_ have been replaced with self. and target.
- a,j,d have been replaced with A, J, D
- defining functions is a bit trickier now, see below for an example
- added self.num and target.num
- added ctimer (catch point timer)
Example of defining functions now(you need to check if they were defined before)
Code: {
clr();
var 1_abc = fun(x) {
return true;
};
var value = 1_abc(1);
print("1_abc: ${value}");
return 1;
}
There is only one chai script object now (instead of a new one been created each time a file is evaluated, huge performance improvement). Because of this everything exists in global space. That's why we are adding { and } at the start and end of our code and why functions have to be checked if they are defined. The problem with functions is that if two people make a function called SilvaIsAwesome() they are competing for that name. Because of this I have decided to create a convention where people should called their functions id_SilvaIsAwesome() (replace id with your characters ID).
Download:
Debug (has console, useful for developing): [attachment=2851]
Release(no console, for users): [attachment=2852] 0.6
Updates: - Added useful error messages (sometimes)
- Added bg params (bg_width, bg_zwidth1, bg_zwidth2)
- Added mode to detect which mode
- Added difficulty (0 = difficult, 2 = easy, 1 = normal , -1 = crazy)
- ORIGINAL AI!!! Now if there is no .chai file, lf2 will use the original AI
Todo:
Quote:#1: fix performance issues / memory leaks
#2: add all holding variables (to fix instant running and maybe more?)
#3: add move() come() stay()
#4: add target_num self_num
Download:
[attachment=2848] 0.5:
Updates: - Improved performance, sometimes, a tiny bit, hopefully, in some situtations, maybe?
- Added weapon_type and shake (yinyin asked for shake, don't ask me why)
- Added loadTarget(int n) function. This lets you change which object is now stored in target_ . Returns -1 if object doesn't exist or the object type if it does.
- Added rand(int n).
- Instead of crashing when you mess up your chaiscript, it now provides (un)helpful error messages! Fix your code bros!
Example of using loadTarget:
Code: clr();
for (var i = 0; i < 400; ++i)
{
if (loadTarget(i) != -1)
{
print (target_hp);
}
}
return 0;
Todo:
Quote:#1: leave original AI intact - only replace for existing .chai files
#2: add all holding variables (to fix instant running and maybe more?)
#3: fix performance issues / memory leaks
Download:
[attachment=2847] 0.4:
Ok, important update. You must include return 0 or return 1 at the end. If you return 0 then everything is normal, if you return 1 you will disable large amounts of the basic AI. This is very useful if you are trying to combo things. If you do not put a return thing at the end of your script, lf2 will crash!
Other updates:
added blink (to see if your blinking - invincible)
added state
Todo:
Improve performance
Call original AI if .chai file isn't found
Holding (to allow walking instead of always running)
?????
Download:
[attachment=2843] 0.3:
Update 0.3: - up()/down()/left()/right()
- added abs() function
- added team/id for self and target
Todo:
too lazy to write this bit.
download:
[attachment=2842]
0.2:
Update 0.2: - Fixed y/z bug
- Fixed facing
- added frame / bdefend / fall
- Made AI id dependent
Download:
[attachment=2838]
You need to have an AI folder, with a file [id].chai where [id] = the id of the character you want the AI for. For example 1.chai will work for deep. Do NOT put [ ] around the number.
To do: - Fix Memory Leaks
- Fix/Remove up()/down()/left()/right()/A()/J()/D()
- Anything else yinyin finds
Original Post:
Programmable AI
I made it possible to write scripts to replace the move AI of characters. Right now it replaces all the AI's with the one in myfile.chai but I'll change that in the future so that it loads AI's from an AI folder with [ID goes here].chai .
Play around with it. It uses Chaiscript ( http://www.chaiscript.com/doxygen/index.html#basics) which I know nothing about, but used because integrating it was a lot easier than anything else I could find.
You have access to :
Code: x;
y;
z;
facing;
holding_up;
holding_down;
holding_left;
holding_right;
holding_a;
holding_j;
holding_d;
up;
down;
left;
right;
A;
J;
D;
DrA;
DlA;
DuA;
DdA;
DrJ;
DlJ;
DuJ;
DdJ;
DJA;
hp;
dark_hp;
max_hp;
mp;
For self and target. Add self_ or target_ as the prefix. So if you want to see your health use:
The list is about reading values. If you want to make the AI do things you have to call the function of that action, so
DJA(), DdA(), DrA() etc.
Figure out what the letters mean or wait for YinYin.
If you've ever programmed before the syntax makes sense. You can use print("bla") to print things for debugging purposes. Check myfile.chai for a super super super simple example.
DirectDraw Hook
Another cool thing is the direct draw wrapper. Before you had to patch your exe to make it load dlls. Those days are over! Just stick ddraw.dll into a folder with a lf2 2.0a (must be a or it wont work) exe and it works! Weeeeeeeeeeeeeeee!
PS: If you post useless things I will kill you.
Oh yeah, and credit to this guy : http://iki.fi/sol/ I basically stole his directdraw wrapper and changed one line to make it work for lf2.
Instructions:
1. Extract in lf2 folder
2. Run lf2
3. Play around with myfile.chai
RE: Programmable AI via scripting (and ddraw hooking) - Azriel - 06-08-2012
cool. is it possible to have access to self's frame_number or an ally/enemy's frame_number?
the possibilities with that will be cool for tag team moves with computer players, and/or story modes where you can get AI to walk to specific places and do actions
i thought ".chai" was short for char-ai till i read the post again
Azriel~
RE: Programmable AI via scripting (and ddraw hooking) - YinYin - 06-08-2012
not yet azzy but after id specific chais are done its on the todo list like many other parameters
heres a very simple general AI i just wrote to test everything a little:
Code: //D>A long ranged
if ((target_y - self_y)*(target_y - self_y) < 100) {
if ((self_x - target_x) > 100) {
if ((self_x - target_x) < 600) {
DlA()
}}
if ((target_x - self_x) > 100) {
if ((target_x - self_x) < 600) {
DrA()
}}}
//D>J and DJA mid ranged
if ((target_y - self_y)*(target_y - self_y) < 81) {
if ((self_x - target_x) > 50) {
if ((self_x - target_x) < 300) {
DlJ()
}}
if ((target_x - self_x) > 50) {
if ((target_x - self_x) < 300) {
DrJ()
}}
if ((self_x - target_x) > 100) {
if ((self_x - target_x) < 400) {
DlJ()
}}
if ((target_x - self_x) > 100) {
if ((target_x - self_x) < 400) {
DrJ()
}}}
//DvJ low health
if (self_hp < 250) {
DdJ()
}
//D^J high health
if (self_hp > 250) {
DuJ()
}
//DvA and D^A short ranged
if ((target_y - self_y)*(target_y - self_y) < 64) {
if ((target_x - self_x) < 50) {
if ((target_x - self_x) > 0) {
if (self_facing == 0) {
DdA()
}}}
if ((self_x - target_x) < 50) {
if ((self_x - target_x) > 0) {
if (self_facing == 1) {
DdA()
}}}
if ((target_x - self_x) < 50) {
if ((target_x - self_x) > 0) {
if (self_facing == 0) {
DuA()
}}}
if ((self_x - target_x) < 50) {
if ((self_x - target_x) > 0) {
if (self_facing == 1) {
DuA()
}}}}
owns me pretty badly with many chars
edit: facing might not work in the first download yet but its already fixed
and there is also D() A() J() but i cannot confirm them to be working yet
and left() right() up() down() still need to be fixed
RE: Programmable AI via scripting (and ddraw hooking) - A-Man - 06-08-2012
The syntax is a combination of python and c++. Experimenting now XD
questions:
Does this work only for AI?. I mean can we make states and other things with it in the future?. I don't know but it sounds possible.
And YINYIN! can you please post what these letters/shortcuts means.
Edit:@Azriel: troll? why would I troll. Thanx anyway for clarification.
RE: Programmable AI via scripting (and ddraw hooking) - Alblaka - 06-08-2012
Hell yeah, finally something to turn random additional chars into killer additional chars :3
RE: Programmable AI via scripting (and ddraw hooking) - Azriel - 06-09-2012
i can already imagine "_player1_ style ai" vs "_player2_ style ai" competitions. or maybe, "upload your best ai" competitions that get run through an unknown stage .
that's something i would put effort into.
Azriel~
RE: [0.2 Update]Programmable AI via scripting - Boop - 06-09-2012
Updated. See first post for info and download.
RE: [0.2 Update]Programmable AI via scripting - A-Man - 06-09-2012
Here is a suggestion:
I think u should add an armor in your todo list. Atleast if this is even possible using the above method.
RE: [0.2 Update]Programmable AI via scripting - Boop - 06-09-2012
(06-09-2012, 02:37 PM)A-MAN Wrote: Here is a suggestion:
I think u should add an armor in your todo list. Atleast if this is even possible using the above method.
What? How does that have anything to do with AI...
Quote:PS: If you post useless things I will kill you.
Seriously, please think before posting things.
RE: [0.2 Update]Programmable AI via scripting - Alblaka - 06-09-2012
(06-09-2012, 02:56 PM)Lord Silva Wrote: (06-09-2012, 02:37 PM)A-MAN Wrote: Here is a suggestion:
I think u should add an armor in your todo list. Atleast if this is even possible using the above method.
What? How does that have anything to do with AI...
Could be useful for characters who have single and multi-hit attacks... former one won't damage Armor'd characters, latter one do.
I assume you mistook his request for the capability to add armor to specific char ID's, I think he just wants something to determine the target's armor level (similar to fall, frame, etc).
Btw, how about the ability to react differently to specific (target) IDs?
|