binding an entity by name, type 1 & type 2

oldyz

Well-known member
O Ilusionista
after running some experiments i found that the "terminate an entity" script disappears the entity & there is no item drop
but at least gave me some idea of a binding script that targets an entity by name
UPDATE:
        Type 1
the parasytic  entity will jump from the original possessor to another,
it might be useful for a game where a "spirit" jumps from one body to the next & with more modification it can even boost the health or other factors in the "possessed"

Code:
void bindobject00(char target_name, float dx, float dy, float dz, int Dir, int Flag)
{// bind any entity on the screen by the given name
//Douglas Baldan - 11.27.2016 - Really thanks for the fix, White Dragon
// Thanks Lagarto
//i pity the fool who don't use it like this: //@cmd bindobject00 "aliasofentity" 	1	2	5	1// 
//see bindentity in manual for the number meanings
   void self = getlocalvar("self");
	int i;
	for (i = 0; i < openborvariant("count_entities"); ++i)
	{
    		void ent = getentity(i);
		if ( getentityproperty(ent, "exists") )
	   	{
       			if ( getentityproperty(ent,"model") == target_name)
			{
				//killentity(ent);
                                bindentity(ent, self, dx, dz, dy, Dir, Flag);
				continue;
			}
		} else continue;
	}
	return;	
}
}

Type 2 - the Object remains with the entity that called it

Code:
void bindobject01(char target_name, float dx, float dy, float dz, int Dir, int Flag)
{// bind any entity on the screen by the given name
//Douglas Baldan - 11.27.2016 - Really thanks for the fix, White Dragon
// Thanks Lagarto
//i pity the fool who don't use it like this: //@cmd bindobject01 "aliasofentity" 	1	2	5	1//
//see bindentity in manual for the number meanings
   void self = getlocalvar("self");
	int i;
	for (i = 0; i < openborvariant("count_entities"); ++i)
	{
    		void ent = getentity(i);
		if ( getentityproperty(ent, "exists") )
	   	{
       			if ( getentityproperty(ent,"name") == target_name)
			{
 changeentityproperty(ent, "name", "melunchbox");// ----changes the alias so no other clone char can grab it 
				//killentity(ent);
                                bindentity(ent, self, dx, dz, dy, Dir, Flag);
				continue;
			}
		} else continue;
	}
	return;	
}
                 

                                                how to use both scripts:
first

save those codes as bindobject00.c & bindobject01.c and put them i the scripts folder.

2nd 
make sure to import them on whatever animationscript data/scripts/nameofchar.c
your entity has  -
you open the nameofchar.c file & paste their paths this way:
#import "data/scripts/bindobject00.c"

3rd

you must give an alias for the entity in question for it to be called in the level.txt file:
Code:
spawn lunchbox
alias lvl8lunchbox
item broodwich
coords	35 200
at	0

4th

characters entities can get a hold of it after an animation frame like this:
Code:
anim spawn
	@script
	if(frame == 0){
	void self = getlocalvar("self");
	int map = rand()%2;
	if(map < 0)
	{
	-map == map;
	}
	changeentityproperty(self, "map", map);
	}
	@end_script
	delay	100               ########################

	offset  73 133             ######################
	bbox    0 0 0 0
	frame	data/chars/mutant2/01
@cmd bindobject01 "lvl8lunchbox" 	1	2	5	1	
frame	data/chars/mutant2/02

a bind tool: https://www.mediafire.com/file/9bfh7wqlzvk30il/spawnbind_tool.ods/file
 
after running some experiments i found that the "terminate an entity" script disappears the entity & there is no item drop
For sure - the script TERMINATE (kill) the entity, hence the name.

Remember when we said that using scripts gives you full control of things in OpenBOR? That is the point: YOU have the full control and the engine will do only what you tell it to do - scripts only do what you make it to do.
On the case above, the script tells the engine to kill an entity, nothing more - and its what the engine will do.

Keep that in mind.

There is a difference between an entity "dying" and an entity "being killed" by script. When an entity "dies", a series of internal routines take place (such as animating death, counting points, releasing items, etc.).

An entity can "die" in several ways: by TIMEOVER (which uses the ATK_TIMEOVER attack type), by falling into holes (which uses the ATK_PIT attack type), by LIFESPAN (which uses the ATK_LIFESPAM attack type), when its life reaches zero, etc.

But when an entidar "was killed" by script, it is simply REMOVED. That simple.


 
if another entity spawns & has the same code - the object jumps/warps from the possesor to the the new entity, what can be added to the code to solve this? - is there a script that could rename the object/entity after it is Binded?
oldyz my function above is using the entityproperty "model", which is the name you give to an entity when setting it on models.txt file. So it doesn't care if the entity has an alias - let's say the entity was called "joe"  and now you gave the alias "soldier" to it... "joe" will be killed, no matter its alias.

And the code run a loop though all active entities to check their name - it won't stop on the first case, but will keep search for matching names until the last entity was checked. So if you have 2 "joe" entities on the screen, both will be killed.

What you can do is changing "model" for "name", so it will search using the alias.
 
Bloodbane, O Ilusionista.

The code works , but if there are many instances of the same character they teleport & "clump" -  how could i avoid this issue? -
basically i would like the "MutantMizer" entity to latch onto the Mutant-"#" it spawns, share its health with it & die with if it dies - & i would like for this to work with a mutlitude of them.

Do i have to make this binding/latching more like a grab? or can i control the range of the bind so the mutant can latch the mutantmizer only if its a pixel away?
 
I could think of some ways to solve this issue but my main question is always the same: what is the main goal of all of these?

Do you want to carry boss 1 status to sub entities? do you want to carry to be dropped item to sub entities? or do you just want to have the slowdown effect + kill all enemies?

Instead of solving seperate issues, I prefer to code the whole system and gained the goal  8)
 
Back
Top Bottom