Solved Destroying a specific entity by name (and ID?)

Question that is answered or resolved.

PS_VITA

Active member
Hi guys,

I already have a script that can destroy a target by name but when I use the script it pretty much deletes all of the entities with that same name. Which is not what I want.

For example: a chicken object that can spawn eggs, lays 3 eggs and they are all called "egg" and all I want is to be able to delete the 2nd egg.

What are some ways to do this in openbor? Even though the chicken lays 3 eggs is there an id to these eggs or some sorta way to identify them?
 
Solution
I use two functions for that on my animationscript- one will kill all enemies with the same model name (not what you want) and one that will kill only the enemies witht he same alias

Use the second one - terminateAlias. You will need to give a proper alias to the entity you want to kill and them call the function:
@cmd terminateAlias "egg"

C:
void terminate(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 11.27.2016 - Really thanks for the fix, White Dragon
// Thanks Lagarto
    int i;
    for (i = 0; i < openborvariant("count_entities"); ++i)
    {
            void ent = getentity(i);
        if ( getentityproperty(ent, "exists") )
           {
                   if (...
@Bloodbane told me some tips a while ago on another thread about a similar situation

basically you need a script that gives aliases to the 3 eggs as they spawn, & then using the entitiy alias another script kills it or them
 
I use two functions for that on my animationscript- one will kill all enemies with the same model name (not what you want) and one that will kill only the enemies witht he same alias

Use the second one - terminateAlias. You will need to give a proper alias to the entity you want to kill and them call the function:
@cmd terminateAlias "egg"

C:
void terminate(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 11.27.2016 - Really thanks for the fix, White Dragon
// Thanks Lagarto
    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);
                continue;
            }
        } else continue;
    }
    return;   
}

void terminateAlias(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 2021.06.17 - Really thanks for the fix, White Dragon
// Thanks Lagarto
  int i;
  for (i = 0; i < openborvariant("count_entities"); ++i)
  {
        void ent = getentity(i);
    if ( getentityproperty(ent, "exists") )
      {
            if ( getentityproperty(ent,"name") == target_name)
      {
        killentity(ent);
        continue;
      }
    } else continue;
  }
  return;
}
 
Solution
I use two functions for that on my animationscript- one will kill all enemies with the same model name (not what you want) and one that will kill only the enemies witht he same alias

Use the second one - terminateAlias. You will need to give a proper alias to the entity you want to kill and them call the function:


C:
void terminate(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 11.27.2016 - Really thanks for the fix, White Dragon
// Thanks Lagarto
    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);
                continue;
            }
        } else continue;
    }
    return; 
}

void terminateAlias(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 2021.06.17 - Really thanks for the fix, White Dragon
// Thanks Lagarto
  int i;
  for (i = 0; i < openborvariant("count_entities"); ++i)
  {
        void ent = getentity(i);
    if ( getentityproperty(ent, "exists") )
      {
            if ( getentityproperty(ent,"name") == target_name)
      {
        killentity(ent);
        continue;
      }
    } else continue;
  }
  return;
}
Just to be clear,

Say I'm playing final fight and there are 3 exact same enemies called poison and run the script above [@cmd terminateAlias poison] all 3 posion enemies will die correct?
 
One script will search for the entntiy MODEL called Poison, the other will search for entity NAME (the alias you give on the stage) and kill it

For example, you have 3 copies of the "Poison" entity, but one of them has the alias "Poison_2". If you use the second script and pass the value "Poison_2", only that entity will die.
 
One script will search for the entntiy MODEL called Poison, the other will search for entity NAME (the alias you give on the stage) and kill it

For example, you have 3 copies of the "Poison" entity, but one of them has the alias "Poison_2". If you use the second script and pass the value "Poison_2", only that entity will die.
Ooooohh you can assign an alias!?
Oh wow, I'm just reading this on the manual. Thank you so much.

This is awesome!
 
I use two functions for that on my animationscript- one will kill all enemies with the same model name (not what you want) and one that will kill only the enemies witht he same alias

Use the second one - terminateAlias. You will need to give a proper alias to the entity you want to kill and them call the function:


C:
void terminate(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 11.27.2016 - Really thanks for the fix, White Dragon
// Thanks Lagarto
    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);
                continue;
            }
        } else continue;
    }
    return;  
}

void terminateAlias(char target_name)
{// kill any entity on the screen by the given name
//Douglas Baldan - 2021.06.17 - Really thanks for the fix, White Dragon
// Thanks Lagarto
  int i;
  for (i = 0; i < openborvariant("count_entities"); ++i)
  {
        void ent = getentity(i);
    if ( getentityproperty(ent, "exists") )
      {
            if ( getentityproperty(ent,"name") == target_name)
      {
        killentity(ent);
        continue;
      }
    } else continue;
  }
  return;
}
thanks brother,,,just what the doctor ordered haha... works amazing great work :)
 
Back
Top Bottom