A question about ondeathscript

Birnbaum

Member
Hello!

I'm trying to create a script to a boss.
Basically if the final blow throw the boss off the screen and the script made him return to the screen performing a jump to return and then ending the death animation.
The script doesnt work and I dont know exactly what is wrong.
Could be a mistake about the concept of how and when to use ondeathscript or a syntax error?

Thanks in advance.


Detail on the char header:
falldie 2
nodieblink 3

Code:
#include data/scripts/escript.c
void  main(){

        void    self = getlocalvar("self");
    int    x = getentityproperty(self,"x");
    int    z = getentityproperty(self,"z");
    int    WidthB = openborvariant("PLAYER_MAX_Z");
    int    WidthA = openborvariant("PLAYER_MIN_Z");
    int    Screen = openborvariant("hResolution");
    int    Base1;
    int    Base2;


        if(frame==1){  
                     if(x<=0){
        Base1    = x+Screen;
    Base2    = WidthB-(WidthA/2);
    targetPos(4.6,Base1,Base2);
    }
    if(x>Screen){    Base1 = x-Screen;
    Base2    = WidthB-(WidthA/2);
    targetPos(4.6,Base1,Base2);}
    }                     }
    if(frame==7){    leap(4.6); }

    }
}

//Functions used:

void targetPos(float Vy, int Tx, int Tz)
{// Targetting certain position before leaping there
//  Vy : Leaping speed
//  Tx : Leaping destination x coordinate
//  Tz : Leaping destination z coordinate
// Used with 'leap' or 'toss2'
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x"); // Get entity's x coordinate
    float z = getentityproperty(self, "z"); // Get entity's z coordinate

    if(Tx < x){
      changeentityproperty(self, "direction", 0); // Face left 
    } else {
      changeentityproperty(self, "direction", 1); // Face right
    }
    setlocalvar("x"+self, (Tx-x)/(20*Vy)); // Calculate Vx then store value in local variable
    setlocalvar("z"+self, (Tz-z)/(20*Vy)); // Calculate Vz then store value in local variable
} 


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!
    }
}
 
I've examined the script and found unpaired brackets:
Code:
    } // ?
      if(frame==7){
        leap(4.6);
      }
    } // ?

Still, even without those brackets, the script would not work because it couldn't acquire frame.

AFAIK ondeathscript is only run once : when entity dies. It won't be run again on 2nd frame, 8th frame or any centisecond later.

I believe you have DEATH animation, you should declare this script there instead :).

BTW:
Code:
      if(x<=0){
        Base1 = x+Screen;
        Base2 = WidthB-(WidthA/2);
        targetPos(4.6,Base1,Base2);
      }
      if(x>Screen){
        Base1 = x-Screen;
        Base2 = WidthB-(WidthA/2);
        targetPos(4.6,Base1,Base2);
      }

I'm only guessing but shouldn't it be like this?
Code:
      if(x<=0){
        Base1 = Screen/2;
        Base2 = (WidthB+WidthA)/2;
        targetPos(4.6,Base1,Base2);
      } else if(x>Screen){
        Base1 = Screen/2;
        Base2 = (WidthB+WidthA)/2;
        targetPos(4.6,Base1,Base2);
      }
 
@Bloodbane
Yes, the character has death and backdeath animations.
I forgot to use "elseif".
So if I need to use the ondeathscript, should I rewrite the script turning it on a function and add it to the frame 7( jump start) to work correctly?

Like this:

Code:
//ondeathscript death.c

#include data/scripts/escript.c

void main(){}

void deathjump(){

       void    self = getlocalvar("self");
    int    x = getentityproperty(self,"x");
    int    z = getentityproperty(self,"z");
    int    WidthB = openborvariant("PLAYER_MAX_Z");
    int    WidthA = openborvariant("PLAYER_MIN_Z");
    int    Screen = openborvariant("hResolution");
    int    Base1;
    int    Base2;

      if(x<=0){
        Base1 = Screen/2;
        Base2 = (WidthB+WidthA)/2;
        targetPos(4.6,Base1,Base2);
      } else if(x>Screen){
        Base1 = Screen/2;
        Base2 = (WidthB+WidthA)/2;
        targetPos(4.6,Base1,Base2);
      }

    }

//Function used:

void targetPos(float Vy, int Tx, int Tz)
{// Targetting certain position before leaping there
//  Vy : Leaping speed
//  Tx : Leaping destination x coordinate
//  Tz : Leaping destination z coordinate
// Used with 'leap' or 'toss2'
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x"); // Get entity's x coordinate
    float z = getentityproperty(self, "z"); // Get entity's z coordinate

    if(Tx < x){
      changeentityproperty(self, "direction", 0); // Face left
    } else {
      changeentityproperty(self, "direction", 1); // Face right
    }
    setlocalvar("x"+self, (Tx-x)/(20*Vy)); // Calculate Vx then store value in local variable
    setlocalvar("z"+self, (Tz-z)/(20*Vy)); // Calculate Vz then store value in local variable
}
 
should I rewrite the script turning it on a function

There's no need to convert it into a function, placing them in main() should be enough.

Though, storing in local variables doesn't work well so I suggest replacing it with entity variables like this:
C:
void targetPos(float Vy, int Tx, int Tz)
{// Targetting certain position before leaping there
//  Vy : Leaping speed
//  Tx : Leaping destination x coordinate
//  Tz : Leaping destination z coordinate
// Used with 'leap' or 'toss2'
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x"); // Get entity's x coordinate
    float z = getentityproperty(self, "z"); // Get entity's z coordinate

    if(Tx < x){
      changeentityproperty(self, "direction", 0); // Face left
    } else {
      changeentityproperty(self, "direction", 1); // Face right
    }
    setentityvar("x"+self, (Tx-x)/(20*Vy)); // Calculate Vx then store value in entity variable
    setentityvar("z"+self, (Tz-z)/(20*Vy)); // Calculate Vz then store value in entity variable
}


void leap(float Vely)
{// Leap with previously attained speed!
    void self = getlocalvar("self");
    float Vx = getentityvar("x"+self);
    float Vz = getentityvar("z"+self);

    if( Vx!=NULL() && Vz!=NULL() ){
      tossentity(self, Vely, Vx, Vz); //Leap towards target!
    }
}

If you're using leap function elsewhere, I suggest :
1. Creating new function for that updated leap function
OR
2. Change all functions which involves local variables in target.h to use entity variables instead.

add it to the frame 7( jump start) to work correctly?

You'd only need to declare leap function at 8th frame like this:
Code:
@cmd leap 4.6
frame ... # 8th frame
 
Back
Top Bottom