Skip to content

Entity.lua

Functions


entity.new

entity.new(instance: LibLegelGen.Instance, type: string, x?: number, y?: number, level?: number | number[]): LibLevelGen.Entity

Create a new LibLevelGen entity. Do note that instead of using this, you should use methods provided by the LibLevelGen.Room and LibLevelGen.Tile classes, which will place the enemy in the level automatically.

Parameters:

Name Type Description
instance LibLegelGen.Instance Parent instance of the entity
type string Entity type
x? number X coordinate of the entity, relative to the room it's in. Defaults to -1
y? number Y coordinate of the entity, relative to the room it's in Defaults to -1
level? number | number[] Level of the entity, if a table is specified it's picked randomly from the provided values. Defaults to 1.

Returns: LibLevelGen.Entity

Classes


LibLevelGen.Entity

Represents a LibLevelGen entity object

Properties:

Name Type Description
instance LibLegelGen.Instance Instance this entity belongs to
type string Entity type
x number Entity X coordinate relative, relative to the room it's in
y number Entity Y coordinate relative, relative to the room it's in
level number Entity level
saleCurrency string | nil If entity has a price, this determines the currency
price table | nil Entity price data, in the format set by Synchrony's levelUtils.setEntityPriceTag
attributes table | nil Additional entity attributes. Use .setAttribute and .getOrCreateAttribute methods to manipulate this table.
inventory table | nil Entity's inventory. Use the .giveItem method to manipulate this table.

Methods:


LibLevelGen.Entity.setAttribute

setAttribute(self: LibLevelGen.Entity, component: string, field: string, value: any): LibLevelGen.Entity

Set value of the given component field for when the entity is spawned.

Parameters:

Name Type Description
self LibLevelGen.Entity The entity
component string Component name
field string Field in the given component
value any Value to write to the field

Returns: LibLevelGen.Entity


LibLevelGen.Entity.setPrice

setPrice(self: LibLevelGen.Entity, currency?: "coins" | "blood", amount?: number): LibLevelGen.Entity

Set price of the entity. If price is not specified, it is automatically obtained.

Parameters:

Name Type Description
self LibLevelGen.Entity The Entity
currency? "coins" | "blood" Currency type, defaults to "coins"
amount? number The price value. If not specified, it's calculated automatically.

Returns: LibLevelGen.Entity


LibLevelGen.Entity.setDiscount

setDiscount(self: LibLevelGen.Entity, discount: number): LibLevelGen.Entity

Set discount on the price.

Parameters:

Name Type Description
self LibLevelGen.Entity The entity
discount number The discount factor. 0.5 will result in the price being halved.

Returns: LibLevelGen.Entity


LibLevelGen.Entity.setQuantity

setQuantity(self: LibLevelGen.Entity, quantity: number): LibLevelGen.Entity

Set quantity (itemStack.quantity field)

Parameters:

Name Type Description
self LibLevelGen.Entity The entity
quantity number The quantity amount to set

Returns: LibLevelGen.Entity


LibLevelGen.Entity.giveItem

giveItem(self: LibLevelGen.Entity, item: string | LibLevelGen.Entity): LibLevelGen.Entity

Add an item to entity's inventory.

Parameters:

Name Type Description
self LibLevelGen.Entity The entity
item string | LibLevelGen.Entity Entity type or an existing entity to add to the inventory.

Returns: LibLevelGen.Entity


LibLevelGen.Entity.getOrCreateAttribute

getOrCreateAttribute(self: LibLevelGen.Entity, component: string, field: string): LibLevelGen.Entity

Get an attribute of the entity. If it doesn't exist, it gets created and added (with no value specified)

Parameters:

Name Type Description
self LibLevelGen.Entity The entity
component string Component name
field string Field name in the given component

Returns: LibLevelGen.Entity


LibLevelGen.Entity.storeItem

storeItem(self: LibLevelGen.Entity, item: string): LibLevelGen.Entity

Add an item to entity's storage.

Parameters:

Name Type Description
self LibLevelGen.Entity The entity
item string Item entity type

Returns: LibLevelGen.Entity