Solved void lifeCheck by %

Question that is answered or resolved.

dantedevil

Well-known member
I am currently working on the bonus stage and I have a problem.
In the bonus stage I have an obstacle that is changing anim follow, as it loses health.
Example:
Code:
anim idle
        loop    1
        delay    10
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        @cmd  lifeCheck 30 "ANI_FOLLOW1"
    frame    data/chars/misc/buda01.png

anim follow1
        loop    1 2 4
    delay    2
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        sound   data/sounds/stone.wav
    frame    data/chars/misc/buda02.png
    frame    data/chars/misc/buda02.png
        @cmd  lifeCheck 20 "ANI_FOLLOW2"
    frame    data/chars/misc/buda02.png
    frame    data/chars/misc/buda02.png

anim follow2
        loop    1 2 4
    delay    10
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        sound   data/sounds/stone.wav
    frame    data/chars/misc/buda03.png
    frame    data/chars/misc/buda03.png
        @cmd  lifeCheck 10 "ANI_FOLLOW3"
    frame    data/chars/misc/buda03.png
    frame    data/chars/misc/buda03.png

anim follow3
        loop    1 2 4
    delay    10
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        sound   data/sounds/stone.wav
    frame    data/chars/misc/buda04.png
    frame    data/chars/misc/buda04.png
        @cmd  lifeCheck 0 "ANI_FALL"
    frame    data/chars/misc/buda04.png
    frame    data/chars/misc/buda04.png

anim fall
    loop    0
    delay    12
        nodieblink    3
        offset    100 162
        @cmd    stop
    platform 0 0 0 0 0 0
        sound   data/sounds/stone2.wav
    frame    data/chars/misc/buda05.png
    frame    data/chars/misc/buda06.png
    frame    data/chars/misc/buda07.png
    frame    data/chars/misc/buda08.png
        @cmd    killentity getlocalvar("self")
    frame data/chars/misc/empty.png

Here the problem, in the bonus stage you see obstacle health for 2player2 and 3 player.
Code:
spawn  Buda
health  150
2phealth 350
3phealth 550
flip    1
coords  238 229

If 2 players, or 3 are playing, the energy will be greater than the one designated in the lifecheck script and it will not see well how the frames go to destroy the obstacle.

I think the solution would be to modify the following script, so that it works based on percentages, instead of doing so by checking the exact amount of health.


Code:
void lifeCheck (int iLife, void Ani)
// Check the life and change the animation if the life is higher than given value
// Douglas Baldan - 04/11/2013
{
     void self = getlocalvar("self");
     void Health = getentityproperty(self,"health");

      if(Health<=iLife)
      {
        changeentityproperty(self, "animation", openborconstant(Ani));
      }
     
}

Something like this:

Code:
anim idle
        loop    1
        delay    10
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        @cmd  lifeCheck 30% "ANI_FOLLOW1"
    frame    data/chars/misc/buda01.png

anim follow1
        loop    1 2 4
    delay    2
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        sound   data/sounds/stone.wav
    frame    data/chars/misc/buda02.png
    frame    data/chars/misc/buda02.png
        @cmd  lifeCheck 20% "ANI_FOLLOW2"
    frame    data/chars/misc/buda02.png
    frame    data/chars/misc/buda02.png

anim follow2
        loop    1 2 4
    delay    10
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        sound   data/sounds/stone.wav
    frame    data/chars/misc/buda03.png
    frame    data/chars/misc/buda03.png
        @cmd  lifeCheck 10% "ANI_FOLLOW3"
    frame    data/chars/misc/buda03.png
    frame    data/chars/misc/buda03.png

anim follow3
        loop    1 2 4
    delay    10
        offset    100 162
    bbox    74 80 52 82
        platform 100 165 -45 -45 45 45 20 500
        sound   data/sounds/stone.wav
    frame    data/chars/misc/buda04.png
    frame    data/chars/misc/buda04.png
        @cmd  lifeCheck 0 "ANI_FALL"
    frame    data/chars/misc/buda04.png
    frame    data/chars/misc/buda04.png

