Skip to content

Class: alife_simulator

Access point for ALife simulation objects and registries.

Source

C++ class alife_simulator

Custom Constructor

alife_simulator

Remarks

This is the active single-player ALife simulator. Most methods expect ids that are already registered in ALife.

Constructors

Constructor

ts
new alife_simulator(): alife_simulator;

Returns

alife_simulator

Methods

actor()

ts
actor<T>(): T;

Get the ALife actor server object.

Type Parameters

Type Parameter
T extends cse_alife_creature_actor

Returns

T

Actor object registered in the ALife graph.

Throws

If no active ALife simulator exists.


add_in_restriction()

ts
add_in_restriction(monster: cse_alife_monster_abstract, restrictorId: number): void;

Add an inside-space restriction to an offline monster.

Parameters

ParameterTypeDescription
monstercse_alife_monster_abstractMonster server object to restrict.
restrictorIdnumberRestrictor object id.

Returns

void

Remarks

monster must be a registered monster server object. restrictorId should point to a space restrictor.


add_out_restriction()

ts
add_out_restriction(monster: cse_alife_monster_abstract, restrictorId: number): void;

Add an outside-space restriction to an offline monster.

Parameters

ParameterTypeDescription
monstercse_alife_monster_abstractMonster server object to restrict.
restrictorIdnumberRestrictor object id.

Returns

void

Remarks

monster must be a registered monster server object. restrictorId should point to a space restrictor.


clone_weapon()

Call Signature

ts
clone_weapon(
   object: cse_abstract, 
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
parent_id: number): Nullable<cse_abstract>;

Clone a registered magazined weapon server object.

Parameters
ParameterTypeDescription
objectcse_abstractSource server weapon object.
sectionstringSection to spawn for the clone.
positionvectorClone position.
level_vertex_idnumberClone level vertex id.
game_vertex_idnumberClone game graph vertex id.
parent_idnumberParent object id, or 65535 for no parent.
Returns

Nullable<cse_abstract>

Spawned clone object, or null.

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source

src/xrGame/alife_simulator_script.cpp, alife_simulator.clone_weapon binding.

Remarks

Returns null when the source object is not a magazined weapon or when the clone cannot be spawned as a magazined weapon. By default the clone is reprocessed through the spawn packet path and registered.

Call Signature

ts
clone_weapon(
   object: cse_abstract, 
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
   parent_id: number, 
should_register: boolean): Nullable<cse_abstract>;

Clone a registered magazined weapon server object with explicit registration control.

Parameters
ParameterTypeDescription
objectcse_abstractSource server weapon object.
sectionstringSection to spawn for the clone.
positionvectorClone position.
level_vertex_idnumberClone level vertex id.
game_vertex_idnumberClone game graph vertex id.
parent_idnumberParent object id, or 65535 for no parent.
should_registerbooleanWhether to reprocess and register the cloned object before returning it.
Returns

Nullable<cse_abstract>

Spawned clone object, or null.

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source

src/xrGame/alife_simulator_script.cpp, alife_simulator.clone_weapon binding.


create()

Call Signature

ts
create<T>(spawn_id: number): T;

Create an object from a spawn graph id.

Type Parameters
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters
ParameterTypeDescription
spawn_idnumberSpawn graph id.
Returns

T

Created server object.

Throws

If spawn_id does not exist or does not resolve to a dynamic ALife object.

Call Signature

ts
create<T>(
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
   parent_object_id?: number): T;

Spawn a server object by section.

Type Parameters
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters
ParameterTypeDescription
sectionstringObject section name.
positionvectorSpawn position.
level_vertex_idnumberLevel vertex id at the spawn position.
game_vertex_idnumberGame graph vertex id at the spawn position.
parent_object_id?numberOptional parent inventory or container id.
Returns

T

Created server object, or null when a non-empty parent id is invalid.

Remarks

If a non-empty parent id is invalid, the engine logs the error and returns null.

Call Signature

ts
create<T>(
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
   parent_object_id: number, 
   reg: boolean): T;

Spawn a server object and optionally defer network registration.

Type Parameters
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters
ParameterTypeDescription
sectionstringObject section name.
positionvectorSpawn position.
level_vertex_idnumberLevel vertex id at the spawn position.
game_vertex_idnumberGame graph vertex id at the spawn position.
parent_object_idnumberParent inventory or container id.
regbooleanWhether to register the object immediately.
Returns

T

Created server object, or null when a non-empty parent id is invalid.

Remarks

Passing reg = false returns the unregistered server object so scripts can edit its packet before registering it manually. If a non-empty parent id is invalid, the engine logs the error and returns null.


create_ammo()

ts
create_ammo(
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
   parent_object_id: number, 
   count: number): cse_abstract;

