[solved] pain in obstacles

O Ilusionista

Captain 100K
I noticed that obstacles can't have a pain animation (or its isn't working), so I will need some help here.

I would like to make a Cola vending machine (remeber Avengers game?), where you can hit the machine few times before it explodes (so it can't die on the first hit).
On each hit, I will make it spawn a cola item, which will heal you a bit.

How its the best way to make it?
 
At the start I was sure obstables can allow pain anims.
And finally figured that this is not possible. (certainly witout using some scripts)

But it still interests me.
 
Here is the solution:

on the IDLE anim, put this:

Code:
counterrange	0 4 3 1
followanim	1

Reffer to the manual for the values:

counterrange {start} {end} {condition} {damage}

~Animation header. Replaces Counterframe and works identically except where noted.
~{start} Start of frame range when counter may trigger.
~{end} End of frame range when counter may trigger.
~cond determines the condition requirements before FOLLOW{#} is played.
1: The counter will always be used.
2: The counter will be used as long as the attacker was an enemy (Or a player if an enemy uses it).
3: The counter will be used as long as the attacker was an enemy, the attack was not unblockable, hits the user from the front, and was not a FREEZE attack.
~damaged determines whether the entity will receive damage from the hit or not.
0, the damage won't be taken
1, the damage will be taken.
~Which FOLLOW animation played is determined by 'followanim'.

Edit: we will need a little trick to make it work as we wanted to.
Let me post all the codes:

Char header
name colamachine
health 20
type obstacle
gfxshadow 1
diesound data/sounds/klunk.wav
nolife 1

Idle animation
anim idle
delay 1000
offset 100 147
counterrange 0 4 3 1
followanim 1

bbox 79 83 48 68
platform 101 149 -19 -20 18 19 10 54
frame data/chars/misc/cola/cola0.png

The idle use a counterrange to send the machine to the follow1 anim:

anim follow1
delay 4
offset 100 147
bbox 79 83 48 68
@script
    if(frame==0){
      void self = getlocalvar("self");
      void Health = getentityproperty(self,"health");

      if(Health<=0)
      {
        changeentityproperty(self, "animation", openborconstant("ANI_FALL"));
      }
    }
@end_script

frame data/chars/misc/cola/cola0.png
offset 98 147
@cmd spawn01 "cola" 0 20 0
frame data/chars/misc/cola/cola0.png
delay 60
offset 100 147
@cmd anichange "ANI_IDLE"
frame data/chars/misc/cola/cola0.png

We check the life to see if the entity still have life. If it doesn't have, it will go to FALL anim, but if it has life, the animation continue and we force it to return to idle animation.

Why this is necessary?

I dunno why, but even if you set "Life 1", the entity won't die directly, it will play the follow1 anim, even if its life is 0 (counterrange is set to make the entity receive damage). And if you don't tell the entity to return to idle, it will be stuck on the follow1 anim and won't die. Don't ask me why.

Then at the Follow1 anim, I just set a jumpframe (to make it fly a bit) and use a SUICIDE to destroy itself.

Thanks Lagarto!

Edit2: I made a small script to make it easier:

Put this in your animationscript
Code:
void lifeCheck (int iLife, void Ani)
// Check the life and change the animation if the life is lower 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));
      }
	  
}

Then I just call it:
Code:
@cmd	lifeCheck 0 "ANI_FALL"
 
that is another solution, but this would bring some problems:
- enemies would attack it
- I need to add NPC on the list of things I can attack, and I don't want to attack all NPC (ok, I could simply do not put a bbox on the NPCs I should not attack)
 
yes it ruins npc cause now you would have enemy npc or friendly npc dillemas,. normally you dont want to attack npc cauyse they help you, changing to type enemy maybe works but has to be nomove 1 1.
 
Yes, with a bit of script. just check the car "life" and spawn a random debris. Then if the life is <then a certain value, change the animation to pain2, etc

if you need the debris to be random, use this code I created:

void spawnRandom(void vName,int vx, int vy )
// Spawn entity at random places
// 24.09.2013 - Douglas Baldan - O Ilusionista
{
int Xr = rand()%vx; // Random X pos
int Yr = rand()%vy; // Random Y pos

spawn01(vName,vx+Xr,vy+Yr,0);
}
 
