Little Fighter Empire - Forums
Simple things. - Printable Version

+- Little Fighter Empire - Forums (https://lf-empire.de/forum)
+-- Forum: Little Fighter 2 Zone (https://lf-empire.de/forum/forumdisplay.php?fid=7)
+--- Forum: AI Scripting (https://lf-empire.de/forum/forumdisplay.php?fid=56)
+--- Thread: Simple things. (/showthread.php?tid=8877)

Pages: 1 2


Simple things. - Gad - 08-13-2013

Ok.
I may be retarded.
Still I have some questions. I hope somebody could help me.
I'm trying to write an AI (very simple for a beginning). I've red a book about C++ programming, so this isn't something hard to understand, but I think I'm in lack of some informations.
I've been studying other AIs, and I don't get why my isn't working.


THIS WORKS: (Click to View)
After adding absolute z distance it doesn't - expected expression value (Click to View)



RE: Simple things. - YinYin - 08-14-2013

You are missing brackets on DrA() and DlA()
(08-13-2013, 11:17 PM)Gad Wrote:  expected expression value
Such an error comes with a line and symbol number so you know where exactly you have to look.


RE: Simple things. - Gad - 08-14-2013

Well. I think I've already pointed out which parameter is a problem.
Nevermind this.

Anyway I'm really confused, with the usage of functions.
Let's say I want to script something like this:

Code:
int xdistance = (self.x-target.x)*(2*(self.facing?1:0)-1);
if(self.mp < 100)
{
target = get_closest_enemy();

    if(xdistance > 100)
    {
        if(self.x-target.x > 0)
        {
            run_left();
        }
        else
            run_right();
    }

}
else act_normally();
Anybody could help me to translate it into the AIscript code?
I'm not trying to ask you to write whole AI for me. :D


RE: Simple things. - YinYin - 08-14-2013

    C-Code:
//assuming this will be an ego function to have 'normal' acting - otherwise you have to control all actions
int ego(){
int xdistance = (self.x-target.x)*(2*(self.facing?1:0)-1);
if(self.mp < 100)
{
 
//target = get_closest_enemy();
//this one won't work as target isn't defined on it's own in any way
//you need to use the loadTarget(object.num as integer) function:
loadTarget(get_closest_enemy());
 
//your get_closest_enemy() function will need to cycle through all 400 objects, check their distance to self
//and return the object number of the closest one
 
	if(xdistance > 100)
	{
		if(self.x-target.x > 0)
		{
			run_left();
		}
		else
			run_right();
	}
//left(1,0) and right(1,0) will do to make the character run - the script will need to run past this twice of course
 
return 1;
//this will make the games id() function return control to your ego() function unless it's got an item to pick or a downed opponent to run away from etc
 
}
//else act_normally();
return 0;
//this will return control to the games id() function to do as it pleases
}



RE: Simple things. - Gad - 08-14-2013

but wait.
get_closest_enemy will work?
is this function built in? thought i need to write it over with some other keywords


ah wait, just red the comment
Sooo, I need to use "for" loop?

Code:
int lowest = 99999;
int final;
    for(i = 0; i <= 399; i++)
{
    loadTarget(i);
    if (xdistance < lowest)
    {
        lowest = xdistance;
        final = i;
        
    }


}
loadTarget(final);

I'd add another condition.
How do I check if object is existing?

Would this work?


RE: Simple things. - YinYin - 08-15-2013

Code:
int get_closest_enemy(){
int lowest = 99999;
int final;
    for(i = 0; i <= 399; i++)
{
    if (loadTarget(i)!=-1 && xdistance < lowest)
    {
        lowest = xdistance;
        final = i;
        
    }


}
return final;
}

loadTarget() itself returns the object type of the loaded object; -1 if it doesn't exist.
(change !=-1 into ==0 and also add a team check to only get enemies - this one will actually get the closest object right now)


RE: Simple things. - Gad - 08-15-2013

OK.
So how do I get the team and state. etc now

Code:
(self.team != target.team && target.type == 0 && target.state !=(12 || 18))
doesn't seem to work for me (at least the team)

And ofcourse the script is red by the program every frame?

and btw, can't i use abs(self.x - target.x) to get distance?
seems ok for me, I'm checking the facing anyway

EDIT:

Hmmm, the get_closest function seems to be jamming.
It doesn't get the target properly, it usually takes one and doesn't change it.
The code looks ok for me, any ideas?

Edit2:
Just wondering.
Is it possible to connect to someone who didn't install AI dll, while I do have it?
If possible how AI will react?


RE: Simple things. - Silverthorn - 08-15-2013

(08-15-2013, 09:49 AM)Gad Wrote:  
Code:
(self.team != target.team && target.type == 0 && target.state !=(12 || 18))
doesn't seem to work for me (at least the team)
Try:
Code:
(self.team != target.team && target.type == 0 && (target.state != 12 || target.state != 18))
I didn't quite follow what you're trying to do but that'd be the proper syntax, which backtranslates to the following:
- target must be in different team than you
- target must be a character
The third condition will always yield true. If the char is in state 12, the second part will make it valid (state != 18), if he is in state 18, the first validates it. Any other state is passed as well. Not quite sure what you're trying to achieve there :p

(08-15-2013, 09:49 AM)Gad Wrote:  And ofcourse the script is red by the program every frame?
Yup.

(08-15-2013, 09:49 AM)Gad Wrote:  and btw, can't i use abs(self.x - target.x) to get distance?
seems ok for me, I'm checking the facing anyway
You might want to add the z-component, too. If you're really picky, y as well. The proper way would be sqrt((self.x - target.x)² + (self.y - target.y)² + (self.z - target.z)²). Distance in 3D-space. But then again, if you just go for the x-component, it shortens down to the abs(self.x - target.x) part. So I guess that's fine, too.

(08-15-2013, 09:49 AM)Gad Wrote:  Hmmm, the get_closest function seems to be jamming.
It doesn't get the target properly, it usually takes one and doesn't change it.
The code looks ok for me, any ideas?
Just to rule out anything, do you call "get_closest_enemy()" in your AI? Also, have you tried to print out the target-index + its xdistance?


(08-15-2013, 09:49 AM)Gad Wrote:  Just wondering.
Is it possible to connect to someone who didn't install AI dll, while I do have it?
If possible how AI will react?
The game will most likely throw a synchronization-error at you once the AI behaves differently from normal.


RE: Simple things. - YinYin - 08-15-2013

(08-15-2013, 09:49 AM)Gad Wrote:  Hmmm, the get_closest function seems to be jamming.
It doesn't get the target properly, it usually takes one and doesn't change it.
The code looks ok for me, any ideas?
How do you know it sticks to one selected target? Are you loading your target before your other stuff?
The games basic AI selects it's own target and starts the ego function with it, so that might be the reason your target selection doesn't really do anything at all (or at least look like it).
Basically if you don't intend to do something special you don't have to select targets inside the ego function - it's easier to just work with the pre selected one.

(08-15-2013, 09:49 AM)Gad Wrote:  Just wondering.
Is it possible to connect to someone who didn't install AI dll, while I do have it?
If possible how AI will react?
It is, but whenever two computer characters with different AI are fighting both games will run differently and get a sync error once the checksum (I think it works by checking the object hp only) on both games differs.


RE: Simple things. - Gad - 08-16-2013

(08-15-2013, 01:31 PM)Blue Phoenix Wrote:  The third condition will always yield true.
doesn't
Code:
target.state !=(12 || 18)
equals
Code:
target.state !=12 && target.state != 18
?
I maybe thinking wrong though.

(08-15-2013, 01:31 PM)Blue Phoenix Wrote:  add the z-component, too.
Can't check right now. But the topic started with the Z-distance problem, which didn't work, still dunno why.
Code looks ok.

(08-15-2013, 01:31 PM)Blue Phoenix Wrote:  Just to rule out anything, do you call "get_closest_enemy()" in your AI? Also, have you tried to print out the target-index + its xdistance?

Cmon, BP. I'm not THAT stupid.
I've been programming for months at least.
I know how to test the program ;P.
I printed the result of getting closest enemies.

(08-15-2013, 04:10 PM)YinYin Wrote:  How do you know it sticks to one selected target? Are you loading your target before your other stuff?
Print(i); (lags as hell xDD)
(08-15-2013, 04:10 PM)YinYin Wrote:  The games basic AI selects it's own target and starts the ego function with it, so that might be the reason your target selection doesn't really do anything at all (or at least look like it).
i tried return 1, the character keeps running forever and doesnt change the target

(08-15-2013, 04:10 PM)YinYin Wrote:  Basically if you don't intend to do something special you don't have to select targets inside the ego function - it's easier to just work with the pre selected one.
It's a script for a shooting unit. I want it to stay as far as possible from the enemy. Ofcourse I'm not going to use simple run-left-right script, but I need to start with something.