• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Targeting Script

Is there a script to target nearby enemies during an attack? I want to have the player rush towards the enemy and perform a rush combo attack. I checked the scripts section but I don't see anything for this type of attacks
 
Here the script:
Code:
void targetL(float Vy, float dx, float dz)
{// Targetting opponent before performing targetted leap attack
// Vy = y Velocity
// dx = x added distance
// dz = z added distance

    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(Tx < x){
        changeentityproperty(self, "direction", 0);
      } else {
        changeentityproperty(self, "direction", 1);
      }

      x = x+dx;
      z = z+dz;
      setlocalvar("x"+self, (Tx-x)/(22*Vy));
      setlocalvar("z"+self, (Tz-z)/(22*Vy));

    } else {
      setlocalvar("z"+self, 0);
      setlocalvar("x"+self, 0);
    }
}

To use this script, you must add the dash or leap script.
Code:
void dash()
{// Dash with previously attained speed!
    void self = getlocalvar("self");
    float Vx = getlocalvar("x"+self);
    float Vz = getlocalvar("z"+self);
    if( Vx!=NULL() && Vz!=NULL() ){
      changeentityproperty(self, "velocity", Vx, Vz); //Move towards target!
    }
}
void leap(float Vely)
{// Leap with previously attained speed!
    void self = getlocalvar("self");
    float Vx = getlocalvar("x"+self);
    float Vz = getlocalvar("z"+self);
    if( Vx!=NULL() && Vz!=NULL() ){
      tossentity(self, Vely, Vx, Vz); //Leap towards target!
    }

}

Here I leave you two examples of how to use it:

with leap:
        @cmd    target 0.7 0.5 0 0 1
        @cmd    leap 4
frame data/chars/caro/jump0.png

with dash:
        @cmd    target 1 1 0 0 2
        @cmd    dash
frame data/chars/midas/at2c.png
 
I got this error message when I implemented the script

Code:
Script compile error: can't find function 'target'

Script compile error in 'animationscript': target line 25, column 12

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'animationscript' data/chars/Yususke/Yususke.txt
Total Ram: 4207882240 Bytes
 Free Ram: 2183176192 Bytes
 Used Ram: 37928960 Bytes

Release level data...........	Done!
Release graphics data........	Done!
Release game data............


Release game data............	Done!
Release timer................	Done!
Release input hardware.......	Done!
Release sound system.........	Done!
Release FileCaching System...	Done!

**************** Done *****************

Can't compile script 'animationscript' data/chars/Yususke/Yususke.txt
 
Code:
anim	freespecial4
	com	D F A freespecial4
	fastattack	1
	delay	15
	offset	25 66
        @cmd    target 0.7 0.5 0 0 1
        @cmd    leap 4
	frame	data/chars/yususke/turn.png
	delay	15
	offset	25 48
	frame	data/chars/yususke/fd.png
	delay	5
	offset	21 67
 	frame	data/chars/yususke/rp1.png
	attack	30 1 20 15 7 0 1 0 9 0
	delay	10
	offset	20 66
	frame	data/chars/yususke/qp2.png
	attack	0 0 0 0 0 0 0 0 0 0
	delay	5
	offset	21 66
	frame	data/chars/yususke/qp1.png
	delay	5
	offset	19 53
	frame	data/chars/yususke/uc2.png
	attack	37 3 19 28 9 0 1 0 8 0
	delay	9
	offset	19 58
	frame	data/chars/yususke/uc3.png
	attack	0 0 0 0 0 0 0 0 0 0
	delay	5
	offset	19 53
	frame	data/chars/yususke/uc2.png
	attack	30 1 20 15 7 0 1 0 9 0
	delay	10
	offset	20 66
	frame	data/chars/yususke/qp2.png
	attack	0 0 0 0 0 0 0 0 0 0
	delay	5
	offset	21 66
	frame	data/chars/yususke/qp1.png
	delay	5
	offset	16 64
	frame	data/chars/yususke/hk1.png
	delay	9
	attack	19 14 12 18 9 0 1 0 5 0
	offset	15 67
	frame	data/chars/yususke/sk1.png
	attack	0 0 0 0 0 0 0 0 0 0
	delay	7
	offset	25 66
	frame	data/chars/yususke/mp1.png
	delay	5
	offset	21 68
	frame	data/chars/yususke/qk1.png
	attack	35 3 28 16 8 0 1 0 12 0
	delay	9
	offset	32 68
	frame	data/chars/yususke/qk2.png
	attack	0 0 0 0 0 0 0 0 0 0
	delay	5
	offset	21 68
	frame	data/chars/yususke/qk1.png
	delay	5
	offset	16 64
	frame	data/chars/yususke/hk1.png
	delay	5
	offset	16 67
	frame	data/chars/yususke/sk1.png
	delay	9
	attack	39 11 19 16 8 2 1 0 12 0
	dropv	3 3 0
	offset	10 67
	frame	data/chars/yususke/sk3.png
	delay	5
	offset	8 70
	frame	data/chars/yususke/hk3.png
	delay	12
	offset	10 78
	frame	data/chars/yususke/sk2.png
	delay	5
	offset	10 67
	frame	data/chars/yususke/sk3.png
	delay	5
	offset	21 66
	frame	data/chars/yususke/mp1.png
 
In the error log says:
Code:
Script compile error: can't find function 'target'

So you add all the script in your animationscript?
 
Sorry for my question, bit is better ask.

You have in you character txt the line:

animationscript data/scripts/script.c
 
Sorry, it was my fault.
I found the error.
Instead of giving the target script, i gave the targerL
script.

Here the correct:
void target(float Velx, float Velz, float dx, float dz, int Stop)
{// 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(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); }
      }
    }
}

My apologies.
 
hey this is really good, it's like 8 years old so i wanted to check if there was a newer version

Also, is there a way to stop the dash momentum? I have an animation that's pretty long, i want the movement to happen at the beginning of the attack but stop before the wind down

edit: in order to stop momentum, add this whereever you want to stop
@cmd target 0 0 0 0 1
@cmd dash
 
Last edited:
Question, can someone help alter the above targetting script so that the player character does NOT turn around?
 
Remove this block:

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

HTH,
DC
 
I've just noticed that the target function is really old one. The latest version has flip parameter to define if entity would flip to target or not if target is found.
 
You already have the function, it's in target.h in data/scripts/library folder. Here's the function:
C:
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
}
 
Back
Top Bottom