• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Custom types

Toranks

Active member
Short question Can I create custom types with the same behavior as the original, but are specifically detected with candamage/hostile? For example type npc / type npc2 / type npc3 etc.

Long question. Some objects on the map are actually NPCs, so they can be attacked by script-objects or enemies, but not by the player. These NPCs have the stealth property to prevent enemies from detecting them, however, sometimes they accidentally hit them, activating things they shouldn't activate. As it is a very used resource in the game, which has been like this since the beginning, it would be a huge task to change all this for performattack scripts (although I am tempted to do it).
Enemies should attack non-stealth NPCs, under other circumstances.
Any short way to do this?
 
Last edited:
Short question Can I create custom types with the same behavior as the original, but are specifically detected with candamage/hostile? For example type npc / type npc2 / type npc3 etc.
@Bloodbane has some coding that can do "factions" - basically you have entities that can be set to be "cowboys" "indians" and if they encounter each other they will attack each other...

new engine will have this stuff for up to 8 by default or something like that.

dont know if the scripted version can be tweaked to include other specific behaviors..
 
The new engine has a built in faction system specifically for these sorts of cases. It's coming before years end, so if you can hold out just a bit longer, that might be the solution you are looking for. Here's a little sneak preview of how it works:


Factions control how entities interact with each other. Use faction settings to decide when an entity is hostile toward other entities, and what groups or types of entities it can damage.

Faction properties are divided into group and type. Group factions allow you to set what faction groups an entity belongs to, and then what groups that entity will attack and damage. Type factions are the legacy type based method. They target an entity using its type (Player, NPC, Enemy, etc.). You can combine both for extremely nuanced faction behavior.

Group​

Member​

Wiki:
faction_member <factions>

Default: faction_member a

Factions entity is a member of. Accepts one more of the following:
  • a … z – Entity is a member of this faction.
  • all – Entity is a member of all a through z factions.
  • neutral – Entity is a member of the neutral faction. Neutral has no special effect and is ignored by hostile/damage faction properties.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.
  • player_verses – No effect.
  • type_inclusive – No effect.
  • type_exclusive – No effect.

Damage Direct​

Wiki:
faction_damage_direct <factions>

Default: faction_damage_direct a type_inclusive

Factions entity can damage with normal attacks. Accepts one or more of the following.
  • a … z – Entity can damage members of these factions.
  • all – Entity can damage members of all a through z factions.
  • neutral – No effect.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.
  • player_verses – Ignore level and menu settings for damaging other players.
  • type_inclusive – Include Type Damage Direct (see below). Both the faction and type checks must pass to damage another entity.
  • type_exclusive – Only use type_damage_direct.

Damage Indirect​

Wiki:
faction_damage_indirect <factions>

Default: faction_damage_direct a type_inclusive

Factions entity can damage when thrown or blasted. For example, when a player throws an enemy into a group of other enemies, this property controls what entities the thrown enemy will hit. Accepts one or more of the following.
  • a … z – Entity can damage members of these factions.
  • all – Entity can damage members of all a through z factions.
  • neutral – No effect.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.
  • player_verses – Ignore level and menu settings for damaging other players.
  • type_inclusive – Include Type Damage Indirect (see below). Both the faction and type checks must pass to damage another entity.
  • type_exclusive – Only use type_damage_indirect.

Hostile​


Wiki:
faction_hostile <factions>

Default: faction_hostile a type_inclusive

Factions entity is hostile toward. Accepts one or more of the following.
  • a … z – Entity is hostile toward members of these factions.
  • all – Entity is hostile toward members of all a through z factions.
  • neutral – No effect.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.
  • player_verses – Ignore level and menu settings for hostility other players.
  • type_inclusive – Include Type Hostile (see below). Both the faction and type checks must pass to be hostile toward another entity.
  • type_exclusive – Only use type_hostile.

Type​

Prior to 4.0, OpenBOR relied solely on entity type for factions. Type properties target other entity’s types. To enable Type checking, you need to assign one of the Type factions to the appropriate faction group properties (see above).

Faction type properties have different defaults depending on the the model’s own type. For example, Enemy types are hostile to and able to hit players, and when thrown cause indirect damage to other enemies.

Wiki:
end_level, enemy, item, none, npc, obstacle, panel, player, projectile, shot, steamer, text_box, trap

Type Damage Direct​

Wiki:
faction_type_damage_direct <types>

Default: Varies, see Type overview.

Entity types this entity can damage with normal attacks. Accepts one or more of the following. Default value depends on model’s type, and is usually appropriate for that type’s needs (example: Player types can damage enemies and obstacles).
  • Any valid types. Entity can damage these types.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.

Type Damage Indirect​

Wiki:
faction_type_damage_indirect <types>

Default: Varies, see Type overview.

