Solved Destroying binded entities by script

Question that is answered or resolved.
Hello there, fellow developers!

Code:
//Direction
//  0 = No change
//  1 = Same direction as parent
// -1 = Opposite direction as parent
//  2 = Always right
// -2 = Always left

//BindFlag:
//  0 = No effect
//  1 = Keep same animation as target
//  2 = Also keep same frame as target
//  4 = Kill binded entity if animation doesn't match
//  5 = Keep same animation as target and kill binded entity if animation doesn't match 
//  6 = Keep same frame as target and kill binded entity if animation doesn't match 

//Example: @cmd spawnbind "Naruto_Rasengan" "ANI_FOLLOW10" 0 0 0 1 0
//Result: Binds a Rasengan on the caller, running its "Follow 10" animation.

void spawnbind(void ChildName, void ChildAnim, float OffsetX, float OffsetY, float OffsetZ, int Direction, int BindFlag)
{
	void self = getlocalvar("self");										//Spawnin parent entity.
	void Child;																//Spawned child entity.

	clearspawnentry();														//Clear current spawn entity.
	setspawnentry("name", ChildName);											//Set spawn entity by it's name.
  	
  	Child = spawn();														//Spawn child entity.
	
	changeentityproperty(Child, "parent", self);							//Set child's parent.
	performattack(Child, openborconstant(ChildAnim));

	
return Child;

	bindentity(Child, self, OffsetX, OffsetY, OffsetZ, Direction, BindFlag);
}

void unbind()
{
	void self = getlocalvar("self");
	bindentity(self, NULL());
}

This is the script that i'm using to spawn and bind entities. But I need a script to unbind (and thus, destroy) the binded entities in a character without changing animations.

Any suggestions?
 
Within the binded entities animation frames add this line @cmd killentity getlocalvar("self") also you can set lifespan {time} in the entity header data to it will die after a certain amount of time that you set.  Personally I use both.
 
I would rather use some script in the "binder" entity, instead of the binder one, since the timing of each special attack would change, and I wouldn't like to make one different animation for each.
 
Hi Paulo HP Bender!

I had a similar problem and my solution may can help you. An alternative way that I found to unbind an entity is saving the spawned entity in a variable and then it will be acessible by unbind script. In my case I need to unbind if players are killed by TIME OVER, because they will execute FALL animation before release the grabbed entity by an "animation script" called "depost" in the last frame.

Here's a example of my script:

Code:
void slamstart()
{//Slam Starter for grab slams
//Use finish or throw after using this
	void self = getlocalvar("self");
	void target = getlocalvar("Target"+self);

	if(target == NULL()){
		target = getentityproperty(self, "grabbing"); //Get grabbed entity
		setlocalvar("Target"+self, target);
		setentityvar(self, "binded", target); //Save grabbed entity in a entityvar
	}
	
	if(target != NULL()){
		damageentity(target, self, 0, 1, openborconstant("ATK_NORMAL7")); // Slam Starter
	}
}

void position(int Frame, float dx, float dy, float dz, int face)
{//Modify grabbed entity's position relative to grabber
//Use slamstart 1st before using this
	void self 	= getlocalvar("self");
	void target = getlocalvar("Target"+self);
	int THealth = getentityproperty(target,"health"); //Get opponents's health

	if(target == NULL()){
		target = getentityproperty(self, "grabbing");
		setlocalvar("Target"+self, target);
	}
	
	if(target != NULL()){
		if(THealth <= 0){
			depost(0);
			finish(0,0,-1,0,0,0);
			slammed(0);
		}else{
			updateframe(target, Frame);
			bindentity(target, self, dx, dz, dy, face, 0);
		}
	}
}

void unbind()
{//Release binded entity by slamstart script if falling by time over
	void self = getlocalvar("self");
	void target = getentityvar(self, "binded"); //Get grabbed entity saved in a entityvar
	
	if(target != NULL()){
		bindentity(target, NULL());
		damageentity(target, self, 0, 1, openborconstant("ATK_NORMAL"));
		setentityvar(self, "binded", NULL()); //Release grabbed entity saved in a entityvar if TIME OVER kill the player before finish throw or slam animation, used in "onfall" script
		clearlocalvar();
	}
}

In this case, the "slamstart" script is used in the first frame of throw/slam animations with "@cmd". And the "unbind" script will be in "onfall" event for all players. You can use "killentity" command after unbind instead of command "damageentity" that I'm using.
 
Paulo HP Bender : You should update your spawnbind function into this:
Code:
void spawnbind(void ChildName, void ChildAnim, float OffsetX, float OffsetY, float OffsetZ, int Direction, int BindFlag, void Store)
{
	void self = getlocalvar("self");										//Spawnin parent entity.
	void Child;																//Spawned child entity.

	clearspawnentry();														//Clear current spawn entity.
	setspawnentry("name", ChildName);											//Set spawn entity by it's name.
  	
  	Child = spawn();														//Spawn child entity.
	
	changeentityproperty(Child, "parent", self);							//Set child's parent.
	performattack(Child, openborconstant(ChildAnim));

	
return Child;

	bindentity(Child, self, OffsetX, OffsetY, OffsetZ, Direction, BindFlag);
        setentityvar(self, Store, Child);
}

