Counterattack feature

machok

Well-known member
counterattack {bi}
Code:
    If set to 1, attackboxes in this animation will also hit opponent's attackbox. However, this only works if opponent has active bbox when he/she is attacking.
    Like the name sais, this is great for counter attacks.


Can anyone explain more about this?

What I want to do is
If both entities (player and enemy) attack each other at the same time, both will receive a hit and doing anim pain at the same time
have tried counterattack 1 and other counter features but only 1 entity has been attacked every time. Never at the same time
 
If you need example, you can try Kula and Athena from Crime Buster v2.5. Kula has freezing pose in which she freezes any enemy trying to hit her in that pose while Athena has Psychic Shield in which she knocks away any enemy trying to hit her. Both uses counterattack 1 in their animation.

If both entities (player and enemy) attack each other at the same time, both will receive a hit and doing anim pain at the same time

Damon caskey once posted something about it before.
 
If you need example, you can try Kula and Athena from Crime Buster v2.5. Kula has freezing pose in which she freezes any enemy trying to hit her in that pose while Athena has Psychic Shield in which she knocks away any enemy trying to hit her. Both uses counterattack 1 in their animation.

Honestly I am not sure how to use their Freespecial6
Code:
D F U A freespecial6
not working for me while in game.
But I assume this counterattack feature isn't what I need?

Damon caskey once posted something about it before.
maybe someone here can point me to the page?
 
Can't find any related DC post about this so I'll temporarily delay this question for another time
@Bloodbane
Can you help me to modify your target script, Make it only for targeting type item/subtype weapons (not player)?

this one:
Code:
void target(float Velx, float Velz, float dx, float dz, int Stop, int Flip)
{// Targetting opponent before leaping or dashing.
// Velx = x Velocity
// Velz = z Velocity
// dx = x added distance
// dz = z added distance
// Stop = flag to stop moving if no target is found

    void self = getlocalvar("self");
    int dir = getentityproperty(self, "direction");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");

    if (dir == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
    }

    setlocalvar("T"+self, findtarget(self)); //Get nearest player

    if( getlocalvar("T"+self) != NULL()){
      void target = getlocalvar("T"+self);
      float Tx = getentityproperty(target, "x");
      float Tz = getentityproperty(target, "z");

      if(Flip == 1){
        if(Tx < x){
          changeentityproperty(self, "direction", 0);
        } else {
          changeentityproperty(self, "direction", 1);
        }
      }

      x = x+dx;
      z = z+dz;
      float Disx = Tx - x;
      float Disz = Tz - z;

//Set both distance as positive value
      if(Disx < 0){
        Disx = -Disx;
      }

      if(Disz < 0){
        Disz = -Disz;
      }

// Calculate velocity for targetting
      if(Disz < Disx)
      {
        if(Tx < x){
          setlocalvar("x"+self, -Velx);
        } else { setlocalvar("x"+self, Velx); }

        setlocalvar("z"+self, Velx*(Tz-z)/Disx);
      } else {
        if(Tz < z){
          setlocalvar("z"+self, -Velz);
        } else { setlocalvar("z"+self, Velz); }

        setlocalvar("x"+self, Velz*(Tx-x)/Disz);
      }

    } else {
      if(Stop == 1)
      {
        setlocalvar("z"+self, 0);
        setlocalvar("x"+self, 0);
      } else {
        setlocalvar("z"+self, 0);
        if(dir==0){
          setlocalvar("x"+self, -Velx);
        } else { setlocalvar("x"+self, Velx); }
      }
    }

    setlocalvar("T"+self, NULL()); //Clears variable
}
 
Sorry for late reply, I can't remember thread where Damon posted about that :cry:.
OTOH I don't know how to make 2 entities hit each other at same time :(. However, I've coded how to create 2 projectiles which cancel each other if they collide :D .

I can say for sure that it doesn't use counterattack feature at all.

Can you help me to modify your target script, Make it only for targeting type item/subtype weapons (not player)?

I'd need to create function to target those types first. Might need some time since I'm kinda occupied lately o_O
 
