All core functions involving xy coordinates interpret these as relative to the
last defined map or room.
+
=== abscoord
Convert a room- or map-relative coordinate to absolute.
local filename = nh.dump_fmtstr("/tmp/nethack.%n.%d.log");
+
=== getlin
Asks the player for a text to enter, and returns the entered string.
Get information about the map location.
Returns a table with the following elements:
+[%header]
|===
| field name | type | description
| glyph | integer |
| flags | table | See below
|===
+[%header]
|===
| field name | type | description
| nodoor | boolean | door
Get trap info at x,y
Returns a table with the following elements:
+[%header]
|===
| field name | type | description
| tx, ty | integer | trap coordinates
nh.pushkey("i");
+
=== random
Generate a random number.
nh.random(10); -- returns a number between 0 and 9, inclusive.
nh.random(1,5); -- same as 1 + nh.random(5);
+
=== rn2
Generate a random number.
nh.rn2(10); -- returns a number between 0 and 9, inclusive.
+
=== s_suffix
Return a string converted to possessive.
nh.verbalize("Message to say.");
+
== Special level functions
Functions for creating special levels. They are in the `des` table.
All special level functions involving xy coordinates interpret these as relative
to the last defined map or room.
+
=== altar
Create an altar of certain type and alignment.
des.altar({ x=6, y=12 });
des.altar({ coord = {5, 10}, align = "noalign", type = "altar" });
+
=== corridor
Create a random corridor from one room to another.
des.corridor({ srcroom=1, srcdoor=2, srcwall="north", destroom=2, destdoor=1, destwall="west" });
+
=== door
Create a door at a coordinate on the map, or in a room's wall.
des.door({ wall = "north", pos = 3, state = "secret" });
des.door("nodoor", 1, 2);
+
=== drawbridge
+Create a drawbridge. Location is where the open drawbridge would be,
+and there should be a wall when moving one step towards the diven direction;
+this is where the portcullis will be placed.
+
+* dir is one of "north", "south", "west", "east", or "random".
+* state is one of "open", "closed", or "random".
+
Example:
des.drawbridge({ dir="east", state="closed", x=05,y=08 });
des.drawbridge({ dir="east", state="closed", coord={05,08} });
+
=== engraving
+Create an engraving.
+
+* type is one of "dust", "engrave", "burn", "mark", or "blood".
+
Example:
des.engraving({ x = 1, y = 1, type = "burn", text = "Foo" });
des.engraving({ coord = {1, 1}, type = "burn", text = "Foo" });
des.engraving({x,y}, "engrave", "Foo");
+
=== feature
Create a feature, and set flags for it.
des.feature({ type = "throne", coord = {4, 6}, looted = true });
des.feature({ type = "tree", coord = {4, 6}, looted = true, swarm = false });
+
=== finalize_level
Only used for testing purposes. See also <<_reset_level>>.
des.finalize_level();
+
=== gold
Create a pile of gold.
des.gold({ amount = 500, coord = {2, 5} });
des.gold();
+
=== grave
+Create a grave. A missing text results in a random epitaph being used.
+
Example:
des.grave(40,11, "Text");
des.grave({ text = "Epitaph text" });
des.grave();
+
=== ladder
+Create a ladder.
+
Example:
des.ladder("down");
des.ladder({ x=11, y=05, dir="down" });
des.ladder({ coord={11, 05}, dir="down" });
+
=== level_flags
Set flags for this level.
des.level_flags("noteleport", "mazelevel");
+
=== level_init
Initialize the map with a random generator of a certain type.
des.level_init({ style = "mines", fg = ".", bg = "}", smoothed=true, joined=true, lit=0 })
des.level_init({ style = "maze", corrwid = 3, wallthick = 1, deadends = false });
+
=== levregion
+Create a region where a stair, a branch stair, or a portal is created,
+or a region which limits teleportation.
+
+* type is one of "stair-down", "stair-up", "portal", "branch", "teleport", "teleport-up", or "teleport-down".
+* name is used for portals as the target level name.
+
Example:
des.levregion({ region = { x1,y1, x2,y2 }, exclude = { x1,y1, x2,y2 }, type = "portal", name="air" });
+
=== map
Construct a piece of the level from text map. Takes one parameter, either a text string
end });
local sel = des.map([[LLL]]);
+
=== mazewalk
+Create a maze.
+
+* dir is one of "north", "south", "east", "west", or "random", and tells which direction the maze creation starts. Default is "random".
+* stocked tells whether the maze is stocked with default monsters and objects.
+* typ is the map terrain used for the walkable parts of the maze.
+
Example:
des.mazewalk({ x = NN, y = NN, typ = ".", dir = "north", stocked = 0 });
des.mazewalk({ coord = {NN, NN}, typ = ".", dir = "north" });
des.mazewalk(x,y,dir);
+
=== message
+Message shown to the player when entering the level for the first time.
+
Example:
des.message("Foo");
+
=== mineralize
+Place random gems, gold, and kelp on the level.
+
Example:
des.mineralize({ gem_prob = 10, gold_prob = 20, kelp_moat = 30, kelp_pool = 40 });
+
=== monster
Create a monster.
des.monster({ id = "giant mimic", appear_as = "obj:boulder" });
des.monster({ class = "H", peaceful = 0 });
+
=== non_diggable
+Set walls in an area of the map as non-diggable. See also: <<_wall_property>>.
+
Example:
des.non_diggable(selection);
des.non_diggable();
+
=== non_passwall
+Set walls in an area of the map as non-passwall, so they can't be phased through. See also: <<_wall_property>>.
+
Example:
des.non_passwall(selection);
des.random_corridors();
+
=== region
+Create a room region, which can be irregular; use the boundary <<_map_characters,map character>> to restrict the floodfilled area.
+
Example:
des.region(selection, lit);
des.region({ x1=NN, y1=NN, x2=NN, y2=NN, lit=BOOL, type=ROOMTYPE, joined=BOOL, irregular=BOOL, filled=NN [ , contents = FUNCTION ] });
des.region({ region={x1,y1, x2,y2}, type="ordinary" });
+
=== replace_terrain
Replaces matching terrain on the area, selection, or whole map.
des.replace_terrain({ mapfragment=[[...]], toterrain=MAPCHAR });
des.replace_terrain({ fromterrain=MAPCHAR, toterrain=MAPCHAR });
+
=== reset_level
Only used for testing purposes. See also <<_finalize_level>>.
des.reset_level();
+
=== room
Create a room of certain type and size. Takes one parameter, a table with the following
| contents | A function called with one parameter, a table with room data. See <<_room_contents>>.
|===
+
==== room contents
The room contents function is called when the room is created.
des.terrain(room.width, room.height, "T");
end });
+
=== stair
+Create stairs.
+
Example:
des.stair("up");
des.stair("down", 4, 7);
des.stair("down", {4, 7});
+
=== teleport_region
Example:
des.teleport_region({ region = { x1,y1, x2,y2} });
des.teleport_region({ region = { x1,y1, x2,y2}, region_islev = 1, exclude = { x1,y1, x2,y2}, exclude_islen = 1, dir = "up" });
+
=== terrain
Example:
des.terrain({20,11}, ".");
des.terrain(21,12, ".");
+
=== trap
Create a trap. The `launchfrom` is relative to the rolling boulder trap coord.
des.trap("rust")
des.trap();
+
=== wall_property
+Set walls in an area nondiggable or non-passwall. See also: <<_non_diggable>> and <<_non_passwall>>.
+
Example:
des.wall_property({ x1=0, y1=0, x2=78, y2=20, property="nondiggable" });
des.wall_property({ region = {1,0, 78,20}, property="nonpasswall" });
+
=== wallify
Example:
Selection object can be used to "select" areas of the map with graphic primitives.
+
=== new
Create a new selection.
Alias for <<_fillrect>>.
+
=== bounds
Get the bounding box for the selection. Returns a table with lx, ly, hx, hy integer fields.
local sel2 = selection.clone(sel);
+
=== ellipse
Example:
local s = selection.ellipse(sel, x, y, radius1, radius2);
local s = selection.ellipse(sel, x, y, radius1, radius2, filled);
+
=== fillrect
Example:
s:fillrect(x1,y1, x2,y2);
selection.area(x1,y1, x2,y2);
+
=== filter_mapchar
Filter points in selection by choosing those that match the map character,
local s = selection.filter_mapchar(sel, mapchar);
local s = selection.filter_mapchar(sel, mapchar, lit);
+
=== floodfill
Select locations by starting floodfill at (x,y),
local s = selection.floodfill(x,y);
local s = selection.floodfill(x,y, true);
+
=== get
Get the selection value at (x,y).
local value = selection.get(sel, x, y);
local value = selection.get(sel, { x = 10, y = 14 });
+
=== gradient
Create a "gradient" of selected positions.
local s = selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12, mindist = 4, maxdist = 10, limited = false });
+
=== grow
Add locations to the selection by choosing unselected locations
local s = selection.grow(sel);
local s = selection.grow(sel, "north");
+
=== iterate
Iterate through the selection, calling a function for each set point.
sel:iterate(function(x,y) ... end);
+
=== line
Draw a line from (x1,y1) to (x2,y2).
local s = selection.line(x1,y1, x2,y2);
s:line(x1,y1, x2,y2);
+
=== match
Every location on the map, centered on the map fragment and matching it,
.L.
...]]);
+
=== negate
Negate the selection. Alias for "unary minus" and "bitwise not".
local s = selection.negate(sel);
local s = selection.negate();
+
=== percentage
Each selected location has a percentage chance of being selected in the new selection.
local s = selection.percentage(sel, 50);
+
=== randline
Example:
local s = selection.randline(sel, x1,y1, x2,y2, roughness);
local s = selection.randline(x1,y1, x2,y2, roughness);
+
=== rect
Draw a rectangle.
local s = selection.rect(sel, x1,y1, x2,y2);
+
=== rndcoord
Choose one of the selected locations, and return a table with x and y keys.
local sel = sel:set();
local sel = selection.set(sel);
+
== Obj
Handling objects via obj-class.
+
=== new
Create a new object via wishing routine.
| `"w"` | "any wall" - see <<_match>>
|===
+
== Constants
These constants are in the `nhc` table.