Entity types this entity can damage when thrown or blasted. For example, when a player throws an enemy into a group of other enemies, this property controls what entities the thrown enemy will hit. Accepts one or more of the following. Default value depends on model’s type, and is usually appropriate for that type’s needs (example: Enemy types damage other enemies).
  • Any valid types. Entity can damage these types.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.

Type Hostile​

Wiki:
faction_type_hostile <types>

Default: Varies, see Type overview.

Entity types this entity is hostile toward. Default value depends on model’s type, and is usually appropriate for that type’s needs (example: Enemy types are hostile toward Players).
  • Any valid types. Entity is hostile toward these types.
  • no_copy – Normally faction properties copy to sub entities and alternate models (ex. projectiles, weapons). If the parent or target model property has no_copy, that property is not copied.

Set Up​

Model Text​

Use any of the following model text commands to set up starting factions.

This model is a member of faction A and faction B. It is hostile to factions C, D, and E. Note it is also configured to damage its own factions if thrown or blasted into them.

Wiki:
faction_group_damage_direct C D E
faction_group_damage_indirect A B
faction_group_hostile C D E
faction_group_member A B

This model is mostly identical to previous sample, but adds type_inclusive and faction type properties. It is now only hostile toward and able to hit factions C, D, and E if they are enemy or NPC types.

Wiki:
faction_group_damage_direct C D E type_inclusive
faction_group_damage_indirect A B type_inclusive
faction_group_hostile C D E type_inclusive
faction_group_member A B

faction_type_damage_direct enemy npc
faction_type_damage_indirect player
faction-type_hostile enemy npc

Spawn​

You may use faction commands in level spawn entries to override an entity’s faction settings on spawn. The command syntax is identical to model text. The following spawn starts out ready to fight faction groups G and H.

Wiki:
spawn    Shermie
coords    350 160
faction_group_damage_direct G H
faction_group_damage_indirect E
faction_group_hostile G H
faction_group_member E
at        10

Script​

Factions are accessible to script through the get_faction_property() and set_faction_property() functions.

Get a faction property. The faction property functions accept a faction pointer and a property constant.

C:
mixed x = get_faction_property(void <faction handle>, int <identifier>);

Modify a faction property value. See the property list for details.

C:
mixed x = <value>;

set_faction_property(void <faction handle>, int <identifier>, x);

ConstantTypeDescription
FACTION_PROPERTY_GROUP_DAMAGE_DIRECTIntegerDamage direct property. Bitwise with following constants.
  • openborconstant("FACTION_GROUP_NONE")
  • openborconstant("FACTION_GROUP_NEUTRAL")
  • openborconstant("FACTION_GROUP_DEFAULT")
  • openborconstant("FACTION_GROUP_NO_COPY")
  • openborconstant("FACTION_GROUP_TYPE_INCLUSIVE")
  • openborconstant("FACTION_GROUP_TYPE_EXCLUSIVE")
  • openborconstant("FACTION_GROUP_PLAYER_VERSES")
  • openborconstant("FACTION_GROUP_ALL_NORMAL")
  • openborconstant("FACTION_GROUP_A") … openborconstant("FACTION_GROUP_Z")
FACTION_PROPERTY_GROUP_DAMAGE_INDIRECTIntegerDamage indirect property. Same constants as Damage Direct.
FACTION_PROPERTY_GROUP_HOSTILEIntegerHostile property. Same constants as Damage Direct.
FACTION_PROPERTY_GROUP_MEMBERIntegerMember property. Same constants as Damage Direct.
FACTION_PROPERTY_TYPE_DAMAGE_DIRECTIntegerType damage direct property. Accepts any type constant.
FACTION_PROPERTY_TYPE_DAMAGE_INDIRECTIntegerType damage indirect property. Accepts any type constant.
FACTION_PROPERTY_TYPE_HOSTILEIntegerType hostile property. Accepts any type constant.


HTH,
DC
 
Short question Can I create custom types with the same behavior as the original, but are specifically detected with candamage/hostile? For example type npc / type npc2 / type npc3 etc.

Long question. Some objects on the map are actually NPCs, so they can be attacked by script-objects or enemies, but not by the player. These NPCs have the stealth property to prevent enemies from detecting them, however, sometimes they accidentally hit them, activating things they shouldn't activate. As it is a very used resource in the game, which has been like this since the beginning, it would be a huge task to change all this for performattack scripts (although I am tempted to do it).
Enemies should attack non-stealth NPCs, under other circumstances.
Any short way to do this?
You can create more entity types by changing "type" property after the spawn, you can use the onspawn script event for that (or any other).
But you must configure the type in the header with the one you want to inherit all the default behaviours, and then it will be maintained as soon as the type is changed.
I'm using this trick in the SORX to convert NPC to LEVEL_ENTITIES, this way enemies can't activate some specific events allowed only for players/partners in defined situations, once NPCs in my game are used by the CPU partners.