Sorry for late reply, I can't remember thread where Damon posted about that :cry:.
OTOH I don't know how to make 2 entities hit each other at same time :(. However, I've coded how to create 2 projectiles which cancel each other if they collide :D .

I can say for sure that it doesn't use counterattack feature at all.



I'd need to create function to target those types first. Might need some time since I'm kinda occupied lately o_O

As I recall, I didn't outline the whole process, just why it's not (and likely never will be) a native feature for OpenBOR.

While I do know how you could script this, I'm honestly a bit hesitent to explain in detail. The script will be rather complex and take quite a bit of writing on my part. I don't want to spend a few hours going through all that just to hear back "oh that's too complicated, I'm not doing that."

The basic outline looks like this:
  1. On hit, get following properties:
    1. Attacker position.
    2. Attacker attack box properties for current animation frame.
    3. Target position.
    4. Target attack box properties for its current animation frame.
  2. From above step, manually calculate collision areas from coordinates and look for overlap. If none, exit.
  3. Create damage object from target's attack box properties and manually apply to attacker.
The tricky parts are getting target attack properties, and calculating the collision areas.

DC
 
Sorry for late reply, I can't remember thread where Damon posted about that :cry:.
OTOH I don't know how to make 2 entities hit each other at same time :(. However, I've coded how to create 2 projectiles which cancel each other if they collide :D .
While cancel each other, can they play pain animation?
I'd need to create function to target those types first. Might need some time since I'm kinda occupied lately o_O
Thank you Bloodbane and please just do it when you have free time.
 
As I recall, I didn't outline the whole process, just why it's not (and likely never will be) a native feature for OpenBOR.

While I do know how you could script this, I'm honestly a bit hesitent to explain in detail. The script will be rather complex and take quite a bit of writing on my part. I don't want to spend a few hours going through all that just to hear back "oh that's too complicated, I'm not doing that."

The basic outline looks like this:
  1. On hit, get following properties:
    1. Attacker position.
    2. Attacker attack box properties for current animation frame.
    3. Target position.
    4. Target attack box properties for its current animation frame.
  2. From above step, manually calculate collision areas from coordinates and look for overlap. If none, exit.
  3. Create damage object from target's attack box properties and manually apply to attacker.
The tricky parts are getting target attack properties, and calculating the collision areas.

DC
I was just about to say oh that's too complicated 😊

What I want to say is, if there is no script available about this feature please there's no need to write it especially when it's a bit complex and will take up someone's time.
But if someone has already made it, I'd be happy to try it.
 
Can you help me to modify your target script, Make it only for targeting type item/subtype weapons (not player)?

I've searched my scripts and found this function:
Code:
void getTarg(int Input, int RxMin, int RxMax, int Rz)
{// Acquires certain entity type within defined distance
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    void vEntity;                                       //Target entity placeholder.
    int  iEntity;                                       //Entity enumeration holder.
    int  iType;                                         //Entity type.
    int  iMax = openborvariant("count_entities");       //Entity count.
    float Tx; float Tz; float Disx; float Disz;
    void Res;

    //Enumerate and loop through entity collection.
    for(iEntity=0; iEntity<iMax; iEntity++){
      vEntity = getentity(iEntity);                 //Get target entity from current loop.
      iType   = getentityproperty(vEntity, "type"); //Get target type.

      if(iType == Input){
        Tx = getentityproperty(vEntity, "x");
        Tz = getentityproperty(vEntity, "z");
        Disx = Tx - x;
        Disz = Tz - z;

        if(Disx >= RxMin && Disx <= RxMax && Disz <= Rz){
          Res = vEntity;
          break;
        }
      }
    }

    return Res;
}

You can use this function to replace findtarget function in your new target function.
Though unlike findtarget function, you need to specify entity type and range in this getTarg function.
Ex: getTarg(openborconstant("TYPE_ITEM"), 0, 500, 50)
 
