Solved 2 bosses share the same bar

Question that is answered or resolved.

dantedevil

Well-known member
It's possible create a way for the two different enemies bosses share the same health bar?

Like the Rude Bros. in Vendetta?

bYpPjNu.png
 
Last edited:
Solution
Oh I thought you don't need this anymore  ;D

Anyways, first, you need to have one boss spawn the other boss (doesn't have to be on screen) with this function:

Code:
void spawnMate(void vName, float fX, float fY, float fZ)
{//Spawns Mate next to caller
 //Spawned Mate & caller will know each other
 //vName: Model name of entity to be spawned in
 //fX: X location adjustment
 //fZ: Y location adjustment
 //fY: Z location adjustment

   void self = getlocalvar("self"); //Get calling entity
   int Health = getentityproperty(self, "health");
   int Map = getentityproperty(self, "map");
   void Mate; //Spawn object.
	
   Mate = spawn01(vName, fX, fY, fZ); //Spawn Mate
   changeentityproperty(Mate, "map", Map); //Match Mate's remap with self's...
Oh I thought you don't need this anymore  ;D

Anyways, first, you need to have one boss spawn the other boss (doesn't have to be on screen) with this function:

Code:
void spawnMate(void vName, float fX, float fY, float fZ)
{//Spawns Mate next to caller
 //Spawned Mate & caller will know each other
 //vName: Model name of entity to be spawned in
 //fX: X location adjustment
 //fZ: Y location adjustment
 //fY: Z location adjustment

   void self = getlocalvar("self"); //Get calling entity
   int Health = getentityproperty(self, "health");
   int Map = getentityproperty(self, "map");
   void Mate; //Spawn object.
	
   Mate = spawn01(vName, fX, fY, fZ); //Spawn Mate
   changeentityproperty(Mate, "map", Map); //Match Mate's remap with self's
   changeentityproperty(Mate, "maxhealth", Health); //Match Mate's health with self's
   changeentityproperty(Mate, "health", Health); //Match Mate's health with self's

   setentityvar(self, 0, Mate); //Store mate to self
   setentityvar(Mate, 0, self); //Store self to mate
}

then set this takedamagescript in both bosses' text:

Code:
void main()
{// Equalize health with mate's health
  void self = getlocalvar("self"); //Get calling entity
  void Mate = getentityvar(self, 0); //Find Mate
  void MateX = getentityproperty(Mate, "exists");
  int Health = getentityproperty(self,"health");

  if(Mate!=NULL() && MateX){
    if(Health > 0){
      changeentityproperty(Mate, "health", Health);
    } else {
      setentityvar(self, 0, NULL());
      setentityvar(Mate, 0, NULL());
      damageentity(Mate, self, 1000, 1, openborconstant("ATK_NORMAL"));
    }
  }
}

like this:

takedamagescript data/scripts/equal.c

After these, both bosses will have equal HP at all times
 
Solution
Well my friend, not work.
Something is wrong.

Here the error log:
Code:
********** An Error Occurred **********
*            Shutting Down            *

There's an exception while executing script 'animationscript' data/chars/bodyguard/bodyguard4.txtTotal Ram: 4294967295 Bytes
 Free Ram: 4294967295 Bytes
 Used Ram: 121274368 Bytes
Release level data........

In my test I try to spawn a "bodyguard" in "bodyguard4".

In "bodyguard4" set the spawnMate in the spawn animation
Code:
animationscript data/scripts/escript.c 
takedamagescript data/scripts/equal.c

anim spawn
	loop	0
	delay	20
	offset	82 177
	frame	data/chars/bodyguard/idle0.png
	frame	data/chars/bodyguard/idle1.png
	delay	28
	frame	data/chars/bodyguard/idle2.png
	delay	20
        @cmd    spawnMate "bodyguard" 100 0 0
	frame	data/chars/bodyguard/idle1.png

In escript.c add the spawnMate script.
When "bodyguard4" goes to spawn the "bodyguard", OpenBor closes
 
Do you have script.txt in data folder with this in it (at least):

maxentityvars  50

The method I'm using uses entity variables

If that doesn't solve the problem, can you post the whole log? I need to read it for the real error
 
You should use PasteBin in order for you to paste the entire thing for your post with a link. Each post is limited with 2000 characters (letters, numbers, symbols, etc.) here. There's nothing wrong with a few posts of yours here but I'm just pointing out for you to use so you can paste your entire log there and share link here. I'm not trying to be/sound judgmental, dictating, or moderating on what you do. I point out what's easier for you, man. :)
 
maxman said:
You should use PasteBin in order for you to paste the entire thing for your post with a link. Each post is limited with 2000 characters (letters, numbers, symbols, etc.) here. There's nothing wrong with a few posts of yours here but I'm just pointing out for you to use so you can paste your entire log there and share link here. I'm not trying to be/sound judgmental, dictating, or moderating on what you do. I point out what's easier for you, man. :)

Thanks my friend!
Did not know that page, it is certainly very useful.
Thanks again.
 
I am currently trying to use this method, so that the Spawnmate script can be executed by choosing with what exact animation you wish to spawn the enemy.
For this I try to mix this two scripts:
SpawnAnim:
Code:
[void spawnAniM(void vName, float fX, float fY, float fZ, void Ani, float Vx, float Vy, float Vz)
{
	//spawnB (Generic spawner) + Specific animation + velocities
	//Damon Vaughn Caskey + Douglas Baldan/O Ilusionista
	//07/06/2007 - 30/05/2013
	//
	//Spawns entity next to caller.
	//
	//vName: Model name of entity to be spawned in.
	//fX: X location adjustment.
	//fZ: Y location adjustment.
      //fY: Z location adjustment.

	void self = getlocalvar("self"); //Get calling entity.
        int  iMap = getentityproperty(self, "map"); // Get caller's remap.
	void vSpawn; //Spawn object.
	int  iDirection = getentityproperty(self, "direction");

	clearspawnentry(); //Clear current spawn entry.
      setspawnentry("name", vName); //Acquire spawn entity by name.

	if (iDirection == 0){ //Is entity facing left?                 
          fX = -fX; //Reverse X direction to match facing.
	}

      fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
      fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
      fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
	
	vSpawn = spawn(); //Spawn in entity.

	changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
	changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
    	performattack(vSpawn, openborconstant(Ani));
	changeentityproperty(vSpawn, "velocity", Vx, Vy, Vz);
        changeentityproperty(vSpawn, "map", iMap); //Set map.
	return vSpawn; //Return spawn.
}


And here the SpawMate:
Code:
void spawnMate(void vName, float fX, float fY, float fZ)
{//Spawns Mate next to caller
 //Spawned Mate & caller will know each other
 //vName: Model name of entity to be spawned in
 //fX: X location adjustment
 //fZ: Y location adjustment
 //fY: Z location adjustment

   void self = getlocalvar("self"); //Get calling entity
   int Health = getentityproperty(self, "health");
   int Map = getentityproperty(self, "map");
   void Mate; //Spawn object.
	
   Mate = spawn01(vName, fX, fY, fZ); //Spawn Mate
   changeentityproperty(Mate, "map", Map); //Match Mate's remap with self's
   changeentityproperty(Mate, "maxhealth", Health); //Match Mate's health with self's
   changeentityproperty(Mate, "health", Health); //Match Mate's health with self's

   setentityvar(self, 0, Mate); //Store mate to self
   setentityvar(Mate, 0, self); //Store self to mate
}

And here my try:
Code:
void spawnMate2(void vName, float fX, float fY, float fZ, void Ani)
{//Spawns Mate next to caller
 //Spawned Mate & caller will know each other
 //vName: Model name of entity to be spawned in
 //fX: X location adjustment
 //fZ: Y location adjustment
 //fY: Z location adjustment

   void self = getlocalvar("self"); //Get calling entity
   void vSpawn; //Spawn object.
   int  iDirection = getentityproperty(self, "direction");
   int Health = getentityproperty(self, "health");
   int Map = getentityproperty(self, "map");
   void Mate; //Spawn object.


	clearspawnentry(); //Clear current spawn entry.
      setspawnentry("name", vName); //Acquire spawn entity by name.

	if (iDirection == 0){ //Is entity facing left?                  
          fX = -fX; //Reverse X direction to match facing.
	}

      fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
      fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
      fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
	
	vSpawn = spawn(); //Spawn in entity.	
   Mate = spawn01(vName, fX, fY, fZ); //Spawn Mate
   changeentityproperty(Mate, "map", Map); //Match Mate's remap with self's
   changeentityproperty(Mate, "maxhealth", Health); //Match Mate's health with self's
   changeentityproperty(Mate, "health", Health); //Match Mate's health with self's
   changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
   changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
   performattack(vSpawn, openborconstant(Ani)); 

   setentityvar(self, 0, Mate); //Store mate to self
   setentityvar(Mate, 0, self); //Store self to mate

   return vSpawn; //Return spawn.
}

No doubt something is wrong, since the Script does not work properly. for some reason when using this to Spawn another enemy, instead of 1, Spawn 2 enemies and I do not understand why.


And something more, for some time I wanted to consult about this system. In order to use this system I need two different enemies, since I must use spawnmate and an entity can not spawn itself.
My question is this:
Is it not possible to use this system in some way that runs on the spawn in level?

It would be something like this :

Spawn  truck
alias      Tomax
takedamagescript data/script/equal.c
coords  600 230

Spawn truck
alias    Xamot
takedamagescript data/script/equal.c
coords 650 230

Then in equal.c, the idea would be that this Script is executed if you verify the name of the enemies, if the 2 o 3 o more, have the same, then run and share the health bar. That would be my idea to be able to use this with the same repeated enemy, sharing the same health bar.

I don't know if possible, buit maybe is an idea to explore.

PD: If this is possible, how do I add the custom Spawn in the levels.txt next to the takedamagescript?
 
I've thought about the second one and finally managed to code something for that :)

First you need this entity:
Code:
name	 Equalo
type	 none
shadow	 0


anim	idle
@script
    void self = getlocalvar("self");
    void Parent = getentityproperty(self, "parent"); // Get parent
    int Health = getentityproperty(self, "health"); // Get entity's health

    if(Parent){ //Have parent?
      int PHealth = getentityproperty(Parent, "health"); // Get parent's health
      int EHealth = getglobalvar("Equalo");

      if(EHealth == NULL()){
        EHealth = 5000;
      }

      if(EHealth <= 0){
        damageentity(Parent, self, 1, 1, openborconstant("ATK_NORMAL"));
      } else if(PHealth <= 0){
        setglobalvar("Equalo", PHealth);
        killentity(self);
      } else if(PHealth < EHealth){
        setglobalvar("Equalo", PHealth);
      } else if(PHealth > EHealth) {
        changeentityproperty(Parent, "health", EHealth);
      }
    }
@end_script
        loop    1
	delay	2
	offset	1 1
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif

Unlike other entities, LOAD this entity in models.txt instead of know

Then copy this script as equalis.c :
Code:
void main()
{
	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

	clearspawnentry(); //Clear current spawn entry.
        setspawnentry("name", "Equalo");
	
	vSpawn = spawn(); //Spawn in entity.

	changeentityproperty(vSpawn, "parent", self); //Set caller as parent.
        bindentity(vSpawn, self, 0, 1, 50, 0, 0);
}

and place it in data/scripts folder
Add this line in endlevel.c
Code:
  setglobalvar("Equalo", 5000);

To use this system, set spawnscript to enemies to be linked like this:
Code:
spawn	Jake
health	200
spawnscript data/scripts/equalis.c
coords	400 190 1
at	200

spawn	Bred
health	300
spawnscript data/scripts/equalis.c
coords	-100 220 1
at	0

spawn	Jay
health	300
spawnscript data/scripts/equalis.c
coords	500 230 1
at	0

In that example, even though Jay and Bred start with 300 health, equalis script will equalize their health with Jake's health which is lower i.e 200
When one of these enemies takes damage, the others will have their health equalized aka take same damage. IOW when one dies, the other will die too

HTH

PS: I missed the first part of your post Dante, so let me read that and think
 
Thank you very much my friend!
I'm going to try it right now.
The only doubt I have left is whether this system will generate any conflict with the fatalities script, as happened previously with the spawmate script.
 
Well my friend!

All works ok in the fatalities, but I found some bug.

When you kill an enemy, the other enemy fall in strange way.
In this video you can see two different cases.
In one case I elimate an enemy with the uppercut of fatality and the other case I eliminate it with a throw.
In both cases you can see the strange behavior that the other enemy has during his fall animation.

https://youtu.be/nJxlP7JfH4U
 
Back
Top Bottom