Little Fighter Empire - Forums
Object not on the map - 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: Object not on the map (/showthread.php?tid=9206)



Object not on the map - pikol - 05-12-2014

I want my character to make an attack (e.g. ball) only if it's not on the map already or if it's far enough for him.
Code:
for (int i = 0; i < 100; ++i) { //darkness if (loadTarget(i)==-1 && target.id==448 && target.team==self.team && abs(self.x-target.x)<500) { DdA(); } }
Something like this works only when a teammate do the same attack and it's gone or far enough, but I want him to make it alone.


RE: Object not on the map - A-Man - 05-13-2014

Dude, that's not how you're supposed to do it XD. Whenever you write such a code try to run it in your head. For instance:
You're looping on the first 100 objects (although you're supposed to loop on 399 since THAT is the maximum number of the objects you can have on the screen) and assigning the index to the variable i. Every loop, you check if that target doesn't exist AND if its ID equals 448. That's like checking if you don't have a cake, and if you don't, you check what color it is; it doesn't exist in the first place!!? So how can you check a property or something that doesn't exist? The right thing you should do is:
    AI-Code:
bool theballexists=false;  //we first start by defining our variable 
for (int i=0; i<399; ++i){    /*we're checking if that ball exists, if it does, we set the variable to true. Else,
                                       it just means that the ball doesn't exist and "theballexists" stays false*/
    if (loadTarget(i)==0 && target.id==448  && target.team==self.team && abs(self.x-target.x)<500){
        theballexists=true;
    }
}
if (!theballexists){   //note that it is the same as saying (theballexists==false)
    DdA();             //if our ball doesn't exist, we do the move.
}





RE: Object not on the map - pikol - 05-13-2014

Ok, I'll keep that in mind.

But it doesn't work either. He just keep spamming with this attack, bacause "theballexists" is always false, just like he would ignore the "if" in the loop.

Ok, it should be loadTarget(i)==3 and it's alright then. Thanks a lot :)


RE: Object not on the map - A-Man - 05-13-2014

(05-13-2014, 03:33 PM)pikol Wrote:  Ok, I'll keep that in mind.

But it doesn't work either. He just keep spamming with this attack, bacause "theballexists" is always false, just like he would ignore the "if" in the loop.
OOps. Yes my bad. The range conditioning check must've been in the if the ball exist condition as well:
    AI-Code:
bool theballexists=false;  //we first start by defining our variable 
for (int i=0; i<399; ++i){    /*we're checking if that ball exists, if it does, we set the variable to true. Else,
                                       it just means that the ball doesn't exist and "theballexists" stays false*/
    if (loadTarget(i)==0 && target.id==448  && target.team==self.team){
        theballexists=true;
    }
}
if (!theballexists && abs(self.x-target.x)<500){   //note that it is the same as saying (theballexists==false)
    DdA();             //if our ball doesn't exist, we do the move.
}