I have some problems to use this system.
This is my obstacle:
Code:
name	   andamio
health	   30
type	   obstacle
candamage  player enemy
gfxshadow  1
nolife 1
flash		flash
noatflash	1



load  down

animationscript data/scripts/obstacle.c 


anim spawn
        loop    0
	delay	1
	offset	102 318
	bbox	29 125 146 194
	platform 102 328 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png



anim idle
        loop    0
	delay	1000
        counterrange 0 4 3 1
        followanim 1
	offset	102 318
	bbox	29 125 146 194
	platform 102 328 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png


anim follow1
        loop    0
	delay	4
	offset	102 318
	bbox	29 125 146 194
	sound data/sounds/klunk.wav
        @cmd    lifeCheck 0 "ANI_FALL"
	platform 318 112 -100 -100 100 100 30 1100
	frame   data/chars/misc/andamio01.png
	frame   data/chars/misc/andamio00.png
        @cmd    anichange "ANI_IDLE"
	frame	data/chars/misc/andamio01.png



anim fall
        loop    0
	delay	1
	offset	102 318
	bbox	29 125 146 194
	platform 102 328 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png
        nodieblink    3 
	offset	102 318
	delay   12
	platform 102 328 -100 -100 100 100 30 1100
	bbox	0 0 0 0
	frame	data/chars/misc/andamio00.png
	frame	data/chars/misc/andamio02.png
	frame	data/chars/misc/andamio00.png
	frame	data/chars/misc/andamio01.png
	delay   10
	frame	data/chars/misc/andamio02.png
	delay   8
	frame	data/chars/misc/andamio03.png
	delay   6
	frame	data/chars/misc/andamio04.png
	delay   5
	frame	data/chars/misc/andamio05.png
	delay   4
        hitfx    data/sounds/indirect.wav
        hitflash flash2
	platform 0 0 0 0 0 0
	attack49  119 87 101 165 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio06.png
	attack49  114 105 101 204 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio07.png
	attack49  171 58 62 248 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio08.png
	attack49  175 70 81 232 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio09.png
	attack49  149 124 166 121 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio10.png
	attack49  197 133 190 109 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio11.png
	attack49  185 156 232 104 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio12.png
	attack49  182 243 256 36 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio13.png
        attack  0 0 0 0
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio14.png
        attack  0 0 0 0
	sound   data/sounds/ironfall.wav
        quakeframe 17 6 4
        subentity down
        spawnframe 17 260 -2 0 0
	platform 102 328 44 44 365 365 30 1100
	frame	data/chars/misc/andamio14.png
	delay   10
	frame	data/chars/misc/andamio14.png
	frame	data/chars/misc/andamio14.png
	frame	data/chars/misc/andamio14.png
	frame	data/chars/misc/andamio14.png
	frame	data/chars/misc/andamio14.png
	frame	data/chars/misc/andamio14.png
Its a some type of scaffold, when you hit him, he fall over the enemies.

Here the problem,  using this system to make the pain animation,  when a hero hits the obstacle OpenBor crash.

Here a resume Log:

Code:
Function need a valid entity handle and at an interger parameter: updateframe(entity, int frame)
Script function 'updateframe' returned an exception, check the manual for details.
 parameters: #218314928, <VT_EMPTY>   Unitialized,  
 
********** An Error Occurred **********
*            Shutting Down            *

There's an exception while executing script 'animationscript' data/chars/misc/andamio.txtTotal Ram: 4294967295 Bytes
 Free Ram: 4294967295 Bytes
 Used Ram: 133115904 Bytes


Warning: 8 script variants are not freed, dumping...
openbor_array
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite
openbor_loadsprite

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

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

There's an exception while executing script 'animationscript' data/chars/misc/andamio.txt

I try with both ways, settings the complete scrip in Follow 1, or calling the script for te animation script.  But the result it's the same.
 
Finaly can make work!

I make some changes in the obstacle:
Code:
name	   andamio
health	   20
type	   obstacle
candamage  player enemy
hostile    player enemy
subtype    flydie
nomove 1
gfxshadow  1
nolife 1
flash		flash
noatflash	1
falldie 1
offscreenkill	300
setlayer 150


load  down

animationscript data/scripts/obstacle.c 


anim spawn
        loop    0
	delay	1
	offset	102 315
	bbox	29 125 146 194
	platform 102 325 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png



