Docs/API

Areas

Fields and methods of area handles: list players and NPCs, find positions, spawn NPCs, start and stop events, and send local messages.

API version 1Lua 5.1Updated 2026-11-07

An area handle refers to one area instance by its key: a public map ("Village") or one player's private hideout ("Cabin@<identity>").

FieldTypeDescription
keystringInstance key.
namestringMap name ("Village", "Cabin").
hideoutbooleanA private hideout map.
loadedbooleanThe instance is loaded now.
player_countnumberPlayers in this instance.
npc_countnumberLiving NPCs.
eventstring or nilThe active native dynamic event's key, or nil. Scenario events are not shown here.
spawnpositionThe map's authored player start point.

Every field except key, name, hideout and loaded is nil while the area is unloaded, and methods return nil, "area is no longer loaded".

area:players()#

Returns: list of players

Players in this instance.

area:players_near(position, radius)#

Returns: list of players

Living players within radius metres.

area:npcs()#

Returns: list of NPCs

Living NPCs.

area:tell(message, [color])#

Returns: —

Sends a private chat line to everyone in this instance. See chat messages.

area:ai_spawn_points()#

Returns: list of positions

The map's authored AI spawn markers, unchecked. May be empty.

area:random_position()#

Returns: position, or nil, err

A random AI spawn marker that is valid ground right now (the same check spawn_npc uses), already moved onto the floor. The safest position to pass to spawn_npc.

area:spawn_npc(position, [kind])#

Returns: NPC, or nil, err

Spawns one NPC. See below.

area:spawn_items(position, items, [radius])#

Returns: message, or nil, err

Drops loose item pickups into the world of any loaded area, hideouts included.

  • position is {x, y, z} (or {x=, y=, z=}).
  • items is an item name, or the same array of records as player:give, limited to item, count and amount (up to 64 instances).
  • Each instance becomes its own pickup. It is scattered randomly within radius metres (0 to 100, default 0 puts them all at the exact point) and then falls onto the ground.
  • Item names match like /give. The whole call validates first or spawns nothing.
area:spawn_items(area.spawn, {{item="Bandage", count=3}, {item="Ammo_223", amount=30}}, 5)

area:place_objects(placements)#

Returns: list of object handles, or nil, err

Queues placement and yields until the batch is ready.

area:remove_objects(objects)#

Returns: true, or nil, err

Queues removal and yields until navigation is updated.

area:can_place(prefab, position, [options])#

Returns: true, or nil, err

Runs the same checks without placing anything.

area:buildings()#

Returns: list of buildings

Every building in the area (scenario, script and admin placed), sorted by id.

area:building(id)#

Returns: building, or nil

One building by id.

area:start_event(name)#

Returns: message, or nil, err

Starts the scenario event name. If no scenario event has that name, it starts the native dynamic event like /spawnevent: this replaces any current native event and fails if the event cannot occur on this map.

area:stop_event([name])#

Returns: true, or nil, err

With a name, ends that scenario event here (reason "stopped"). Without one, stops the native dynamic event.

Spawning NPCs#

area:spawn_npc(position, kind) uses the server's normal AI spawn path:

  • The position is moved onto valid ground: it must be both a physical floor and a walkable navigation surface, or the spawn fails.
  • The NPC gets the standard loadout for its kind and starts wandering.
  • It counts towards the map's AI population and saves with the area like any other NPC.

kind is one of bandit, guard, military, nomad, bogeyman or punisher. Without a kind, the map's own AI type is used. The spawn fails in a private hideout, at an invalid position, while a Nomad gathering is clearing hostile AI from the map, or when the area has run out of NPC IDs.

The boss kinds (bogeyman, punisher) are normally spawned by their native events. Spawning them elsewhere uses their exported AI, but has not been checked in game.

Found a mistake or missing detail? Tell us in the Discord.