Skip to content

Room functions

define_room_template

source

function define_room_template(room_template: string, type: ROOM_TEMPLATE_TYPE): integer
room_template: string
type: ROOM_TEMPLATE_TYPE

Returns integer

Define a new room template to use with set_room_template

get_room_index

source

function get_room_index(x: number, y: number): integer, integer
x: number
y: number

Returns integer, integer

Transform a position to a room index to be used in get_room_template and PostRoomGenerationContext.set_room_template

get_room_pos

source

function get_room_pos(x: integer, y: integer): number, number
x: integer
y: integer

Returns number, number

Transform a room index into the top left corner position in the room

get_room_template

source

function get_room_template(x: integer, y: integer, layer: LAYER): integer?
x: integer
y: integer
layer: LAYER

Returns integer? (may be nil)

Get the room template given a certain index, returns nil if coordinates are out of bounds

get_room_template_name

source

function get_room_template_name(room_template: integer): string
room_template: integer

Returns string

For debugging only, get the name of a room template, returns 'invalid' if room template is not defined

is_machine_room_origin

source

function is_machine_room_origin(x: integer, y: integer): boolean
x: integer
y: integer

Returns boolean

Get whether a room is the origin of a machine room

is_room_flipped

source

function is_room_flipped(x: integer, y: integer): boolean
x: integer
y: integer

Returns boolean

Get whether a room is flipped at the given index, returns false if coordinates are out of bounds

set_room_template_size

source

function set_room_template_size(room_template: integer, width: integer, height: integer): boolean
room_template: integer
width: integer
height: integer

Returns boolean

Set the size of room template in tiles, the template must be of type ROOM_TEMPLATE_TYPE.MACHINE_ROOM.

spawn_roomowner

documented onlysource

-- spawns waddler selling pets
-- all the aggro etc mechanics from a normal shop still apply
local x, y, l = get_position(get_player(1).uid)
local owner = spawn_roomowner(ENT_TYPE.MONS_STORAGEGUY, x+1, y, l, ROOM_TEMPLATE.SHOP)
add_item_to_shop(spawn_on_floor(ENT_TYPE.MONS_PET_DOG, x-1, y, l), owner)
add_item_to_shop(spawn_on_floor(ENT_TYPE.MONS_PET_CAT, x-2, y, l), owner)
add_item_to_shop(spawn_on_floor(ENT_TYPE.MONS_PET_HAMSTER, x-3, y, l), owner)
-- use in a tile code to add shops to custom levels
-- this may spawn some shop related decorations too
define_tile_code("pet_shop_boys")
set_pre_tile_code_callback(function(x, y, layer)
local owner = spawn_roomowner(ENT_TYPE.MONS_YANG, x, y, layer, ROOM_TEMPLATE.SHOP)
-- another dude for the meme, this has nothing to do with the shop
spawn_on_floor(ENT_TYPE.MONS_BODYGUARD, x+1, y, layer)
add_item_to_shop(spawn_on_floor(ENT_TYPE.MONS_PET_HAMSTER, x+2, y, layer), owner)
return true
end, "pet_shop_boys")
function spawn_roomowner(owner_type: ENT_TYPE, x: number, y: number, layer: LAYER, room_template?: ROOM_TEMPLATE): integer
owner_type: ENT_TYPE
x: number
y: number
layer: LAYER
room_template?: ROOM_TEMPLATEoptional

Returns integer

Spawn a RoomOwner (or a few other like CavemanShopkeeper) in the coordinates and make them own the room, optionally changing the room template. Returns the RoomOwner uid.