anim idle
        loop    0
	delay	1000
        counterrange 0 4 3 1
        followanim 1
	offset	102 315
	bbox	29 125 146 194
	platform 102 325 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png



anim follow1
        loop    0
	delay	4
	offset	102 315
	bbox	29 125 146 194
	sound data/sounds/klunk.wav
        @cmd  lifeCheck 0 "ANI_FALL"
	platform 102 325 -100 -100 100 100 30 1100
	frame   data/chars/misc/andamio01.png
	frame   data/chars/misc/andamio00.png
        @cmd    anichange "ANI_IDLE" 0
	frame	data/chars/misc/andamio01.png




anim fall
        loop    0
@script
    void self = getlocalvar("self");

    if(frame == 0){
      changeentityproperty(self, "velocity", 0, 0, 0);
      changeentityproperty(self, "speed", 0.0);
    }
@end_script
	delay	12
	offset	102 315
	bbox	0 0 0 0
	platform 102 325 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png
	frame	data/chars/misc/andamio02.png
	frame	data/chars/misc/andamio00.png
	frame	data/chars/misc/andamio01.png
	delay   10
	frame	data/chars/misc/andamio02.png
	delay   8
	frame	data/chars/misc/andamio03.png
	delay   6
	frame	data/chars/misc/andamio04.png
	delay   5
	frame	data/chars/misc/andamio05.png
	delay   4
        hitfx    data/sounds/indirect.wav
        hitflash flash2
	platform 0 0 0 0 0 0
	attack49  119 87 101 165 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio06.png
	attack49  114 105 101 204 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio07.png
	attack49  171 58 62 248 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio08.png
	attack49  175 70 81 232 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio09.png
	attack49  149 124 166 121 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio10.png
	attack49  197 133 190 109 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio11.png
	attack49  185 156 232 104 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio12.png
	attack49  182 243 256 36 200 1 1 0 10 20
        dropv   1 2 -0.2
	frame	data/chars/misc/andamio13.png
	delay   8
	sound   data/sounds/ironfall.wav
        quakeframe 17 6 4
        subentity down
        spawnframe 17 260 -2 0 0
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio14.png
	delay   6
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio15.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio16.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio17.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio18.png
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio19.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 -1
	frame	data/chars/misc/andamio20.png
        attack  0 0 0 0
	frame	data/chars/misc/andamio21.png
	delay   10
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png



anim death
	loop	1
	delay	100
        nodieblink    3 
	offset	102 315
	frame	data/chars/misc/andamio21.png

I don't know exactly wath the problem,  but this work perfect.
 
I found a rare bug using this method to make the pain animation in obstacles.

Here my obstacle:
Code:
name	   Andamio2
health	   20
type	   obstacle
candamage  player enemy
hostile    player enemy
subtype    flydie
nomove 1
gfxshadow  1
nolife 1
flash		flash
noatflash	1
falldie 1
offscreenkill	300



load  down

animationscript data/scripts/obstacle.c 


anim spawn
        loop    0
	delay	1
	offset	102 315
	bbox	29 125 146 194
	platform 102 325 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png



anim idle
        loop    0
	delay	1000
        counterrange 0 4 3 1
        followanim 1
	offset	102 315
	bbox	29 125 146 194
	platform 102 325 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png



anim follow1
        loop    0
	delay	4
	offset	102 315
	bbox	29 125 146 194
	sound data/sounds/klunk.wav
        @cmd  lifeCheck 0 "ANI_FALL"
	platform 102 325 -100 -100 100 100 30 1100
	frame   data/chars/misc/andamio01.png
	frame   data/chars/misc/andamio00.png
        @cmd    anichange "ANI_IDLE" 0
	frame	data/chars/misc/andamio01.png




anim fall
        loop    0
@script
    void self = getlocalvar("self");

    if(frame == 0){
      changeentityproperty(self, "velocity", 0, 0, 0);
      changeentityproperty(self, "speed", 0.0);
    }