I've searched my scripts and found this function:
Code:
void getTarg(int Input, int RxMin, int RxMax, int Rz)
{// Acquires certain entity type within defined distance
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    void vEntity;                                       //Target entity placeholder.
    int  iEntity;                                       //Entity enumeration holder.
    int  iType;                                         //Entity type.
    int  iMax = openborvariant("count_entities");       //Entity count.
    float Tx; float Tz; float Disx; float Disz;
    void Res;

    //Enumerate and loop through entity collection.
    for(iEntity=0; iEntity<iMax; iEntity++){
      vEntity = getentity(iEntity);                 //Get target entity from current loop.
      iType   = getentityproperty(vEntity, "type"); //Get target type.

      if(iType == Input){
        Tx = getentityproperty(vEntity, "x");
        Tz = getentityproperty(vEntity, "z");
        Disx = Tx - x;
        Disz = Tz - z;

        if(Disx >= RxMin && Disx <= RxMax && Disz <= Rz){
          Res = vEntity;
          break;
        }
      }
    }

    return Res;
}

You can use this function to replace findtarget function in your new target function.
Though unlike findtarget function, you need to specify entity type and range in this getTarg function.
Ex: getTarg(openborconstant("TYPE_ITEM"), 0, 500, 50)
Can I use leap or dash like your terget script with this?
Code:
{// Targetting opponent before leaping or dashing.
 
@Bloodbane
how to use this function?
When I put like this:
@cmd getTarg(openborconstant("TYPE_ITEM"), 0, 500, 50)
can't open the openbor, on log:
Code:
Script error: data/chars/sodom/sodom.txt, line 2379: Unknown error ',' (in production 'assignment_expr')

            getTarg(openborconstant("TYPE_ITEM"),(0,, 500,, 50));
                                                          ^



Script error: data/chars/sodom/sodom.txt, line 2379: Unknown error ';' (in production 'stmt_list')

            getTarg(openborconstant("TYPE_ITEM"),(0,, 500,, 50));
                                                                ^

If I put like this:
@cmd getTarg "TYPE_ITEM" 0 500 50
still error, on log:
Code:
There's an exception while executing script 'sodom' data/chars/sodom/sodom.txt
 
Ah you've misunderstood.

What I mean is for you to create new function like this:
Code:
void targetI(float Velx, float Velz, float dx, float dz, int Stop, int Flip)
{// Targetting item before leaping or dashing.
// Velx = x Velocity
// Velz = z Velocity
// dx = x added distance
// dz = z added distance
// Stop = flag to stop moving if no target is found

    void self = getlocalvar("self");
    int dir = getentityproperty(self, "direction");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");

    if (dir == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
    }

    setlocalvar("T"+self, getTarg(openborconstant("TYPE_ITEM"), 0, 500, 50)); //Get an item

    if( getlocalvar("T"+self) != NULL()){
      void target = getlocalvar("T"+self);
      float Tx = getentityproperty(target, "x");
      float Tz = getentityproperty(target, "z");

      if(Flip == 1){
        if(Tx < x){
          changeentityproperty(self, "direction", 0);
        } else {
          changeentityproperty(self, "direction", 1);
        }
      }

      x = x+dx;
      z = z+dz;
      float Disx = Tx - x;
      float Disz = Tz - z;

//Set both distance as positive value
      if(Disx < 0){
        Disx = -Disx;
      }

      if(Disz < 0){
        Disz = -Disz;
      }

// Calculate velocity for targetting
      if(Disz < Disx)
      {
        if(Tx < x){
          setlocalvar("x"+self, -Velx);
        } else { setlocalvar("x"+self, Velx); }

        setlocalvar("z"+self, Velx*(Tz-z)/Disx);
      } else {
        if(Tz < z){
          setlocalvar("z"+self, -Velz);
        } else { setlocalvar("z"+self, Velz); }

        setlocalvar("x"+self, Velz*(Tx-x)/Disz);
      }

    } else {
      if(Stop == 1)
      {
        setlocalvar("z"+self, 0);
        setlocalvar("x"+self, 0);
      } else {
        setlocalvar("z"+self, 0);
        if(dir==0){
          setlocalvar("x"+self, -Velx);
        } else { setlocalvar("x"+self, Velx); }
      }
    }

    setlocalvar("T"+self, NULL()); //Clears variable
}

and declare it like any target function:
Ex: @cmd targetI 2 2 0 0 0 1
 
Back
Top Bottom