Spawn ammo with a custom amount left in the box.

Parameters

ParameterTypeDescription
sectionstringAmmo section name.
positionvectorSpawn position.
level_vertex_idnumberLevel vertex id at the spawn position.
game_vertex_idnumberGame graph vertex id at the spawn position.
parent_object_idnumberParent inventory or container id, or 65535 for no parent.
countnumberAmount of ammo in the spawned box.

Returns

cse_abstract

Spawned server object, or null when a non-empty parent id is invalid.

Remarks

The section must spawn a server ammo object, and count must not exceed the ammo box size.

Throws

If the spawned section is not ammo, or if count is larger than the box size.


dont_has_info()

ts
dont_has_info(object_id: number, info_id: string): boolean;

Check that an object does not know an info portion.

Parameters

ParameterTypeDescription
object_idnumberALife object id.
info_idstringInfo portion id.

Returns

boolean

Whether the object does not have the info portion.


get_children()

ts
get_children(object: cse_abstract): LuaIterable<number>;

Get child object ids for a server object.

Parameters

ParameterTypeDescription
objectcse_abstractServer object whose child id list should be exposed.

Returns

LuaIterable<number>

Iterable child object ids.

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source

src/xrGame/alife_simulator_script.cpp, alife_simulator.get_children binding.


has_info()

ts
has_info(object_id: number, info_id: string): boolean;

Check that an object knows an info portion.

Parameters

ParameterTypeDescription
object_idnumberALife object id.
info_idstringInfo portion id.

Returns

boolean

Whether the object has the info portion.


iterate_info()

ts
iterate_info(object_id: number, cb: (this: void, object_id: number, info_id: string) => void): void;

Iterate info portions known by an ALife object.

Parameters

ParameterTypeDescription
object_idnumberALife object id.
cb(this: void, object_id: number, info_id: string) => voidCallback called with the object id and each known info portion id.

Returns

void

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source

src/xrGame/alife_simulator_script.cpp, alife_simulator.iterate_info binding.

Remarks

Does nothing when the object has no info registry.


iterate_objects()

ts
iterate_objects(cb: (this: void, object: cse_alife_object) => boolean | void): void;

Iterate over registered ALife objects until the callback returns true.

Parameters

ParameterTypeDescription
cb(this: void, object: cse_alife_object) => boolean | voidCallback called for every server object.

Returns

void

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Remarks

Returning true from the callback stops iteration early.


kill_entity()

ts
kill_entity(
   monster: cse_alife_monster_abstract, 
   graph_id?: number, 
   schedulable?: cse_alife_monster_abstract): void;

Kill an offline monster.

Parameters

ParameterTypeDescription
monstercse_alife_monster_abstractMonster server object.
graph_id?numberOptional game graph vertex id used as death location.
schedulable?cse_alife_monster_abstractOptional killer or source object.

Returns

void

Remarks

Use only for monster server objects registered in ALife.

Throws

If monster is not a valid ALife monster object.


level_id()

ts
level_id(): number;

Get the current level id from the active ALife graph.

Returns

number

Current level id.


level_name()

ts
level_name<T>(level_id: number): T;

Method to get level name based on level ID. Easy way to get level is to get it by game vertex ID graph or iterate over all levels in graphs.

Type Parameters

Type ParameterDefault type
T extends stringstring

Parameters

ParameterTypeDescription
level_idnumberID of the level.

Returns

T

Level name based on level ID provided.

Throws

If level_id is not present in the game graph header.


object()

Call Signature

ts
object<T>(object_id: number, no_assert?: boolean): Nullable<T>;

Get a server object by id.

Type Parameters
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters
ParameterTypeDescription
object_idnumberALife object id.
no_assert?booleanReturn null instead of asserting when the object is missing.
Returns

Nullable<T>

Matching server object, or null.

Remarks

With the default id overload, an invalid id is logged and returns null. Pass no_assert to use the raw engine lookup mode.

Call Signature

ts
object<T>(name: string): Nullable<T>;

Get a server object by its engine replacement name.

Type Parameters
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters
ParameterTypeDescription
namestringServer object replacement name.
Returns

Nullable<T>

Matching server object, or null.


register()

ts
register(object: cse_abstract): cse_abstract;

Reprocess and register a server object through the spawn packet path.

Parameters

ParameterTypeDescription
objectcse_abstractServer object to reprocess.

Returns

cse_abstract

Registered replacement server object.

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source

src/xrGame/alife_simulator_script.cpp, alife_simulator.register binding.

Remarks

The native helper serializes the object, frees its current id, destroys the old instance, and processes a new spawn packet. The returned object is the registered replacement.


release()

ts
release(object: Nillable<cse_alife_object>, flag: boolean): void;

Release an ALife object from the simulator.

Parameters