@end_script
	delay	12
	offset	102 315
	bbox	0 0 0 0
	platform 102 325 -100 -100 100 100 20 1100
	frame	data/chars/misc/andamio00.png
	sound   data/sounds/ironfall.wav
	frame	data/chars/misc/andamio02.png
	frame	data/chars/misc/andamio00.png
	frame	data/chars/misc/andamio01.png
	delay   10
	frame	data/chars/misc/andamio02.png
	delay   8
	frame	data/chars/misc/andamio03.png
	delay   6
	frame	data/chars/misc/andamio04.png
	delay   5
	frame	data/chars/misc/andamio05.png
	delay   4
        hitfx    data/sounds/indirect.wav
        hitflash flash2
	platform 0 0 0 0 0 0
	attack49  119 87 101 165 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio06.png
	attack49  114 105 101 204 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio07.png
	attack49  171 58 62 248 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio08.png
	attack49  175 70 81 232 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio09.png
	attack49  149 124 166 121 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio10.png
	attack49  197 133 190 109 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio11.png
	attack49  185 156 232 104 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio12.png
	attack49  182 243 256 36 200 1 1 0 10 20
        dropv   1 2 0
	frame	data/chars/misc/andamio13.png
	delay   8
        quakeframe 17 6 4
        @cmd    spawn01 "down" 260 0 -2
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
	frame	data/chars/misc/andamio14.png
	delay   10
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
	frame	data/chars/misc/andamio15.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
	frame	data/chars/misc/andamio16.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
	frame	data/chars/misc/andamio17.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
@script
void self = getlocalvar("self");

if(frame == 21){
  changeentityproperty(self, "setlayer", -1);
}

@end_script
	frame	data/chars/misc/andamio18.png
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
	frame	data/chars/misc/andamio19.png
        otg 1
	attack49  174 262 264 55 200 1 1 0 10 20
        dropv   0.5 0.2 0
	frame	data/chars/misc/andamio20.png
        attack  0 0 0 0
	frame	data/chars/misc/andamio21.png
	delay   10
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png
	frame	data/chars/misc/andamio21.png



anim death
	loop	1
	delay	100
        nodieblink    3 
	offset	102 315
	frame	data/chars/misc/andamio21.png

The pain animation in this obstacle works perfect.

But, here the problem:
As you see in the idle animation you can find this lines:

        counterrange 0 4 3 1
        followanim 1


Seems when the obstacle using this, Openbor not recognized as an obstacle.

I have some move in my heros with a cancelgrab script before start the slam.
Code:
void cancelgrab()
        {// Check grabbed opponent's name
        // If it's forbidden to grab him/her, revert to IDLE
           void self = getlocalvar("self");
           void target = getlocalvar("Target" + self);

           if(target==NULL())
           {
             target = getentityproperty(self, "opponent");
             setlocalvar("Target" + self, target);
           }
           if(target!=NULL())
           {
             char Tname = getentityproperty(target, "defaultname");
             char iType = getentityproperty(target, "type");

             if(Tname == "GORO" || Tname == "KINTARO" || Tname == "MOTARO" || Tname == "KIMOKAHN" || 

Tname == "BULLDOZER" || Tname == "KNIFER" || Tname == "KNIFER2" || iType == openborconstant

("TYPE_OBSTACLE") || iType ==openborconstant("TYPE_ITEM"))
             {
                 changeentityproperty(self, "animation", openborconstant("ANI_FREESPECIAL15"));
             }
           }
        }

With this cancelgrab, when the heros perform the animation close to an obstacle, the hero's play ANI_FREESPECIAL15.

This work on the "Andamio" only if remove the lines:
        counterrange 0 4 3 1
        followanim 1


With the lines the cancelgrab not work, so the heros perform the grab animation without grab the "Andamio", or grabing the body of the most closer enemy, no matter if the enemy is dead, the hero perform the grab with him.

So what happened here??

PD: I try adding "Andamio" in the names of cancelgrab script, but not work.
I try adding this script in the animations of the Andamio:
Code:
@script
if(frame==1)
{
  changeentityproperty(getlocalvar("self"), "type", openborconstant("TYPE_OBSTACLE"));
}
@end_script
It does not work...



 
Dante, I have a new version which will even let you use different animations based on the attacker facing, take a look:
 
Last edited:
O Ilusionista said:
Dante, I have a new version which will even let you use different animations based on the attacker facing, take a look:
http://www.chronocrash.com/forum/index.php?board=20.0
That's great my friend!
Thanks for the info.
;)
 
Back
Top Bottom