Similar to Kratus' suggestion, this will spawn and bind an entity and also store it in entity variable defined at last parameter.
Ex: @cmd spawnbind "FX1" "ANIM_FOLLOW1" 10 20 1 1 0 1

Then to remove that FX1 entity, use this new function:
Code:
void releaseChild(void Num)
{
    void self = getlocalvar("self");
    void Child = getentityvar(self, Num);

    if(Child){
      bindentity(Child, NULL());
      killentity(Child);
    }
}

Unlike unbind function, this function is declared in binder's text
Ex: @cmd releaseChild 1
This will remove binded entity

HTH
 
Hi sorry to dig up this topic: I tried lately to bind an entity during a runattack animation like this:
Code:
load runtaurus

anim runattack
    delay    7
    offset    37 164
    bbox 21 13 38 151
    forcedirection -1
    @cmd    dasher 3.5 0 0 1
    @cmd     spawnbind "runtaurus" "ANI_RUNATTACK" 0 0 0 1 0       
    frame    data/chars/aldebaran/runattack1.png
    frame    data/chars/aldebaran/runattack2.png
    frame    data/chars/aldebaran/runattack3.png
    attack2 60 40 55 83 20 1 0 0 5 12
    frame    data/chars/aldebaran/runattack4.png
    frame    data/chars/aldebaran/runattack5.png
    frame    data/chars/aldebaran/runattack6.png
    frame    data/chars/aldebaran/runattack7.png
    attack2 0 0 0 0 0 0 0 0 0 0
    @cmd    stop
    delay    12
    frame    data/chars/aldebaran/runattack8.png
    frame    data/chars/aldebaran/runattack9.png
    frame    data/chars/aldebaran/runattack10.png
I've got no runtaurus entity during this anim. Maybye, I've done something wrong or misused this script?
 
I've tried that function myself. Although it has error in it (swapped OffsetY and OffsetZ), it can spawn entity properly.

I can only make some guesses here, so I'll start with some questions:
1. Does runtaurus has RUNATTACK animatin?
2. Is there other spawnbind function somewhere in your module?
 
Thanks for sharing :)

I've tried spawnbinding runtaurus on test mod and it works. So I begin to think of another possible cause:
Code:
name    runtaurus
type    none
shadow    0
setlayer 1
#antigravity 100

Why do you need to set setlayer 1? if there were decoration or other entity with higher setlayer, this runtaurus would be covered by the former and would appear as if it's not there at all.
I believe setting OffsetZ parameter to -1 should be enough to put this effect behind Aldebaran and setlayer isn't needed.
 
Solved thanks to @Kratus by rewriting the spawnbind script like this:
- Fixed the spawnbind script by moving the "bindentity" function to before "return Child" line.

Code:
void spawnbind(void ChildName, void ChildAnim, float OffsetX, float OffsetY, float OffsetZ, int Direction, int BindFlag)

{
    void self = getlocalvar("self");                                        //Spawnin parent entity.
    void Child;                                                                //Spawned child entity.
    clearspawnentry();                                                        //Clear current spawn entity.
    setspawnentry("name", ChildName);                                            //Set spawn entity by it's name.

      Child = spawn();                                                        //Spawn child entity.

  changeentityproperty(Child, "parent", self);                            //Set child's parent.
  performattack(Child, openborconstant(ChildAnim));
  bindentity(Child, self, OffsetX, OffsetY, OffsetZ, Direction, BindFlag);

  return Child;
}


void unbind()
{
    void self = getlocalvar("self");
    bindentity(self, NULL());
}

I set the runtaurus like this and here is how it appears ingame:
Code:
name    runtaurus
type    none
shadow    0
setlayer 1
lifespan 1

anim    idle
    loop    1
    delay    60
    offset    80 155
    frame    data/chars/aldebaran/special/runtaurus.png
    frame    data/chars/aldebaran/special/runtaurus.png
bfRhUbj.png

Maybye I don't need to setlayer 1 too :)
Edit: setlayer 1 removed, thanks @Bloodbane ;).
 
Last edited:
Yeah, I forgot to tell you that I've rearranged the function before using it in test module.
And I also have fixed one detail in the function, the bindentity function should be like this:
C:
bindentity(Child, self, OffsetX, OffsetZ, OffsetY, Direction, BindFlag);

Nonetheless, if you're using this function to spawn bind entity and also changes its animation to match spawner's animation, I suggest not to bother changing animation manually and instead set BindFlag to 4.
I use this function to do similar purpose:
C:
void spawnBind(void Name, float dx, float dy, float dz, int Dir, int Flag)
{ // Spawn entity and bind it
   void self = getlocalvar("self");
   void Spawn;

   Spawn = spawn01(Name, dx, dy, dz);
   bindentity(Spawn, self, dx, dz, dy, Dir, Flag);
}

It's almost the same but with B instead of b.
Declared it like this:
@cmd spawnBind "runtaurus" 0 0 0 1 4

If runtaurus has same animation as Aldebaran's animation (in which he spawns the former), it will appear.
 
Back
Top Bottom