Spawn functions
default_spawn_is_valid
function default_spawn_is_valid(x: number, y: number, layer: LAYER): booleanx:numbery:numberlayer:LAYER
Returns boolean
Default function in spawn definitions to check whether a spawn is valid or not
define_extra_spawn
function define_extra_spawn(do_spawn: fun(p1: number, p2: number, p3: integer), is_valid: fun(p1: number, p2: number, p3: integer): boolean, num_spawns_frontlayer: integer, num_spawns_backlayer: integer): integerdo_spawn:fun(p1: number, p2: number, p3: integer)is_valid:fun(p1: number, p2: number, p3: integer): boolean- Returning nil (or nothing): treated as false.
num_spawns_frontlayer:integernum_spawns_backlayer:integer
Returns integer
Define a new extra spawn, these are semi-guaranteed level gen spawns with a fixed upper bound.
The function nil do_spawn(float x, float y, LAYER layer) contains your code to spawn the thing, whatever it is.
The function bool is_valid(float x, float y, LAYER layer) determines whether the spawn is legal in the given position and layer.
Use for example when you can spawn only on the ceiling, under water or inside a shop.
Set is_valid to nil in order to use the default rule (aka. on top of floor and not obstructed).
To change the number of spawns use PostRoomGenerationContext:set_num_extra_spawns during ON.POST_ROOM_GENERATION
No name is attached to the extra spawn since it is not modified from level files, instead every call to this function will return a new unique id.
define_procedural_spawn
function define_procedural_spawn(procedural_spawn: string, do_spawn: fun(p1: number, p2: number, p3: integer), is_valid: fun(p1: number, p2: number, p3: integer): boolean): PROCEDURAL_CHANCEprocedural_spawn:stringdo_spawn:fun(p1: number, p2: number, p3: integer)is_valid:fun(p1: number, p2: number, p3: integer): boolean- Returning nil (or nothing): treated as false.
Returns PROCEDURAL_CHANCE
Define a new procedural spawn, the function nil do_spawn(float x, float y, LAYER layer) contains your code to spawn the thing, whatever it is.
The function bool is_valid(float x, float y, LAYER layer) determines whether the spawn is legal in the given position and layer.
Use for example when you can spawn only on the ceiling, under water or inside a shop.
Set is_valid to nil in order to use the default rule (aka. on top of floor and not obstructed).
If a user disables your script but still uses your level mod nothing will be spawned in place of your procedural spawn.
door
function door(x: number, y: number, layer: LAYER, w: integer, l: integer, t: integer): integerx:numbery:numberlayer:LAYERw:integerl:integert:integer
Returns integer
Short for spawn_door.
get_missing_extra_spawns
function get_missing_extra_spawns(extra_spawn_chance_id: integer): integer, integerextra_spawn_chance_id:integer
Returns integer, integer
Use to query whether any of the requested spawns could not be made, usually because there were not enough valid spaces in the level.
Returns missing spawns in the front layer and missing spawns in the back layer in that order.
The value only makes sense after level generation is complete, aka after ON.POST_LEVEL_GENERATION has run.
get_procedural_spawn_chance
function get_procedural_spawn_chance(chance_id: PROCEDURAL_CHANCE): integerchance_id:PROCEDURAL_CHANCE
Returns integer
Get the inverse chance of a procedural spawn for the current level. A return value of 0 does not mean the chance is infinite, it means the chance is zero.
layer_door
function layer_door(x: number, y: number)x:numbery:number
Short for spawn_layer_door.
spawn
-- spawn a jetpack next to the playerspawn(ENT_TYPE.ITEM_JETPACK, 1, 0, LAYER.PLAYER, 0, 0)function spawn(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER, vx: number, vy: number): integerReturns integer
Short for spawn_entity.
spawn_apep
function spawn_apep(x: number, y: number, layer: LAYER, right: boolean): integerx:numbery:numberlayer:LAYERright:boolean
Returns integer
Spawns apep with the choice if it going left or right, if you want the game to choose use regular spawn functions with ENT_TYPE.MONS_APEP_HEAD
spawn_companion
function spawn_companion(companion_type: ENT_TYPE, x: number, y: number, layer: LAYER): integerReturns integer
Spawn a companion (hired hand, player character, eggplant child)
spawn_critical
function spawn_critical(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER, vx: number, vy: number): integerReturns integer
Short for spawn_entity_nonreplaceable.
spawn_door
function spawn_door(x: number, y: number, layer: LAYER, w: integer, l: integer, t: integer): integerx:numbery:numberlayer:LAYERw:integerl:integert:integer
Returns integer
Spawn a door to another world, level and theme and return the uid of spawned entity. Uses level coordinates with LAYER.FRONT and LAYER.BACK, but player-relative coordinates with LAYER.PLAYERn
spawn_entity
-- spawn megajelly on top of player using absolute coordinates on level startset_callback(function() local x, y, layer = get_position(players[1].uid) spawn_entity(ENT_TYPE.MONS_MEGAJELLYFISH, x, y+3, layer, 0, 0)end, ON.LEVEL)
-- spawn clover next to player using player-relative coordinatesset_callback(function() spawn(ENT_TYPE.ITEM_PICKUP_CLOVER, 1, 0, LAYER.PLAYER1, 0, 0)end, ON.LEVEL)function spawn_entity(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER, vx: number, vy: number): integerReturns integer
Spawn an entity in position with some velocity and return the uid of spawned entity. Uses level coordinates with LAYER.FRONT and LAYER.BACK, but player-relative coordinates with LAYER.PLAYER(n), where (n) is a player number (1-4).
spawn_entity_nonreplaceable
function spawn_entity_nonreplaceable(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER, vx: number, vy: number): integerReturns integer
Same as spawn_entity but does not trigger any pre-entity-spawn callbacks, so it will not be replaced by another script
spawn_entity_over
function spawn_entity_over(entity_type: ENT_TYPE, over_uid: integer, x: number, y: number): integerentity_type:ENT_TYPEover_uid:integerx:numbery:number
Returns integer
Spawn an entity of entity_type attached to some other entity over_uid, in offset x, y
spawn_entity_snapped_to_floor
function spawn_entity_snapped_to_floor(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER): integerReturns integer
Spawns an entity directly on the floor below the tile at the given position. Use this to avoid the little fall that some entities do when spawned during level gen callbacks.
spawn_grid_entity
function spawn_grid_entity(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER): integerReturns integer
Spawn a grid entity, such as floor or traps, that snaps to the grid.
spawn_layer_door
function spawn_layer_door(x: number, y: number)x:numbery:number
Spawn a door to backlayer.
spawn_liquid
function spawn_liquid(entity_type: ENT_TYPE, x: number, y: number)entity_type:ENT_TYPEx:numbery:number
function spawn_liquid(entity_type: ENT_TYPE, x: number, y: number, velocityx: number, velocityy: number, liquid_flags: integer, amount: integer)entity_type:ENT_TYPEx:numbery:numbervelocityx:numbervelocityy:numberliquid_flags:integeramount:integer
function spawn_liquid(entity_type: ENT_TYPE, x: number, y: number, velocityx: number, velocityy: number, liquid_flags: integer, amount: integer, blobs_separation: number)entity_type:ENT_TYPEx:numbery:numbervelocityx:numbervelocityy:numberliquid_flags:integeramount:integerblobs_separation:number
Spawn liquids, always spawns in the front layer, will have fun effects if entity_type is not a liquid (only the short version, without velocity etc.).
Don't overuse this, you are still restricted by the liquid pool sizes and thus might crash the game.
liquid_flags - not much known about, 2 - will probably crash the game, 3 - pause_physics, 6-12 is probably agitation, surface_tension etc. set to 0 to ignore
amount - it will spawn amount x amount (so 1 = 1, 2 = 4, 3 = 6 etc.), blobs_separation is optional
spawn_mushroom
function spawn_mushroom(x: number, y: number, l: LAYER): integerx:numbery:numberl:LAYER
Returns integer
function spawn_mushroom(x: number, y: number, l: LAYER, height: integer): integerx:numbery:numberl:LAYERheight:integer
Returns integer
Spawns and grows mushroom, height relates to the trunk, without it, it will roll the game default 3-5 height Regardless, if there is not enough space, it will spawn shorter one or if there is no space even for the smallest one, it will just not spawn at all Returns uid of the base or -1 if it wasn't able to spawn
spawn_on_floor
function spawn_on_floor(entity_type: ENT_TYPE, x: number, y: number, layer: LAYER): integerReturns integer
Short for spawn_entity_snapped_to_floor.
spawn_over
function spawn_over(entity_type: ENT_TYPE, over_uid: integer, x: number, y: number): integerentity_type:ENT_TYPEover_uid:integerx:numbery:number
Returns integer
Short for spawn_entity_over
spawn_player
function spawn_player(player_slot: integer, x?: number, y?: number, layer?: LAYER): integerplayer_slot:integerx?:numberoptionaly?:numberoptionallayer?:LAYERoptional
Returns integer
Spawn a player in given location, if player of that slot already exist it will spawn clone, the game may crash as this is very unexpected situation
If you want to respawn a player that is a ghost, set in his Inventory health to above 0, and time_of_death to 0 and call this function, the ghost entity will be removed automatically
spawn_playerghost
function spawn_playerghost(char_type: ENT_TYPE, x: number, y: number, layer: LAYER): integerReturns integer
Spawn the PlayerGhost entity, it will not move and not be connected to any player, you can then use steal_input and send_input to control it
or change it's player_inputs to the input of real player so he can control it directly
spawn_tree
function spawn_tree(x: number, y: number, layer: LAYER): integerx:numbery:numberlayer:LAYER
Returns integer
function spawn_tree(x: number, y: number, layer: LAYER, height: integer): integerx:numbery:numberlayer:LAYERheight:integer
Returns integer
Spawns and grows a tree
spawn_unrolled_player_rope
function spawn_unrolled_player_rope(x: number, y: number, layer: LAYER, texture: TEXTURE): integerReturns integer
function spawn_unrolled_player_rope(x: number, y: number, layer: LAYER, texture: TEXTURE, max_length: integer): integerReturns integer
Spawns an already unrolled rope as if created by player