Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loadtarget
#1
? 
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);
    
              }
    
    }

    
}












Reply
Thanks given by:
#2
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.
[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: 90134123 , mfc
#3
thank you !!
I like a LFE because is friendly place
Sorry i will pay attention next time
Reply
Thanks given by: Draya Vartaila
#4
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?
Reply
Thanks given by:
#5
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/...).
Reply
Thanks given by: 90134123
#6
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?
Reply
Thanks given by:
#7
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.
Reply
Thanks given by: 90134123
#8
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
Reply
Thanks given by:




Users browsing this thread: 3 Guest(s)