Thanks to @Bloodbane for the tip.

C:
//USED BY ENTITIES THAT NEEDS TO BE DETECTED BY OTHER CHARACTERS
setglobalvar("LEVEL_ENTITY", 262144);
changeentityproperty(self, "type", getglobalvar("LEVEL_ENTITY"));

//TURN ON HOSTILE AND GO TO FIGHT!!
changeentityproperty(self, "hostile", getglobalvar("LEVEL_ENTITY"), getglobalvar("LEVEL_ENTITY2"), etc...);
 
Whoooo thanks! Just tested and works.
The best way to show this is on video and the very basic code that I have used.

The "false" npc (the truck)

C#:
name        Mtruck3
type        npc
[...]
anim    spawn
@script
    void self = getlocalvar("self");
    if(frame==1){
    changeentityproperty(self, "type", 262144);
    }
@end_script   
loop 0
[...]


The entity that must attack the truck (the guy that falls from the sky)

C#:
name     mrkshw1
type     obstacle
hostile        none
candamage    none
[...]
anim    spawn
@script
    void self = getlocalvar("self");
    if(frame==1){
    changeentityproperty(self, "hostile", 262144);
    changeentityproperty(self, "candamage", 262144);
    }
@end_script   
    loop    0
[...]

The guy with the glasses is a normal enemy that can attack players and npc. During the fight I didn't see him touch the big blue area of the truck's impact box, but I'm assuming it worked.

 
I have a couple of questions.

What does the number mean? Can it be any number? It doesn't let me use names like "interactive" for example (with or without quotes).

Can I put that number directly in candamage and hostile (candamage player npc 235354), or should I always modify it via script?
 
I have a couple of questions.

What does the number mean? Can it be any number? It doesn't let me use names like "interactive" for example (with or without quotes).

Can I put that number directly in candamage and hostile (candamage player npc 235354), or should I always modify it via script?

Internally, type is a bitwise integer, so those numbers can and do have meaning. Be careful. The candamage and other type based text commands convert string input to numbers by matching your text to an existing list, and then looking up the appropriate number constant - so no, you can't just put whatever into them.

DC
 
I have a couple of questions.

What does the number mean? Can it be any number? It doesn't let me use names like "interactive" for example (with or without quotes).

Can I put that number directly in candamage and hostile (candamage player npc 235354), or should I always modify it via script?
@Toranks DC explained it perfectly, so you can't use any number. According to my tests you will need to use numbers starting from 16384 (and doubling it gradually) to avoid conflicts with the ones used natively by the engine.

Below an example used in the SORX.
C:
//CUSTOM TYPES USED BY SOME SCRIPTS
setglobalvar("PLAYER_SHOT", 16384);
setglobalvar("NPC_SHOT", 32768);
setglobalvar("ENEMY_SHOT", 65536);
setglobalvar("HIDE_ENTITY", 131072);
setglobalvar("LEVEL_ENTITY", 262144);

or should I always modify it via script?
Yes, in my case all events related to candamage/hostile/projectilehit are managed with scripts for all entities, mainly centralized in the onspawnscript event, scripted grabs (applying projectilehit properties to released opponents) or directly in the spawn01/shoot/toss scripts (for projectiles).
To make the management easier you can save all types in a named globalvar or declare it as a constant using #define.
 
I would also be really careful with this method if you want to keep compatibility with future engines. If we ever add more types (not likely, but possible) each new type's constant doubles the previous value in keeping with bitwise logic, and likely break your script completely.

One last thing, remember you can't exceed 2,147,483,647.


DC
 
I would also be really careful with this method if you want to keep compatibility with future engines. If we ever add more types (not likely, but possible) each new type's constant doubles the previous value in keeping with bitwise logic, and likely break your script completely.

One last thing, remember you can't exceed 2,147,483,647.


DC
No problem buddy, I'm planning to change my scripts to the new faction feature in future engine updates :)
 
Thanks, I was reading the wiki about it earlier, it's a really great feature something I've wanted to be able to do.

Glad you like. Technically, you're already using factions, it's just set up by default to mimic the old behavior for backward compatibility. Everybody defaults to being a member of / hostile to / can damage Faction A, but the "also use type" switch for them is turned on, so it acts the same as 3.0 did until you change something.

DC
 
would there be a way with script to check an enemy if he is the last faction member alive on screen?

You'd have to do an enumeration. Meaning loop over all the entities (except the the one in question) and compare their factions. If you don't find anyone who is a member of his faction, then you know he's the last.


Factions and types are both bit logic variables (same principal as keys).

DC
 
Back
Top Bottom