anim fall
    loop    0
    delay    12
        nodieblink    3
        offset    100 162
        @cmd    stop
    platform 0 0 0 0 0 0
        sound   data/sounds/stone2.wav
    frame    data/chars/misc/buda05.png
    frame    data/chars/misc/buda06.png
    frame    data/chars/misc/buda07.png
    frame    data/chars/misc/buda08.png
        @cmd    killentity getlocalvar("self")
    frame data/chars/misc/empty.png
 
Last edited:
Solution
You should've used percentage based script in the first place
Here's updated version using percentage base

Code:
void lifeCheck (int Percent, void Ani)
// Check the life and change the animation if the health falls below defined percentage
// Douglas Baldan - 04/11/2013
{
     void self = getlocalvar("self");
     int MHealth = getentityproperty(self,"maxhealth");
     int Health = getentityproperty(self,"health");

      if(Health/MHealth <= Percent/100)
      {
        changeentityproperty(self, "animation", openborconstant(Ani));
      }
	 
}

Ex: @cmd  lifeCheck 30 "ANI_FOLLOW1" means if health falls below 30%, change animation to FOLLOW1
You should've used percentage based script in the first place
Here's updated version using percentage base

Code:
void lifeCheck (int Percent, void Ani)
// Check the life and change the animation if the health falls below defined percentage
// Douglas Baldan - 04/11/2013
{
     void self = getlocalvar("self");
     int MHealth = getentityproperty(self,"maxhealth");
     int Health = getentityproperty(self,"health");

      if(Health/MHealth <= Percent/100)
      {
        changeentityproperty(self, "animation", openborconstant(Ani));
      }
	 
}

Ex: @cmd  lifeCheck 30 "ANI_FOLLOW1" means if health falls below 30%, change animation to FOLLOW1
 
Solution
Bloodbane said:
You should've used percentage based script in the first place
Here's updated version using percentage base

Code:
void lifeCheck (int Percent, void Ani)
// Check the life and change the animation if the health falls below defined percentage
// Douglas Baldan - 04/11/2013
{
     void self = getlocalvar("self");
     int MHealth = getentityproperty(self,"maxhealth");
     int Health = getentityproperty(self,"health");

      if(Health/MHealth <= Percent/100)
      {
        changeentityproperty(self, "animation", openborconstant(Ani));
      }
	 
}

Ex: @cmd  lifeCheck 30 "ANI_FOLLOW1" means if health falls below 30%, change animation to FOLLOW1

That's great my friend!
This is perfect!

Thanks!  ;D
 
I'm sorry, but just today I tried the script and I found a problem,

With just give a simple hit to the car, immediately start to pass all the anim follow, until you reach the fall and death.

It seems that there is something wrong with the script.

Here the bonus car with the script included:
Code:
name	car
health	500
nolife  1
type	obstacle
subtype    flydie
noatflash 1
flash	flash
shadow	0
noquake 1
falldie 1
score 3000 5


diesound data/sounds/phone.wav


animationscript data/scripts/spitems.h 


anim idle
	loop    1
	delay	10
	offset	105 154
	bbox	24 75 149 101 30
        platform 105 194 -125 -95 80 120 50 90
        @cmd  lifeCheckP 95 "ANI_FOLLOW1"
	frame	data/chars/misc/bonus/car/car01.png

anim follow1
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car02.png
	frame	data/chars/misc/bonus/car/car02.png
        @cmd  lifeCheckP 90 "ANI_FOLLOW2"
	frame	data/chars/misc/bonus/car/car02.png
	frame	data/chars/misc/bonus/car/car02.png

anim follow2
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car03.png
	frame	data/chars/misc/bonus/car/car03.png
        @cmd  lifeCheckP 85 "ANI_FOLLOW3"
	frame	data/chars/misc/bonus/car/car03.png
	frame	data/chars/misc/bonus/car/car03.png


anim follow3
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car04.png
	frame	data/chars/misc/bonus/car/car04.png
        @cmd  lifeCheckP 80 "ANI_FOLLOW4"
	frame	data/chars/misc/bonus/car/car04.png
	frame	data/chars/misc/bonus/car/car04.png

