O Ilusionista
Captain 100K
Hello my friends.
I have a function that I use to check if a specific entity exists and, if it does, it makes the caller change to a new animation and it works perfectly:
The problem is that I want to do the opposite - I want to check if an entity DOES NOT EXIST and, if it does not exist, the animation changes. If it does exist, nothing should happen.
I tried to adapt the code like this (terrible name, I know), but it doesn't work - even though the entity is no longer active, sometimes it works, sometimes it doesn't:
What I am doing wrong?
I have a function that I use to check if a specific entity exists and, if it does, it makes the caller change to a new animation and it works perfectly:
C-like:
void checkEntChangeAnim(char target_name, int Ani)
{// Check if there is a specific entity and make the called to change to a specific animation
//Douglas Baldan / O Ilusionista - 2023.11.25
void self = getlocalvar("self"); // Get Caller
int i;
for (i = 0; i < openborvariant("count_entities"); ++i) // Count available entities and execute an entity enumeration loop
{
void ent = getentity(i);
if ( getentityproperty(ent, "exists") && !getentityproperty(ent, "dead") && getentityproperty(ent, "aiflag", "autokill" ) == 0)// Entity exist and its not dead?
{
if (getentityproperty(ent,"model") == target_name) // Check if the entity model (and not the alias) matches the one you want
{
changeentityproperty(self, "animation", openborconstant(Ani)); // Make the caller to change its animation
continue;
}
} else continue;
}
return;
}
The problem is that I want to do the opposite - I want to check if an entity DOES NOT EXIST and, if it does not exist, the animation changes. If it does exist, nothing should happen.
I tried to adapt the code like this (terrible name, I know), but it doesn't work - even though the entity is no longer active, sometimes it works, sometimes it doesn't:
C-like:
void checkEntChangeAnimNot(char target_name, int Ani)
{// Check if there isn't a specific entity and make the called to change to a specific animation
//Douglas Baldan / O Ilusionista - 2025.01.25
void self = getlocalvar("self"); // Get Caller
int i;
for (i = 0; i < openborvariant("count_entities"); ++i) // Count available entities and execute an entity enumeration loop
{
void ent = getentity(i);
if ( getentityproperty(ent, "exists") && !getentityproperty(ent, "dead") && getentityproperty(ent, "aiflag", "autokill" ) == 0)// Entity exist and its not dead?
{
if (getentityproperty(ent,"model") == target_name) // Check if the entity model (and not the alias) matches the one you want
{
break;
}
} else {
changeentityproperty(self, "animation", openborconstant(Ani)); // Make the caller to change its animation
}
}
return;
}
What I am doing wrong?