![]() |
|
loadtarget - 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: loadtarget (/showthread.php?tid=9079) |
loadtarget - 90134123 - 01-14-2014 I want to jan can follow teammate and if teammate is in range she will loadtarget for enemy this is my program but isn't work How can i correct it? Code: void id()
{
D(0,0);
A(0,0);
J(0,0);
right(0,0);
down(0,0);
left(0,0);
up(0,0);
for (int i = 0; i < 400; i++){ //target
if (loadTarget(i) == 0 && target.num != self.num && target.team==self.team){
break;
}
}
int VARxdst = self.x-target.x;
int VARydst = self.y-target.y;
int VARzdst = self.z-target.z;
int VARzbgu = self.z-bg_zwidth1;
int VARzbgb = bg_zwidth2-self.z;
int VARxbgr = bg_width-self.x;
int VARxabs = abs(VARxdst);
int VARyabs = abs(VARydst);
int VARzabs = abs(VARzdst);
int VARsf; //self facing
int VARtf; //target facing
int VARDirToTargetH; //lawannya di kiri atau kanan
int VARDirToTargetV; //lawannya di atas atau bawah
int VARholdinglgtweapon = 0;
if(self.facing == true){VARsf = -1;}
if(self.facing == false){VARsf = 1;}
if(target.facing == true){VARtf = -1;}
if(target.facing == false){VARtf = 1;}
if(VARxdst < 0){VARDirToTargetH = 1;}
if(VARxdst > 0){VARDirToTargetH = -1;}
if(VARzdst < 0){VARDirToTargetV = 1;}
if(VARzdst > 0){VARDirToTargetV = -1;}
if(target.hp>0)
{
if(VARzdst<-30)
down(1,1);
else if(VARzdst>30)
up(1,1);
else if(VARxdst<-200)
right(1,1);
else if(VARxdst>200)
left(1,1);
}
if(VARzdst>-30 && VARzdst<30 && VARxdst>-200 && VARxdst<200)
{
for (int i = 0; i < 400; i++){ //target
if (loadTarget(i) == 0 && target.num != self.num && target.team!=self.team){
break;
}
}
}
if(target.hp>0 && VARzabs<= 20 && target.team!=self.team)
{
if(VARxdst>-75 && VARxdst<0 )
{
if(VARsf==-1)
right(1,1);
A();
}
else if(VARxdst<75 && VARxdst>=0)
{
if(VARsf==1)
left(1,1);
A();
}
else
{
left(0,0);
right(0,0);
A(0,0);
}
}
}RE: loadtarget - Boop - 01-14-2014 You need to recalculate all your variables after you change target. Here is a cheap fix: Code: void id() {
clr();
D(0,0);
A(0,0);
J(0,0);
right(0,0);
down(0,0);
left(0,0);
up(0,0);
for (int i = 0; i < 400; i++){ //target
if (loadTarget(i) == 0 && target.num != self.num && target.team==self.team){
print("Ally: "+ target.num + "\n");
break;
}
}
int VARxdst = self.x-target.x;
int VARydst = self.y-target.y;
int VARzdst = self.z-target.z;
int VARzbgu = self.z-bg_zwidth1;
int VARzbgb = bg_zwidth2-self.z;
int VARxbgr = bg_width-self.x;
int VARxabs = abs(VARxdst);
int VARyabs = abs(VARydst);
int VARzabs = abs(VARzdst);
int VARsf; //self facing
int VARtf; //target facing
int VARDirToTargetH; //lawannya di kiri atau kanan
int VARDirToTargetV; //lawannya di atas atau bawah
int VARholdinglgtweapon = 0;
if(self.facing == true){VARsf = -1;}
if(self.facing == false){VARsf = 1;}
if(target.facing == true){VARtf = -1;}
if(target.facing == false){VARtf = 1;}
if(VARxdst < 0){VARDirToTargetH = 1;}
if(VARxdst > 0){VARDirToTargetH = -1;}
if(VARzdst < 0){VARDirToTargetV = 1;}
if(VARzdst > 0){VARDirToTargetV = -1;}
if(target.hp>0) {
if(VARzdst<-30)
down(1,1);
else if(VARzdst>30)
up(1,1);
else if(VARxdst<-200)
right(1,1);
else if(VARxdst>200)
left(1,1);
}
if(VARzdst>-30 && VARzdst<30 && VARxdst>-200 && VARxdst<200) {
for (int i = 0; i < 400; i++){ //target
if (loadTarget(i) == 0 && target.num != self.num && target.team!=self.team){
print("enemy: "+ target.num + "\n");
break;
}
}
}
VARxdst = self.x-target.x;
VARydst = self.y-target.y;
VARzdst = self.z-target.z;
VARzbgu = self.z-bg_zwidth1;
VARzbgb = bg_zwidth2-self.z;
VARxbgr = bg_width-self.x;
VARxabs = abs(VARxdst);
VARyabs = abs(VARydst);
VARzabs = abs(VARzdst);
VARsf; //self facing
VARtf; //target facing
VARDirToTargetH; //lawannya di kiri atau kanan
VARDirToTargetV; //lawannya di atas atau bawah
VARholdinglgtweapon = 0;
if(self.facing == true){VARsf = -1;}
if(self.facing == false){VARsf = 1;}
if(target.facing == true){VARtf = -1;}
if(target.facing == false){VARtf = 1;}
if(VARxdst < 0){VARDirToTargetH = 1;}
if(VARxdst > 0){VARDirToTargetH = -1;}
if(VARzdst < 0){VARDirToTargetV = 1;}
if(VARzdst > 0){VARDirToTargetV = -1;}
if(target.hp>0 && VARzabs<= 20 && target.team!=self.team) {
print("punching: "+ target.num + "\n");
if(VARxdst>-75 && VARxdst<0 ) {
if(VARsf==-1)
right(1,1);
A();
}
else if(VARxdst<75 && VARxdst>=0) {
if(VARsf==1)
left(1,1);
A();
}
else {
left(0,0);
right(0,0);
A(0,0);
}
}
}I didn't really bother trying to understand what you did. Please use the code tag next time so that the formatting stays sane. Welcome to LFE. RE: loadtarget - 90134123 - 01-14-2014 thank you !! I like a LFE because is friendly place Sorry i will pay attention next time RE: loadtarget - 90134123 - 01-23-2014 I have a question if I use a for loop to check enemy my Character only find the fixed num So my scrip just can use for 1 on 1 in stage mode like a fool... How can i fix it? RE: loadtarget - YinYin - 01-23-2014 Use the loop to find more than one object. I like to look for two most important things: The object that poses the most immediate danger (blast/weapon/opponent about to connect a hit) and the opponent with the highest priority to be defeated (closest/boss/low hp/...). RE: loadtarget - 90134123 - 01-23-2014 I use more than for loop to check object but my AI didn't know which attack first when two enemy one at left side and the other at right side If I use more than one loop I need set new Variable to the other enemy? and how can i let computer know which is first attack compare two enemy variable? RE: loadtarget - YinYin - 01-23-2014 Huh? Just use one loop to look at all objects and store their numbers inside respective variables (one for each kind of criteria). To know who hits first just extrapolate movement and see how many frames it'll take to intersect with your bdy. RE: loadtarget - 90134123 - 01-24-2014 Tank you answer me! I have read your basic AI is helpful to me you use Array and many function I will learn more about your scripting |