ParameterTypeDescription
objectNillable<cse_alife_object>Object to remove.
flagbooleanCompatibility flag accepted by the engine binding.

Returns

void

Remarks

Online objects are destroyed through a network event. Offline objects are removed from ALife immediately.

Throws

If object is null or is not an ALife object.


remove_all_restrictions()

ts
remove_all_restrictions(objectId: number, type: TXR_dynamic_restrictor_type): void;

Remove all restrictions of one type from an object.

Parameters

ParameterTypeDescription
objectIdnumberRestricted object id.
typeTXR_dynamic_restrictor_typeRestriction type.

Returns

void

Remarks

objectId must resolve to an ALife object that has restriction storage.


remove_in_restriction()

ts
remove_in_restriction(monster: cse_alife_monster_abstract, restrictorId: number): void;

Remove an inside-space restriction from an offline monster.

Parameters

ParameterTypeDescription
monstercse_alife_monster_abstractMonster server object to update.
restrictorIdnumberRestrictor object id.

Returns

void

Remarks

monster must be a registered monster server object.


remove_out_restriction()

ts
remove_out_restriction(monster: cse_alife_monster_abstract, restrictorId: number): void;

Remove an outside-space restriction from an offline monster.

Parameters

ParameterTypeDescription
monstercse_alife_monster_abstractMonster server object to update.
restrictorIdnumberRestrictor object id.

Returns

void

Remarks

monster must be a registered monster server object.


set_interactive()

ts
set_interactive(objectId: number, enabled: boolean): void;

Enable or disable interaction for an ALife object.

Parameters

ParameterTypeDescription
objectIdnumberALife object id.
enabledbooleanNew interaction state.

Returns

void

Remarks

objectId must resolve to a registered ALife object.


set_objects_per_update()

ts
set_objects_per_update(count: number): void;

Set count of object updated in alife per one tick.

Parameters

ParameterTypeDescription
countnumberCount of objects to update per tick.

Returns

void

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033


set_process_time()

ts
set_process_time(microseconds: number): void;

Set ALife processing time budget in microseconds.

Parameters

ParameterTypeDescription
microsecondsnumberProcessing time budget.

Returns

void

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source

src/xrGame/alife_simulator_script.cpp, alife_simulator.set_process_time binding.


set_switch_distance()

ts
set_switch_distance(distance: number): void;

Set the online/offline switch distance.

Parameters

ParameterTypeDescription
distancenumberSwitch distance in meters.

Returns

void

Since

OpenXRay 2022-06-29, 09598fe7, PR #1033


set_switch_offline()

ts
set_switch_offline(objectId: number, enabled: boolean): void;

Allow or forbid switching an ALife object offline.

Parameters

ParameterTypeDescription
objectIdnumberALife object id.
enabledbooleanNew offline switching state.

Returns

void

Remarks

objectId must resolve to a registered ALife object.


set_switch_online()

ts
set_switch_online(objectId: number, enabled: boolean): void;

Allow or forbid switching an ALife object online.

Parameters

ParameterTypeDescription
objectIdnumberALife object id.
enabledbooleanNew online switching state.

Returns

void

Remarks

objectId must resolve to a registered ALife object.


spawn_id()

ts
spawn_id(spawnStoryId: number): number;

Resolve a spawn story id to a spawn graph id.

Parameters

ParameterTypeDescription
spawnStoryIdnumberSpawn story id.

Returns

number

Spawn graph id.


story_object()

ts
story_object(storyId: number): Nullable<cse_alife_object>;

Get a server object by story id.

Parameters

ParameterTypeDescription
storyIdnumberStory id.

Returns

Nullable<cse_alife_object>

Matching server object, or null when it is not registered.


switch_distance()

Call Signature

ts
switch_distance(): number;
Returns

number

Alife server-client switch distance.

Call Signature

ts
switch_distance(distance: number): void;

Set alife server-client switch distance.

Parameters
ParameterTypeDescription
distancenumberDistance to set.
Returns

void


teleport_object()

ts
teleport_object(
   object_id: number, 
   game_vertex_id: number, 
   level_vertex_id: number, 
   position: vector): void;

Move a server object to another graph and level vertex.

Parameters

ParameterTypeDescription
object_idnumberObject id to teleport.
game_vertex_idnumberDestination game graph vertex id.
level_vertex_idnumberDestination level vertex id.
positionvectorDestination position.

Returns

void

Since

OpenXRay 2017-08-15, 565b39e5


valid_object_id()

ts
valid_object_id(object_id: number): boolean;

Check whether an object id is usable.

Parameters

ParameterTypeDescription
object_idnumberALife object id.

Returns

boolean

Whether the id is not the engine invalid id.

Remarks

This only checks the engine invalid id value. It does not prove that an object with this id is registered.