Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there any easy ddraw tutorial to script AI?
#21
So here you are:
http://en.wikibooks.org/wiki/C_Programming nice introduction to programming, I think you should especially read (and understand) part about program flow
http://www.angelcode.com/angelscript/sdk...cript.html a bit more advanced, reference documentation of AngelScript
You should also read YinYin's tutorial because it consists every variable and function accessible from your scripts, they are characteristic only for LF2-AI AngelScript implementation.
If you have any problems, just ask :) Sorry for confusion.

Edit:
I will also try to explain it myself. Let's assume you want only to add to your characters some new moves, so they wouldn't be so dumb. The easiest way to do so, is NOT to use void id() function, because in this way we would overwrite whole the basic AI. Instead we will write our code in a body of ego() function. It means that this code:
Code:
int ego()
{
return 0;
}
will do only basic AI's actions, no combos at all.

Combos need to be performed only when a suitable situation occurs, i.e. we will use combo only when we are in the same line (the same z axis coordinate) as an opponent. It would be also nice to do it when we are at a good distance and when we are faced towards him. I wrote some functions to help me in this task:
Code:
int face_distance()
// distance to target, positive when faced towards it (vis-a-vis), negative when we are faced in the opposite direction
// 80 pixels may be considered as a maximum distance allowing close combat
{
    return ( self.x - target.x ) * ( 2 * ( self.facing ? 1 : 0 ) - 1 );
}

bool dist_between( int min, int max )
// checks whether distance to target is within bounds
{
    return ( ( face_distance() < max ) && ( face_distance() > min ) );
}

bool z_axis_dist( int dist )
// a more general version of same_z_axis()
{
    return ( abs( self.z - target.z ) <= dist ) ? true : false;
}

bool same_z_axis()
// checks whether our character is on the same z axis as the opponent
{
    return ( abs( self.z - target.z ) <= 8 ) ? true : false;
}

Using them we can script AI in a very simple way. For example I would like to do a close combat combo, only when I am close enough to an opponent and have enough MP:
Code:
//... functions from above should be here ...

int ego()
{
    if( dist_between(10,60) && ( target.state < 3 ) && same_z_axis() && ( self.mp > 50 ) )
    {
        DdA();
    }
    return 0;
}

&& means literally "and".
The condition in the IF statement means:
IF ( distance between us and an opponent is from 10 to 60 (while being faced towards him) AND
our target (opponent) is staying, walking or running (states 0, 1 and 2) - check THIS out AND
we are in the same line (nearly the same z axis coordinate) AND
our mana is above 50 ) DO Defense+Down+Attack combo.

Check my AI scripts to learn some tricks from them.
Reply
Thanks given by: professional DCer
#22
(08-16-2012, 02:39 PM)Shymeck Wrote:  If you have any problems, just ask :) Sorry for confusion.

No. If you have problems try to figure it out your self.
Quote:in your tutorial i have seen words like d(0,0) duj(0,1) etc what all these words means? can you please help me?

That would take you literally take you 5 seconds to test if LF2 was already running. First think, then post. It's even in the forum rules:

Quote:Rule 2: Think before posting
[Image: doty7Xn.gif]

10 ʏᴇᴀʀs sɪɴᴄᴇ ɪʀᴄ ɢᴏᴏᴅ.ɪ ᴡᴀʟᴋ ᴛʜʀᴏᴜɢʜ ᴛʜᴇ ᴇᴍᴘᴛʏ sᴛʀᴇᴇᴛs ᴛʀʏɪɴɢ ᴛᴏ ᴛʜɪɴᴋ ᴏғ sᴏᴍᴇᴛʜɪɴɢ ᴇʟsᴇ ʙᴜᴛ ᴍʏ ᴘᴀᴛʜ ᴀʟᴡᴀʏs ʟᴇᴀᴅs ᴛᴏ ᴛʜᴇ ɪʀᴄ. ɪ sᴛᴀʀᴇ ᴀᴛ ᴛʜᴇ sᴄʀᴇᴇɴ ғᴏʀ ʜᴏᴜʀs ᴀɴᴅ ᴛʀʏ ᴛᴏ sᴜᴍᴍᴏɴ ᴛʜᴇ ɢᴏᴏᴅ ɪʀᴄ. ɪ ᴡᴀᴛᴄʜ ᴏᴛʜᴇʀ ɪʀᴄ ᴄʜᴀɴɴᴇʟs ʙᴜᴛ ɪᴛ ɪs ɴᴏ ɢᴏᴏᴅ. ɪ ᴘᴇsᴛᴇʀ ᴢᴏʀᴛ ᴀɴᴅ ᴛʀʏ ᴛᴏ ʀᴇsɪsᴛ ʜɪs sᴇxɪɴᴇss ʙᴜᴛ ɪᴛ ɪs ᴀʟʟ ᴍᴇᴀɴɪɴɢʟᴇss. ᴛʜᴇ ᴇɴᴅ ɪs ɴᴇᴀʀ.ɪ ᴛʜᴇɴ ᴜsᴜᴀʟʟʏ ʀᴇᴀᴅ sᴏᴍᴇ ᴏʟᴅ ɪʀᴄ ʟᴏɢs ᴀɴᴅ ᴄʀʏ ᴍʏsᴇʟғ ᴛᴏ sʟᴇᴇᴘ.