anim follow4
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car05.png
	frame	data/chars/misc/bonus/car/car05.png
        @cmd  lifeCheckP 76 "ANI_FOLLOW5"
	frame	data/chars/misc/bonus/car/car05.png
	frame	data/chars/misc/bonus/car/car05.png

anim follow5
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car06.png
	frame	data/chars/misc/bonus/car/car06.png
        @cmd  lifeCheckP 72 "ANI_FOLLOW6"
	frame	data/chars/misc/bonus/car/car06.png
	frame	data/chars/misc/bonus/car/car06.png

anim follow6
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car07.png
	frame	data/chars/misc/bonus/car/car07.png
        @cmd  lifeCheckP 68 "ANI_FOLLOW7"
	frame	data/chars/misc/bonus/car/car07.png
	frame	data/chars/misc/bonus/car/car07.png

anim follow7
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car08.png
	frame	data/chars/misc/bonus/car/car08.png
        @cmd  lifeCheckP 64 "ANI_FOLLOW8"
	frame	data/chars/misc/bonus/car/car08.png
	frame	data/chars/misc/bonus/car/car08.png

anim follow8
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car09.png
	frame	data/chars/misc/bonus/car/car09.png
        @cmd  lifeCheckP 60 "ANI_FOLLOW9"
	frame	data/chars/misc/bonus/car/car09.png
	frame	data/chars/misc/bonus/car/car09.png

anim follow9
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car10.png
	frame	data/chars/misc/bonus/car/car10.png
        @cmd  lifeCheckP 56 "ANI_FOLLOW10"
	frame	data/chars/misc/bonus/car/car10.png
	frame	data/chars/misc/bonus/car/car10.png

anim follow10
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car11.png
	frame	data/chars/misc/bonus/car/car11.png
        @cmd  lifeCheckP 52 "ANI_FOLLOW11"
	frame	data/chars/misc/bonus/car/car11.png
	frame	data/chars/misc/bonus/car/car11.png

anim follow11
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car12.png
	frame	data/chars/misc/bonus/car/car12.png
        @cmd  lifeCheckP 48 "ANI_FOLLOW12"
	frame	data/chars/misc/bonus/car/car12.png
	frame	data/chars/misc/bonus/car/car12.png

anim follow12
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car13.png
	frame	data/chars/misc/bonus/car/car13.png
        @cmd  lifeCheckP 44 "ANI_FOLLOW13"
	frame	data/chars/misc/bonus/car/car13.png
	frame	data/chars/misc/bonus/car/car13.png

anim follow13
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car14.png
	frame	data/chars/misc/bonus/car/car14.png
        @cmd  lifeCheckP 40 "ANI_FOLLOW14"
	frame	data/chars/misc/bonus/car/car14.png
	frame	data/chars/misc/bonus/car/car14.png

anim follow14
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car15.png
	frame	data/chars/misc/bonus/car/car15.png
        @cmd  lifeCheckP 36 "ANI_FOLLOW15"
	frame	data/chars/misc/bonus/car/car15.png
	frame	data/chars/misc/bonus/car/car15.png

anim follow15
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car16.png
	frame	data/chars/misc/bonus/car/car16.png
        @cmd  lifeCheckP 32 "ANI_FOLLOW16"
	frame	data/chars/misc/bonus/car/car16.png
	frame	data/chars/misc/bonus/car/car16.png

anim follow16
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car17.png
	frame	data/chars/misc/bonus/car/car17.png
        @cmd  lifeCheckP 28 "ANI_FOLLOW17"
	frame	data/chars/misc/bonus/car/car17.png
	frame	data/chars/misc/bonus/car/car17.png

anim follow17
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car18.png
	frame	data/chars/misc/bonus/car/car18.png
        @cmd  lifeCheckP 24 "ANI_FOLLOW18"
	frame	data/chars/misc/bonus/car/car18.png
	frame	data/chars/misc/bonus/car/car18.png

