Entity that acts like enemy but is not

Aerisetta

Active member
Hi

I would like to create an entity that continously tries to attack the player as if it is an enemy.

However, they are not actually an enemy and the game will not need them to defeated before moving on.

Any example of this?
 
You can use candamage in a non-enemy type to hit against players.

Example:
Code:
type npc
candamage player enemy obstacle

candamage {type1} {type2} ...

  • Optional.
  • Specifies what types this entity can hit (very similar to hostile, but determines what entity may hit, not what it will intentionally target).
  • Available types are enemy, player, npc, obstacle, shot and you can use as many as you need. If you don't want entity to hit anything, just set 'none' here.
  • Be aware if you use this setting, you must provide all types you wish this entity to be able to hit. That is to say, an enemy with ‘candamage npc obstacle’ will be able to hit npc and obstacle types, not players.
The entity in that example only attacks players, enemies and obstacles, not NPCs and those not included.

EDIT: You can use hostile too.

hostile {type1} {type2} ...

  • Optional.
  • Specifies what types an AI controlled entity will attack and what entities a projectile with the chase subtype will seek (this does not determine what the entity can hit, only what it will intentionally attack).
  • Accepted types are enemy, player, npc, obstacle, shot and you can use as many as you need. If you want entity to be hostile to nothing, just set 'none' here.
  • Be aware if you use this setting, you must provide all types you wish this entity to be hostile towards. That is to say, an enemy with ‘hostile npc obstacle’ will only attack npc and obstacle types, not players.
  • Also 'stealth' feature below affect if the entity will target certain other entities or not.

Example:
Code:
hostile enemy player obstacle
 
Last edited:
However, they are not actually an enemy and the game will not need them to defeated before moving on.

Any example of this?

I've made such example before :) about creating factions other than player and NPC but I couldn't remember in which thread I've posted it 😅.

The idea is to spawn the entity as enemy first, then give them onspawnscript which changes their type to other type. The script also adjusts hostile, candamage and projectilehit to suit that change. This is the onspawnscript used by second faction::
faction2.c
C:
void main()
{
    void vSelf = getlocalvar("self");
    changeentityproperty(vSelf, "type", 2048);
    changeentityproperty(vSelf, "hostile", openborconstant("TYPE_ENEMY") + openborconstant("TYPE_PLAYER") + openborconstant("TYPE_NPC") + 4096 );
    changeentityproperty(vSelf, "candamage", openborconstant("TYPE_ENEMY") + 4096 + openborconstant("TYPE_PLAYER") + openborconstant("TYPE_OBSTACLE") + openborconstant("TYPE_NPC") );
    changeentityproperty(vSelf, "projectilehit", openborconstant("TYPE_ENEMY") + 4096 + openborconstant("TYPE_PLAYER") + openborconstant("TYPE_OBSTACLE") + openborconstant("TYPE_NPC"));
}

For your purpose, you could use this simpler version:
faknemy.c
C:
void main()
{
    void vSelf = getlocalvar("self");
    changeentityproperty(vSelf, "type", 2048);
}

Declare this in enemy's header:
onspawnscript data/scripts/faknemy.c

This script changes enemy's type into a type which is not counted by group.

Important note though, since this type is not enemy, player can't hurt this type. You'd need special onspawnscript to allow hurting it.
 
Back
Top Bottom