Solved To play an animation when the player gets a life to achieved score

Question that is answered or resolved.

Steven1985

Active member
Hi, I would like to know how to play an animation when the player gets a life having achieved a certain score like Cadillacs and Dinosaurs.
Thank you in advance.
 
Solution
Thanks for sharing the video, now I remember having such animation before.

Anyways, I've coded something for this and it works. Though like I've mentioned before, it involves multiple files to work properly and stable.
First, you'd need score1.c which is player 1's score script:
C:
void main()
{
    int PScore = getplayerproperty(0, "score");
    int PLives = getplayerproperty(0, "lives"); // Get player 1's lives
    int P1S = getglobalvar("1M"); //Get player 1's score status
    int ScoReq = 20000;

    if(P1S == NULL()){
      P1S = 0;
    }

//Player notif
    if(PScore >= ScoReq*(P1S+1)){
      setglobalvar("1Win", "W");
    }

//Player 1
    while(PScore >= ScoReq*(P1S+1)){
      changeplayerproperty(0, "lives", PLives+1)...
I can't recall if I ever had such animation before in Cadillacs and Dinosaurs but I did see one in Kings of Dragons.

Anyways, I can imagine how to implement this with script but it won't be simple aka might include multiple files for stability.
 
Thanks for sharing the video, now I remember having such animation before.

Anyways, I've coded something for this and it works. Though like I've mentioned before, it involves multiple files to work properly and stable.
First, you'd need score1.c which is player 1's score script:
C:
void main()
{
    int PScore = getplayerproperty(0, "score");
    int PLives = getplayerproperty(0, "lives"); // Get player 1's lives
    int P1S = getglobalvar("1M"); //Get player 1's score status
    int ScoReq = 20000;

    if(P1S == NULL()){
      P1S = 0;
    }

//Player notif
    if(PScore >= ScoReq*(P1S+1)){
      setglobalvar("1Win", "W");
    }

//Player 1
    while(PScore >= ScoReq*(P1S+1)){
      changeplayerproperty(0, "lives", PLives+1); // Give life
      P1S = P1S + 1;
    }

    setglobalvar("1M", P1S);
}

This script will notify player 1 is score has reached minimum requirement to earn 1up.
Second, speaking of player, you'd need this script in each character's IDLE to perform the animation:
C:
anim    idle
@script
  if(frame>=1){
    void self = getlocalvar("self");
    char Win = getglobalvar("1Win"); //Get player 1's notif

    if(Win=="W"){
      setglobalvar("1Win", 0);

      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
  }
@end_script
...

This script will make character perform FOLLOW1 when score1.c has sent the notif.
Third, you have to set super high lifescore in models.txt to disable default 1up bonus.

Fourth, to stabilize this system, you'd need to reset some variables in update.c with this line:
Code:
  if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen")){
      setglobalvar("1M", NULL()); // resets 1up bonus counter
  }

and in endlevel.c
Code:
  setglobalvar("1Win", 0);

This script might need update for multiplayer but it works.
 
Solution
Hi, @Bloodbane
reviewing your answer above, I had some doubts:
1) I think score1.c must be declared in the character header: data/scripts/score1.c
2) If I already have a script in an animation, is it possible to insert another one?
Example:
anim idle
@script
....
@endscript
@script
...
@endscript
3) if there is no update.c and endlevel.c in the game, do I create them in the scripts folder and just put the lines you wrote?
 
1) I think score1.c must be declared in the character header: data/scripts/score1.c

No, it doesn't need to declared anywhere.

2) If I already have a script in an animation, is it possible to insert another one?
Example:
anim idle
@script
....
@endscript
@script
...
@endscript

I think it is but it's best to merge them into one script.

3) if there is no update.c and endlevel.c in the game, do I create them in the scripts folder and just put the lines you wrote?

Yes, if you don't have any of those, create them.
 
Hi @Bloodbane , I did as you wrote but I have this error:
Script error: data/scripts/update.c, line 2: Invalid external declaration 'if' (in production 'external_decl')

if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen")){
^
 
You are missing void main() as a starting point in update.c. That's why it crashes. It should be like this:

C:
void main(){
    if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen")){
      setglobalvar("1M", NULL()); // resets 1up bonus counter
    }
}
 
Back
Top Bottom