Reply
Thanks given by: mfc , Evil Sonidow
#23
I would like to provide you a simple example which is always applicable for offensive moves:
//D>J mid range
if ( abs(self.x-target.x) >= 90 && abs(self.x-target.x) <= 160 && abs(self.z-target.z) <= 10 ) {
if (target.x > self.x) {
DrJ();
} else {
DlJ();
}}

the meaning: when target is between 90px to 160px on x-axis and within 10px on z-axis, if target is on my right (when target is on my right, his coordinate on x-axis should be greater than mine) then D>J, else (on my left) D<J

other useful conditions:

my mp is above 300 : (self.mp >= 300)
target is not going to attack me right now : (target.state != 3) -> his state is not equal to 3

I only know how to make use of these to make sure the AI will perform moves in different conditions

P.S. if you always mess up with brackets, use Notepad++ to edit the scripts
Reply
Thanks given by: professional DCer
#24
Uhh, while I was editing my post, some other guys posted underneath :)

Lord Silva Wrote:No. If you have problems try to figure it out your self.
I think good and interesting questions are always valuable. ;p
Reply
Thanks given by:
#25
(08-16-2012, 03:18 PM)Shymeck Wrote:  Uhh, while I was editing my post, some other guys posted underneath :)

Lord Silva Wrote:No. If you have problems try to figure it out your self.
I think good and interesting questions are always valuable. ;p


no problem yours is much more detailed, nice
Reply
Thanks given by:
#26
(08-16-2012, 03:05 PM)totokwok Wrote:  I would like to provide you a simple example which is always applicable for offensive moves:
//D>J mid range
if ( abs(self.x-target.x) >= 90 && abs(self.x-target.x) <= 160 && abs(self.z-target.z) <= 10 ) {
if (target.x > self.x) {
DrJ();
} else {
DlJ();
}}

the meaning: when target is between 90px to 160px on x-axis and within 10px on z-axis, if target is on my right then D>J, else (on my left) D<J

other useful conditions:

my mp is above 300 : (self.mp >= 300)
target is not going to attack me right now : (target.state != 3) -> his state is not equal to 3

I only know how to make use of these to make sure the AI will perform moves in different conditions

P.S. if you always mess up with brackets, use Notepad++ to edit the scripts

Thanks, can you please explain me about abs and <= >= etc.
Life is like a bicycle; to keep your balance, you must keep moving.
Reply
Thanks given by:
#27
abs() - absolute value
<= - less or equal
>= - greater or equal
Reply
Thanks given by: professional DCer
#28
Thanks, but can you please explain me how to make my char run to the opposite direction when the target is standing, walking or running towards my char in x or z position within 80 pixel.
Life is like a bicycle; to keep your balance, you must keep moving.
Reply
Thanks given by:
#29
You should check the target's velocity and position, think about it.
Reply
Thanks given by:
#30
(08-16-2012, 03:05 PM)totokwok Wrote:  P.S. if you always mess up with brackets, use Notepad++ to edit the scripts
Or my Data Changer. It has color coding implemented for AI scripts.

(08-16-2012, 03:18 PM)Shymeck Wrote:  
Lord Silva Wrote:No. If you have problems try to figure it out your self.
I think good and interesting questions are always valuable. ;p
But you should still try to solve it yourself before asking, since if you don't all the good and interesting questions are going to drown in all the terrible and obvious ones.

Generally if you have a problem, try to do a google search, as others have stated, the syntax is similar to C++ so if you have a problem with AngelScript, try searching for something to do with C++.
You can also take a look at the AngelScript Documentation (Clicky). It has a complete overview over the syntax, and if you are looking for an overview of our implementation check our YinYin's tutorial (Clicky).
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)