[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / scripting/scriptEntityEvents

# scripting/scriptEntityEvents

## Type Aliases

### ScriptEntityEvent

> **ScriptEntityEvent** = `Extract`\<[`ScriptWorldEvent`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptworldevent), \{ `type`: `"entitySpawn"` \| `"entityHurt"` \| `"entityDie"`; \}\>

Defined in: [packages/prismarine/src/scripting/scriptEntityEvents.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptEntityEvents.ts#L21)

An entity event the scripts hear.

## Functions

### damageSourceOfScript()

> **damageSourceOfScript**(`source`, `actorOf`): [`DamageSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/DamageSource/classes/DamageSource.md)

Defined in: [packages/prismarine/src/scripting/scriptEntityEvents.ts:70](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptEntityEvents.ts#L70)

The damage source a script's `applyDamage` describes.

#### Parameters

##### source

[`ScriptDamageSource`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptdamagesource)

##### actorOf

(`id`) => [`StoreActor`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/data/storeActors/classes/StoreActor.md) \| `undefined`

Finds a live entity by the id the scripts know it by.

#### Returns

[`DamageSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/DamageSource/classes/DamageSource.md)

***

### levelEntityEvents()

> **levelEntityEvents**(`server`, `level`): (`listener`) => () => `void`

Defined in: [packages/prismarine/src/scripting/scriptEntityEvents.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptEntityEvents.ts#L88)

Hears the entity events of one level's worlds. The server raises no `entitySpawn` for a player,
whose arrival the player events tell.

#### Parameters

##### server

[`Server`](https://jsprismarine.dev/api/@jsprismarine/prismarine/Server/classes/Server.md)

##### level

[`Level`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/Level/classes/Level.md)

#### Returns

A function that stops it.

(`listener`) => () => `void`

***

### scriptDamageSource()

> **scriptDamageSource**(`source`): [`ScriptDamageSource`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptdamagesource)

Defined in: [packages/prismarine/src/scripting/scriptEntityEvents.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptEntityEvents.ts#L60)

A damage source as `EntityDamageSource` reads it.

#### Parameters

##### source

[`DamageSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/DamageSource/classes/DamageSource.md)

#### Returns

[`ScriptDamageSource`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptdamagesource)

***

### scriptEntityRef()

> **scriptEntityRef**(`actor`): [`ScriptEntityRef`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptentityref)

Defined in: [packages/prismarine/src/scripting/scriptEntityEvents.ts:54](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptEntityEvents.ts#L54)

An entity as the scripts name it: its runtime id and its type.

#### Parameters

##### actor

[`StoreActor`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/data/storeActors/classes/StoreActor.md)

#### Returns

[`ScriptEntityRef`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptentityref)