anim follow18
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car19.png
	frame	data/chars/misc/bonus/car/car19.png
        @cmd  lifeCheckP 20 "ANI_FOLLOW19"
	frame	data/chars/misc/bonus/car/car19.png
	frame	data/chars/misc/bonus/car/car19.png

anim follow19
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car20.png
	frame	data/chars/misc/bonus/car/car20.png
        @cmd  lifeCheckP 16 "ANI_FOLLOW20"
	frame	data/chars/misc/bonus/car/car20.png
	frame	data/chars/misc/bonus/car/car20.png

anim follow20
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car21.png
	frame	data/chars/misc/bonus/car/car21.png
        @cmd  lifeCheckP 12 "ANI_FOLLOW21"
	frame	data/chars/misc/bonus/car/car21.png
	frame	data/chars/misc/bonus/car/car21.png

anim follow21
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car22.png
	frame	data/chars/misc/bonus/car/car22.png
        @cmd  lifeCheckP 8 "ANI_FOLLOW22"
	frame	data/chars/misc/bonus/car/car22.png
	frame	data/chars/misc/bonus/car/car22.png

anim follow22
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car23.png
	frame	data/chars/misc/bonus/car/car23.png
        @cmd  lifeCheckP 4  "ANI_FOLLOW23"
	frame	data/chars/misc/bonus/car/car23.png
	frame	data/chars/misc/bonus/car/car23.png

anim follow23
        loop    1 2 4
	delay	2
	offset	105 154
	bbox	24 75 149 101
        platform 105 194 -125 -95 80 120 50 90
        sound   data/sounds/metal.wav
	frame	data/chars/misc/bonus/car/car24.png
	frame	data/chars/misc/bonus/car/car24.png
        @cmd    lifeCheck 0 "ANI_FALL"
	frame	data/chars/misc/bonus/car/car24.png
	frame	data/chars/misc/bonus/car/car24.png

anim fall
        loop    0
	delay	12
	offset	105 154
	bbox	0 0 0 0
        @cmd    stop
	sound   data/sounds/obstacle.wav
	frame	data/chars/misc/bonus/car/car25.png
	frame	data/chars/misc/bonus/car/car25.png

anim death
	loop 1
	delay	999
        nodieblink    3 
	offset	105 154
	frame	data/chars/misc/bonus/car/car25.png

And here your script:
Code:
void lifeCheckP (int Percent, void Ani)
// Check the life and change the animation if the health falls below defined percentage
// Douglas Baldan - 04/11/2013
//update by Bloodbane - 18/11/2017
{
     void self = getlocalvar("self");
     int MHealth = getentityproperty(self,"maxhealth");
     int Health = getentityproperty(self,"health");

      if(Health/MHealth <= Percent/100)
      {
        changeentityproperty(self, "animation", openborconstant(Ani));
      }
	
}

 ;)

I just only change the "lifeCheck" for "lifeCheckP", to differentiate it from the old lifeCheck script.
 
Looks like OpenBoR handles division differently
Anyways, here's the fixed version:

Code:
void lifeCheckP (int Percent, void Ani)
// Check the life and change the animation if the health falls below defined percentage
// Douglas Baldan - 04/11/2013
//update by Bloodbane - 18/11/2017
{
     void self = getlocalvar("self");
     int MHealth = getentityproperty(self,"maxhealth");
     int Health = getentityproperty(self,"health");

      if(Health*100 <= Percent*MHealth){
        changeentityproperty(self, "animation", openborconstant(Ani));
      }	
}
 
Bloodbane said:
Looks like OpenBoR handles division differently
Anyways, here's the fixed version:

Code:
void lifeCheckP (int Percent, void Ani)
// Check the life and change the animation if the health falls below defined percentage
// Douglas Baldan - 04/11/2013
//update by Bloodbane - 18/11/2017
{
     void self = getlocalvar("self");
     int MHealth = getentityproperty(self,"maxhealth");
     int Health = getentityproperty(self,"health");

      if(Health*100 <= Percent*MHealth){
        changeentityproperty(self, "animation", openborconstant(Ani));
      }	
}

Now works perfect my friend!

Thanks!  :)
 
Back
Top Bottom