Difference between revisions of "DSB/Exposed functions"
(78 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
==Introduction== | ==Introduction== | ||
Functions are given in the form: | Functions are given in the form: | ||
− | ; | + | ;function(arguments, ~[optional arguments]) = return value |
− | :If the terminology doesn't make sense, check [ | + | :If the terminology doesn't make sense, check [[DSB/Basic DSB Terminology]]. |
Functions without a dsb_ prefix are part of [[DSB/Base Code|base/]], not the core engine. | Functions without a dsb_ prefix are part of [[DSB/Base Code|base/]], not the core engine. | ||
Line 18: | Line 18: | ||
==Bitmaps and Drawing== | ==Bitmaps and Drawing== | ||
;<b>dsb_get_bitmap</b>(name) = bitmap | ;<b>dsb_get_bitmap</b>(name) = bitmap | ||
− | :Searches the dungeon's directory for the bitmap, and then <i>graphics.dsb</i>, and finally the default <i>graphics.dat</i>. Returns a truecolor bitmap, but the bitmap can be 256 colors on disk to save space. | + | :Searches the dungeon's directory for the bitmap, and then <i>graphics.dsb</i>, and finally the default <i>graphics.dat</i>. Returns a truecolor bitmap, but the bitmap can be 256 colors on disk to save space. Don't specify a file extension as DSB will figure it out. |
+ | |||
+ | ;<b>dsb_get_bitmap</b>(name, relative_path) = bitmap | ||
+ | :Same as above but with subdirectories. Example: "path/to/actual/file.ext" | ||
;<b>dsb_get_mask_bitmap(name)</b> = bitmap | ;<b>dsb_get_mask_bitmap(name)</b> = bitmap | ||
Line 39: | Line 42: | ||
;<b>dsb_bitmap_blit</b>(src_bmp, dest_bmp, x_src, y_src, x_dest, y_dest, width, height) | ;<b>dsb_bitmap_blit</b>(src_bmp, dest_bmp, x_src, y_src, x_dest, y_dest, width, height) | ||
+ | ;<b>dsb_bitmap_blit</b>(src_bmp, dest_bmp, x_src, y_src, x_dest, y_dest, src_width, src_height, final_width, final_height) | ||
:Blits one bitmap onto another. | :Blits one bitmap onto another. | ||
+ | :This function takes either 8 or 10 parameters. In the 10 parameter version, the last two parameters define the size of the final bitmap to be rendered. This allows you to scale bitmaps dynamically. There's no anti-aliasing, so this works best with simple pixel images. | ||
;<b>dsb_bitmap_draw</b>(src_bmp, dest_bmp, x, y, flip) | ;<b>dsb_bitmap_draw</b>(src_bmp, dest_bmp, x, y, flip) | ||
− | :Draws the entire source bitmap on to the destination, taking any animation or offsets into account. Pass true to | + | ;<b>dsb_bitmap_draw</b>(src_bmp, dest_bmp, x, y, src_width, src_height, final_width, final_height, flip) |
+ | :Draws the entire source bitmap on to the destination, taking any animation or offsets into account. Pass true to the last parameter to horizontally flip the bitmap. Pass only 5 parameters to draw a simple bitmap at x,y, or pass 9 parameters to scale the bitmap dynamically. | ||
;<b>dsb_bitmap_width</b>(bitmap) = integer | ;<b>dsb_bitmap_width</b>(bitmap) = integer | ||
− | <b>dsb_bitmap_height</b>(bitmap) = integer | + | ;<b>dsb_bitmap_height</b>(bitmap) = integer |
:Returns the dimension of the bitmap. | :Returns the dimension of the bitmap. | ||
Line 52: | Line 58: | ||
;<b>dsb_bitmap_textout</b>(bitmap, font, string, x, y, alignment, color) = integer | ;<b>dsb_bitmap_textout</b>(bitmap, font, string, x, y, alignment, color) = integer | ||
− | :Renders text onto a bitmap in the specified font and color, with the specified alignment: (LEFT, RIGHT, CENTER, or MULTILINE). Returns the number of lines printed. | + | :Renders text onto a bitmap in the specified font and color, with the specified alignment: (LEFT, RIGHT, CENTER, or MULTILINE). Returns the number of lines printed. If you use the MULTILINE version, call <b>dsb_textformat()</b> first to set the line length and height. The textformat settings are global so if you don't know what code may run between the <b>dsb_textformat</b> call and the <b>dsb_bitmap_textout</b> call, then you don't really know what format it will draw in. |
;<b>dsb_dungeon_view</b>(lev, x, y, dir, light) = bitmap | ;<b>dsb_dungeon_view</b>(lev, x, y, dir, light) = bitmap | ||
:Return a rendering of the viewport. | :Return a rendering of the viewport. | ||
− | ;<b> | + | ;<b>dsb_viewport_distort</b>(effect) |
− | : | + | :For viewport postprocessing |
+ | |||
+ | ;<b>dsb_get_pixel</b>(bmp, x, y) = {R,G,B},[alpha] | ||
+ | ;<b>dsb_set_pixel</b>(bmp, x, y, {R,G,B}, [alpha]) | ||
+ | :These are used for per-pixel bitmap manipulation. | ||
+ | :If the pixel queried with '''dsb_get_pixel()''' has an alpha channel, then the function returns two values: the {R,G,B} table, and an extra parameter containing the alpha. If there is no alpha, this second one will be '''nil'''. | ||
+ | :Alpha values for both '''dsb_get_pixel()''' and '''dsb_set_pixel()''' are in the range 0-255, where 0 is fully transparent and 255 is fully opaque. | ||
+ | :Here is a short example of how you might use these function to tint a bitmap: | ||
+ | :http://dungeon-master.com/forum/viewtopic.php?f=53&t=28859&p=135634#p135634 | ||
+ | |||
+ | ;<b>dsb_rgb_to_hsv</b>({R,G,B}) = {H,S,V} | ||
+ | ;<b>dsb_hsv_to_rgb</b>({H,S,V}) = {R,G,B} | ||
+ | :Converts color model. | ||
− | ;<b> | + | ;<b>dsb_screen_bitmap</b>() = bitmap |
− | : | + | :Takes a screenshot of the entire Windows screen and assigns it to a bitmap you can use later. If you're running the game in fullscreen mode, this will allow you to screenshot the entire game window. If you're running in Windowed mode, this will screenshot your visible Windows screen from the top/left 0,0 coordinate (probably not very useful in your dungeon!) |
==Fonts and Text== | ==Fonts and Text== | ||
− | ;<b>dsb_get_font</b>(name) = font | + | ;<b>dsb_get_font</b>(name, relative_path) = font |
− | :Searches the same paths as <b>dsb_get_bitmap</b>, loading a font. | + | :Searches the same paths as <b>dsb_get_bitmap</b>, loading a font. Example with a subdirectory: |
+ | :<code>gfx["GAUDYMEDIEVALFONT"] = dsb_get_font("GAUDYMEDIEVAL", "fonts/gaudymedieval.pcx")</code> | ||
;<b>dsb_textformat</b>(chars_per_line, y_offset_per_line, max_lines) | ;<b>dsb_textformat</b>(chars_per_line, y_offset_per_line, max_lines) | ||
Line 72: | Line 91: | ||
;<b>dsb_write</b>(RGB, string) | ;<b>dsb_write</b>(RGB, string) | ||
:Outputs the given text string in the given color to the console. (that is, a table of { R, G, B }) | :Outputs the given text string in the given color to the console. (that is, a table of { R, G, B }) | ||
+ | |||
+ | <b>dsb_text_size(font, string) = width, height</b> [DSB 0.54+] | ||
+ | : Returns the width and height in pixels of the supplied string for the specified font. | ||
==Sound and Music== | ==Sound and Music== | ||
Line 79: | Line 101: | ||
;<b>dsb_sound</b>(sound, ~[loop]) = chan_handle | ;<b>dsb_sound</b>(sound, ~[loop]) = chan_handle | ||
:Plays the given sound. An optional boolean parameter allows you to specify if the sound should loop. Be careful, the only way to stop a looping sound is via <b>dsb_stopsound</b>, so don't lose the channel handle! | :Plays the given sound. An optional boolean parameter allows you to specify if the sound should loop. Be careful, the only way to stop a looping sound is via <b>dsb_stopsound</b>, so don't lose the channel handle! | ||
+ | |||
+ | ;<b>dsb_music</b>(sound, ~[loop]) = chan_handle | ||
+ | :Plays a sound file directly from disk instead of loading into memory first. This function only works with direct filenames, you can't send it a full path -- so your music file must be in the root of your dungeon directoy. If you use <i>dsb_music</i>, it will at least load it on demand and destroy it when it's finished, so your memory usage will be lower than if you loaded it directly as a sound. | ||
;<b>dsb_3dsound</b>(sound, lev, x, y, ~[loop]) = chan_handle | ;<b>dsb_3dsound</b>(sound, lev, x, y, ~[loop]) = chan_handle | ||
Line 85: | Line 110: | ||
;<b>local_sound</b>(id, sound) = chan_handle | ;<b>local_sound</b>(id, sound) = chan_handle | ||
:Plays a sound that appears to originate from the location of a given instance. | :Plays a sound that appears to originate from the location of a given instance. | ||
+ | |||
+ | ;<b>dsb_music_to_background</b>(?) = ? | ||
+ | :Allows multiple music streams. | ||
;<b>dsb_stopsound</b>(chan_handle) | ;<b>dsb_stopsound</b>(chan_handle) | ||
− | :Stops the sound playing on a channel handle previously returned by a call to a sound playing function. | + | :Stops the sound playing on a channel handle previously returned by a call to a sound playing function. As of DSB 0.70, passing a channel handle of -1 will stop all currently playing sounds (and release their handles). |
;<b>dsb_get_soundvol</b>(chan_handle) | ;<b>dsb_get_soundvol</b>(chan_handle) | ||
Line 96: | Line 124: | ||
==Levels and Wallsets== | ==Levels and Wallsets== | ||
− | ;<b>dsb_level_getinfo</b>(level) = x_size, y_size, light, xp_multiplier | + | <b>dsb_bottomlevel()</b> DSB 0.71+ |
+ | :Returns the deepest level of the dungeon, counting from 0 -- so a 10 level dungeon will return 9. | ||
+ | |||
+ | ;<b>dsb_level_getinfo</b>(level) = x_size, y_size, light, xp_multiplier, wallset_name | ||
:Returns the basic info about a level. | :Returns the basic info about a level. | ||
− | ;<b>dsb_level_tint</b>(level, RGB) | + | ;<b>dsb_level_tint</b>(level, RGB, ~[level]) |
− | :Tells DSB to tint the dynamically scaled and shaded objects in a level a certain way. By default, this is {0, 0, 0}, causing the dungeon to fade to black, just like DM, but if the ambient light color is different, or you are outdoors and fade to a misty grey instead of black, you will probably want to change this. | + | :Tells DSB to tint the dynamically scaled and shaded objects in a level a certain way. By default, this is {0, 0, 0}, causing the dungeon to fade to black, just like DM, but if the ambient light color is different, or you are outdoors and fade to a misty grey instead of black, you will probably want to change this. The third parameter is to control the level of tint applied. The default is 64 but a value of over 200 or so will make everything so dark you can't see anything. |
;<b>dsb_make_wallset</b>(floor, roof, pers0, pers0alt, pers1, pers1alt, pers2, pers2alt, pers3, persl3alt, farwall3, farwall3alt, front1, front2, front3, patch1, patch2, patch3, patchside, window) = wallset | ;<b>dsb_make_wallset</b>(floor, roof, pers0, pers0alt, pers1, pers1alt, pers2, pers2alt, pers3, persl3alt, farwall3, farwall3alt, front1, front2, front3, patch1, patch2, patch3, patchside, window) = wallset | ||
Line 106: | Line 137: | ||
;<b>dsb_make_wallset_ext</b>(floor, roof, pers0, pers0alt, pers1, pers1alt, pers2, pers2alt, pers3, persl3alt, farwall3, farwall3alt, front1, front2, front3, left1, left1alt, left2, left2alt, left3, left3alt, patch1, patch2, patch3, patchside, window) = wallset | ;<b>dsb_make_wallset_ext</b>(floor, roof, pers0, pers0alt, pers1, pers1alt, pers2, pers2alt, pers3, persl3alt, farwall3, farwall3alt, front1, front2, front3, left1, left1alt, left2, left2alt, left3, left3alt, patch1, patch2, patch3, patchside, window) = wallset | ||
− | :Creates a wallset from the specified bitmaps. This command takes 6 more arguments: 6 "left side" bitmaps. If you're using a converted DM2, [[DSB/DSB for RTC users|DSB for RTC users]], or WHACK wallset, you'll find this command useful. | + | :Creates a wallset from the specified bitmaps. This command takes 6 more arguments: 6 "left side" bitmaps. If you're using a converted DM2, [[DSB/DSB for RTC users|DSB for RTC users]], or WHACK wallset, you'll find this command useful. From DSB 0.70 onwards, the window bitmap can be a table containing two different bitmaps: one for the hole part, and one for the magic glow, eg: {gfx.default_window_hole, gfx.window_glow_wall} |
;<b>dsb_level_wallset</b>(level, wallset) | ;<b>dsb_level_wallset</b>(level, wallset) | ||
Line 115: | Line 146: | ||
;<b>dsb_alt_wallset</b>(wallset, level, x, y, dir) | ;<b>dsb_alt_wallset</b>(wallset, level, x, y, dir) | ||
:Tells DSB to use the specified wallset only on the given direction of the given tile. If CENTER is specified, it will use that wallset on all directions of the given tile. | :Tells DSB to use the specified wallset only on the given direction of the given tile. If CENTER is specified, it will use that wallset on all directions of the given tile. | ||
+ | |||
+ | ;<b>dsb_get_alt_wallset</b>(level, x, y, dir) | ||
+ | :Return the wallset at the given direction of the given tile. Use in conjunction with the Wall Graphics mode in ESB where you can paint alternate wallsets on individual faces of individual tiles. | ||
+ | |||
+ | ;<b>dsb_wallset_flip_floor</b>(wallset, flip) | ||
+ | :Pass true to flip to automatically flip the floor every other step, like standard floors, or pass a bitmap to have a different bitmap show up when the floor is "flipped." | ||
+ | |||
+ | ;<b>dsb_wallset_flip_roof</b>(wallset, flip) | ||
+ | :Pass true to flip to automatically flip the roof every other step, like standard floors, or pass a bitmap to have a different bitmap show up when the roof is "flipped." | ||
+ | |||
+ | ;<b>dsb_override_floor</b>(bitmap_name, flip) | ||
+ | :Overrides the floor with the bitmap in the gfx table with the given name, regardless of what wallset is in use. Pass true to flip to automatically flip the floor every other step, like standard floors, or pass a second bitmap name to have a different bitmap show up when the floor is "flipped." | ||
+ | |||
+ | ;<b>dsb_override_roof</b>(bitmap_name, flip) | ||
+ | :Overrides the roof with the bitmap in the gfx table with the given name, regardless of what wallset is in use. Pass true to flip to automatically flip the roof every other step, like standard roofs, or pass a second bitmap name to have a different bitmap show up when the roof is "flipped." | ||
;<b>dsb_text2map</b>(level, x_size, y_size, light, xp_multiplier, maptable) | ;<b>dsb_text2map</b>(level, x_size, y_size, light, xp_multiplier, maptable) | ||
Line 123: | Line 169: | ||
;<b>dsb_get_cell</b>(level, x, y) = boolean | ;<b>dsb_get_cell</b>(level, x, y) = boolean | ||
− | :Returns a boolean specifying whether or not the given cell in the dungeon is a wall. Use <b>dsb_fetch</b> to find out anything else about what's there. | + | :Returns a boolean specifying whether or not the given cell in the dungeon is a wall. Use <b>dsb_fetch</b> to find out anything else about what's there. Note that an out of bounds cell is not considered a wall. |
;<b>dsb_set_cell</b>(level, x, y, value) | ;<b>dsb_set_cell</b>(level, x, y, value) | ||
Line 141: | Line 187: | ||
;<b>dsb_offer_champion</b>(char_id, mode, take_function) | ;<b>dsb_offer_champion</b>(char_id, mode, take_function) | ||
:Offers the given char_id, with the options specified by "mode" available. | :Offers the given char_id, with the options specified by "mode" available. | ||
− | ~[1 = resurrect, 2 = reincarnate, 3 = both]. The take_function is a Lua function that is executed if the offered character is resurrected or reincarnated. It is typically used to clear out the champion's mirror, or do something else to denote that the character is no longer available. | + | :~[1 = resurrect, 2 = reincarnate, 3 = both]. The take_function is a Lua function that is executed if the offered character is resurrected or reincarnated. It is typically used to clear out the champion's mirror, or do something else to denote that the character is no longer available. |
;<b>dsb_champion_toparty</b>(ppos, char) | ;<b>dsb_champion_toparty</b>(ppos, char) | ||
Line 151: | Line 197: | ||
;<b>dsb_get_charname</b>(char) = string | ;<b>dsb_get_charname</b>(char) = string | ||
:Returns the character's name. | :Returns the character's name. | ||
+ | |||
+ | ;<b>dsb_get_chartitle</b>(char) = string | ||
+ | :Returns the character's lastname or title. | ||
;<b>dsb_get_bar</b>(char, bar) = integer | ;<b>dsb_get_bar</b>(char, bar) = integer | ||
Line 168: | Line 217: | ||
;<b>do_damage(ppos, char, type, amount)</b> | ;<b>do_damage(ppos, char, type, amount)</b> | ||
:This function will damage the given character at the given ppos the given amount of the given type (HEALTH, STAMINA, or MANA). The units specified here are as the player perceives them (that is, divided by ten from internal representations and the same scale used by monsters) | :This function will damage the given character at the given ppos the given amount of the given type (HEALTH, STAMINA, or MANA). The units specified here are as the player perceives them (that is, divided by ten from internal representations and the same scale used by monsters) | ||
− | Defined in <i>base/damage.lua</i>. | + | :Defined in <i>base/damage.lua</i>. |
;<b>dsb_get_load</b>(char) = integer | ;<b>dsb_get_load</b>(char) = integer | ||
Line 186: | Line 235: | ||
;<b>dsb_replace_portrait</b>(char, portrait_name) | ;<b>dsb_replace_portrait</b>(char, portrait_name) | ||
:Replaces the portrait of a character with the given image. This can happen on-the-fly at any time. Note that the portrait must be specified as a string, not an entry in the gfx table. That is, pass "portrait", not gfx.portrait. | :Replaces the portrait of a character with the given image. This can happen on-the-fly at any time. Note that the portrait must be specified as a string, not an entry in the gfx table. That is, pass "portrait", not gfx.portrait. | ||
+ | |||
+ | ;<b>dsb_get_portraitname</b>(char) = portrait_name | ||
+ | :Retrieves the name of a character's portrait. | ||
+ | |||
+ | ;<b>dsb_set_portraitname</b>(char, portrait_name) | ||
+ | :An alias for dsb_replace_portrait (for symmetry). | ||
+ | |||
+ | ;<b>dsb_replace_topimages</b>(char, hands_image_name, portrait_background_image_name, death_image_name) | ||
+ | :Replaces the top "hands", "portrait background" and "death" images. Pass the image names nil to leave the image alone, or 0 to go back to the default. Remember that we pass the image parameters as strings, and not a direct reference to the ''gfx'' table. Example: ''dsb_replace_topimages(char, nil, nil, "frozen_face_halk")'' | ||
;<b>dsb_replace_charhand</b>(char, hand_name) | ;<b>dsb_replace_charhand</b>(char, hand_name) | ||
Line 202: | Line 260: | ||
;<b>dsb_give_xp</b>(char, skill, subskill, xp) | ;<b>dsb_give_xp</b>(char, skill, subskill, xp) | ||
:Gives the specified amount of XP in the specified skill and subskill (or 0 for no subskill). | :Gives the specified amount of XP in the specified skill and subskill (or 0 for no subskill). | ||
− | Important: This function gives XP only. It doesn't deal with XP multipliers, leveling up, bonuses, or anything else. | + | :Important: This function gives XP only. It doesn't deal with XP multipliers, leveling up, bonuses, or anything else. |
− | More useful to most designers will be the helper function <b>xp_up</b>. | + | :More useful to most designers will be the helper function <b>xp_up</b>. |
;<b>xp_up</b>(char, skill, subskill, xp) | ;<b>xp_up</b>(char, skill, subskill, xp) | ||
:This function takes XP multipliers, leveling up, etc. into account. | :This function takes XP multipliers, leveling up, etc. into account. | ||
− | Defined in <i>base/xp.lua</i>. | + | :Defined in <i>base/xp.lua</i>. |
;<b>dsb_get_xp</b>(char, skill, subskill) = xp | ;<b>dsb_get_xp</b>(char, skill, subskill) = xp | ||
Line 273: | Line 331: | ||
;<b>dsb_party_scanfor</b>(arch) = id | ;<b>dsb_party_scanfor</b>(arch) = id | ||
:Scans the entire party's inventory for a given arch. Returns the id for the first instance of that arch if it is found, or nil if nothing is found. | :Scans the entire party's inventory for a given arch. Returns the id for the first instance of that arch if it is found, or nil if nothing is found. | ||
+ | |||
+ | ;<b>dsb_get_caster</b>() = ppos | ||
+ | :Returns the current spell caster. | ||
==Multiple Parties== | ==Multiple Parties== | ||
− | + | <b>dsb_get_mpartyflag</b>(flag) = value | |
<b>dsb_set_mpartyflag</b>(flag) | <b>dsb_set_mpartyflag</b>(flag) | ||
<b>dsb_clear_mpartyflag</b>(flag) | <b>dsb_clear_mpartyflag</b>(flag) | ||
Line 281: | Line 342: | ||
:Gets, sets, clears, or toggles the value of a [[DSB/Multiple Parties|Multiple Parties]] flag. | :Gets, sets, clears, or toggles the value of a [[DSB/Multiple Parties|Multiple Parties]] flag. | ||
− | + | <b>dsb_set_exviewinst</b>(char, monster_id) | |
:This will associate a given monster inst with a character. The monster must be in LIMBO. From then on, whenever that character is seen from a 3rd person perspective, that monster will be drawn to represent that character. Don't kill this monster or bad things will happen. | :This will associate a given monster inst with a character. The monster must be in LIMBO. From then on, whenever that character is seen from a 3rd person perspective, that monster will be drawn to represent that character. Don't kill this monster or bad things will happen. | ||
− | + | <b>dsb_party_apush</b>(party) | |
<b>dsb_party_apop</b>(party) | <b>dsb_party_apop</b>(party) | ||
:The game uses a "party stack" to keep track of which sub-party the various party-related commands affect. The currently viewed party is always at the bottom. When a party steps on a trigger, it is pushed onto the stack before the trigger is processed. This means things like <b>dsb_party_coords</b> will generally affect the "right" party. You can directly manipulate the stack with these commands, but be careful. If you're not sure what to do with these commands, you probably don't need them. | :The game uses a "party stack" to keep track of which sub-party the various party-related commands affect. The currently viewed party is always at the bottom. When a party steps on a trigger, it is pushed onto the stack before the trigger is processed. This means things like <b>dsb_party_coords</b> will generally affect the "right" party. You can directly manipulate the stack with these commands, but be careful. If you're not sure what to do with these commands, you probably don't need them. | ||
+ | |||
+ | <b>dsb_party_contains</b>(ppos) = party_id | ||
+ | :Returns the party containing a given character ppos | ||
==Interacting with Insts== | ==Interacting with Insts== | ||
Line 292: | Line 356: | ||
:Spawns a new instance at the specified coordinates and returns its id. | :Spawns a new instance at the specified coordinates and returns its id. | ||
Note that if "level" is negative, various [[DSB/Special Values|Special Values]] can be used. | Note that if "level" is negative, various [[DSB/Special Values|Special Values]] can be used. | ||
+ | |||
+ | The ID will be a value between 1 and 32767. If there are more than 32767 insts at a time then the system will crash. Insts that are removed from the dungeon will free up IDs for new insts. Since inst IDs can be thus recycled, it may not always be safe to assume a stored ID will always point to inst it started as. | ||
;<b>dsb_move</b>(id, level, x, y, tile_location) | ;<b>dsb_move</b>(id, level, x, y, tile_location) | ||
Line 306: | Line 372: | ||
;<b>dsb_get_coords</b>(id) = level, x, y, tile_location | ;<b>dsb_get_coords</b>(id) = level, x, y, tile_location | ||
:Returns the coordinates of an instance. This is either the location in the dungeon, or, using special coordinates, its location in a character or monster's inventory, in limbo, etc. | :Returns the coordinates of an instance. This is either the location in the dungeon, or, using special coordinates, its location in a character or monster's inventory, in limbo, etc. | ||
+ | |||
+ | ;<b>dsb_get_coords_prev</b>(id) = level, x, y, tile_location | ||
+ | :Returns the object's coordinates before its most recent movement. | ||
;<b>dsb_fetch</b>(level, x, y, tile_location) = id (or table of ids), ~[number] | ;<b>dsb_fetch</b>(level, x, y, tile_location) = id (or table of ids), ~[number] | ||
Line 338: | Line 407: | ||
;<b>dsb_collide</b>(id, lev, x, y, tile, direction) = { {id, tile}, ~[...] } | ;<b>dsb_collide</b>(id, lev, x, y, tile, direction) = { {id, tile}, ~[...] } | ||
:Performs collision detection on a flying object for the specified location. This is useful when directly moving monsters around (e.g., via <b>dsb_move</b>) so that they will not apparently move "through" flying missiles. | :Performs collision detection on a flying object for the specified location. This is useful when directly moving monsters around (e.g., via <b>dsb_move</b>) so that they will not apparently move "through" flying missiles. | ||
+ | |||
+ | ;<b>dsb_set_flyreps</b>(id, repetitions) | ||
+ | :Allows you to set the number of update <b>repetitions</b> (default value is 1) that a flying object performs per tick. For example, a value of 8 will cause the <b>id</b> flying object to move 8 sub-tiles per tick, or 4 full tiles. | ||
;<b>dsb_get_gfxflag</b>(id, flag) = value | ;<b>dsb_get_gfxflag</b>(id, flag) = value | ||
Line 365: | Line 437: | ||
;<b>dsb_valid_inst</b>(id) = ternary value | ;<b>dsb_valid_inst</b>(id) = ternary value | ||
:Returns true if the instance exists, false if it doesn't but the id is valid, and nil if it is not a valid instance id. | :Returns true if the instance exists, false if it doesn't but the id is valid, and nil if it is not a valid instance id. | ||
+ | |||
+ | ;<b>clone_arch</b>(base_arch, changes) = new arch | ||
+ | :Creates a new arch type. See a simple [http://www.dungeon-master.com/forum/viewtopic.php?f=53&t=28613&p=111165#p111165 example]. | ||
+ | :The new arch will be the original arch, but with changes applied from a list of key/value pairs | ||
+ | :Note that this cannot clear a key from the original arch - any removals would need to be applied manually to the new arch | ||
==Monsters== | ==Monsters== | ||
Line 395: | Line 472: | ||
==Messaging== | ==Messaging== | ||
;<b>dsb_msg</b>(delay, id, message, data, ~[sender]) | ;<b>dsb_msg</b>(delay, id, message, data, ~[sender]) | ||
− | :Sends the specified [[DSB/Messages|Messages]] to the specified instance after the specified delay. Messages are simply integers. The object responds to the message as specified by its msg_handler, defined in its archetype. See <i>base/msg_handlers.lua</i> for many examples of what can be done with message handlers. Normally it doesn't matter where a message comes from. However, it is possible to assert the sender of the message, in the rare cases where it is needed. | + | :Sends the specified [[DSB/Messages|Messages]] to the specified instance after the specified delay. Messages are simply integers. The object responds to the message as specified by its msg_handler, defined in its archetype. See <i>base/msg_handlers.lua</i> for many examples of what can be done with message handlers. Normally it doesn't matter where a message comes from. However, it is possible to assert the sender of the message, in the rare cases where it is needed. (See [[DSB/Messages]] for more information on how to use messages) |
;<b>dsb_msg_chain</b>(id, target_id) | ;<b>dsb_msg_chain</b>(id, target_id) | ||
Line 411: | Line 488: | ||
;<b>dsb_toggle</b>(id) | ;<b>dsb_toggle</b>(id) | ||
:See the previous two. | :See the previous two. | ||
+ | |||
+ | ;<b>dsb_add_msgtype</b>(code_name,int_value) <font color="#999"> = none?</font> | ||
+ | :Adds a new message type to the system. Values above 100000 are reserved for the base code. | ||
+ | :Custom msg types will presumably still be handled the same way the built in ones are, so may be useful for triggering events on custom archs. | ||
+ | :Hmm. This could get messy if you combine msgtypes with importable archs... | ||
==Light== | ==Light== | ||
Line 418: | Line 500: | ||
==Conditions== | ==Conditions== | ||
− | + | :Conditions (i.e., status variables) are added to the game by modifying the <b>conditions</b> table, which is defined in <i>base/conditions.lua</i>. See that file for examples. | |
− | : | + | :The <b>scope</b> of the condition is either PARTY (affects the whole party) or INDIVIDUAL (affects one person). You can also specify images for the condition, like a <b>subrenderer_image</b> or a <b>portrait_image</b>. PARTY conditions can instead have an <b>overlay_image</b> that goes over the entire game's viewport. |
+ | :If <b>update_rate</b> is > 0, the specified <b>update_func</b> will be called at the specified number of ticks. The function takes the following form: | ||
+ | : | ||
function update_func(char, condition_strength) | function update_func(char, condition_strength) | ||
Line 425: | Line 509: | ||
end | end | ||
: | : | ||
− | + | ;<b>dsb_add_condition</b>(type, inventory_gfx, portrait_gfx, update_freq, function, [flags]) = condition_id <font color="red">(Deprecated)</font> | |
+ | :Adds a condition (status variable) to the list of those available, but see above. | ||
− | ;<b>dsb_replace_condition</b>(condition_id, type, inventory_gfx, portrait_gfx, update_freq, function) | + | ;<b>dsb_replace_condition</b>(condition_id, type, inventory_gfx, portrait_gfx, update_freq, function) <font color="red">(Deprecated)</font> |
− | :Replaces the information for the condition with the given id with the new condition | + | :Replaces the information for the condition with the given id with the new condition. |
;<b>dsb_get_condition</b>(char, condition) = strength | ;<b>dsb_get_condition</b>(char, condition) = strength | ||
Line 447: | Line 532: | ||
==Fullscreen== | ==Fullscreen== | ||
− | ;< | + | ;dsb_fullscreen(bitmap_or_func, click_func, update_func, mouse, { fade = true, game_draw = true }) (DSB < v0.76) |
+ | ;dsb_fullscreen(bitmap_or_func, click_func, update_func, mouse, { fade = true, game_draw = true, keep_viewmode = true }) (DSB v0.76+) | ||
:This engages the full-screen renderer, and is used for cut scenes or other interludes. If the first parameter passed is a bitmap, that bitmap will be displayed. If the first parameter is instead a function, that function will be executed every frame. The draw function will be passed the bitmap to draw to, the mouse's x location, and the mouse's y location, in the form: <code><b>draw_function</b>(bitmap, mouse_x, mouse_y)</code> | :This engages the full-screen renderer, and is used for cut scenes or other interludes. If the first parameter passed is a bitmap, that bitmap will be displayed. If the first parameter is instead a function, that function will be executed every frame. The draw function will be passed the bitmap to draw to, the mouse's x location, and the mouse's y location, in the form: <code><b>draw_function</b>(bitmap, mouse_x, mouse_y)</code> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==Subrenderers== | + | :The click_func, if provided, will be executed every time the mouse is clicked. It is of the form: <code><b>click_func</b>(mouse_x, mouse_y, mouse_buttons)</code> |
+ | |||
+ | :Update_func, if provided, will be executed every game tick. It takes no parameters. | ||
+ | |||
+ | :If mouse is nil or false, no mouse pointer will be drawn. If it is true, the standard "yellow arrow" mouse pointer will be drawn. If it is a bitmap, that bitmap will be drawn as the mouse pointer. | ||
+ | |||
+ | :There is an optional 5th parameter (a table of booleans): | ||
+ | ::<code><b>fade</b></code> will quickly fade the fullscreen bitmap in from a black screen | ||
+ | ::<code><b>game_draw</b></code> allows you to have the game view drawn in the background. So, for example, for a fullscreen view that fades in and draws the game view. | ||
+ | ::<code><b>keep_viewmode</b></code> which will draw the inventory view if the renderer is invoked from an inventory (DSB v0.76+) | ||
+ | |||
+ | :The full-screen renderer will run until any of its associated functions returns something other than false or nil, and the game logic does not advance while in <b>dsb_fullscreen</b>. | ||
+ | |||
+ | ==Subrenderers and System Renderers== | ||
;<b>dsb_subrenderer_target</b>() = bitmap | ;<b>dsb_subrenderer_target</b>() = bitmap | ||
:Returns a bitmap to be drawn upon. Use only in a [[DSB/Subrenderers|Subrenderer]]. | :Returns a bitmap to be drawn upon. Use only in a [[DSB/Subrenderers|Subrenderer]]. | ||
;<b>dsb_objzone</b>(bitmap, id, number, x, y) | ;<b>dsb_objzone</b>(bitmap, id, number, x, y) | ||
− | :Creates an object zone associated with the given id at the given x and y coordinates on the given subrenderer bitmap. This object zone can be used to access instances that are stored inside of the given instance. See the implementation of chests in <i>base/objects.lua</i> for more information and examples. | + | :Creates an object zone associated with the given id at the given x and y coordinates on the given subrenderer or system bitmap. This object zone can be used to access instances that are stored inside of the given instance. See the implementation of chests in <i>base/objects.lua</i> for more information and examples. |
− | ;<b>dsb_msgzone</b>(bitmap, id, number, x, y, width, height, msg) | + | ;<b>dsb_msgzone</b>(bitmap, id, number, x, y, width, height, msg, ~[data1, data2]) |
− | :Creates an object zone associated with the given id at the given x and y coordinates on the given subrenderer bitmap, with the given width and height. When it is clicked, the specified message will be sent to the instance. This can allow fairly complicated user interfaces in subrenderers. | + | :Creates an object zone associated with the given id at the given x and y coordinates on the given subrenderer or system bitmap, with the given width and height. When it is clicked, the specified message will be sent to the instance. This can allow fairly complicated user interfaces in subrenderers. |
− | + | :The third parameter, number, allows you to override/replace zones by specifying an existing handle. It also allows msgzones to have more information about where you clicked, because the zone number you clicked is passed as the msg's data parameter. If you don't care about any of this, just keep incrementing the number for every new zone. (See [[DSB/Messages]] for more information on how to use messages) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Global Data, Utility Functions, and Misc.== | ==Global Data, Utility Functions, and Misc.== | ||
;<b>dsb_get_gameflag</b>(flag) = value | ;<b>dsb_get_gameflag</b>(flag) = value | ||
− | <b>dsb_set_gameflag</b>(flag) | + | ;<b>dsb_set_gameflag</b>(flag) |
− | <b>dsb_clear_gameflag</b>(flag) | + | ;<b>dsb_clear_gameflag</b>(flag) |
− | <b>dsb_toggle_gameflag</b>(flag) | + | ;<b>dsb_toggle_gameflag</b>(flag) |
:Gets, sets, clears, or toggles the value of a [[DSB/Global Flags|Global Flag]]. | :Gets, sets, clears, or toggles the value of a [[DSB/Global Flags|Global Flag]]. | ||
− | ;<b>dsb_hide_mouse</b>() | + | ;<b>dsb_hide_mouse</b>(~[bool]) |
− | <b>dsb_show_mouse</b>() | + | ;<b>dsb_show_mouse</b>() |
− | :Functions to make the mouse pointer appear or disappear. | + | :Functions to make the mouse pointer appear or disappear. <i>dsb_hide_mouse</i> Takes an optional parameter of true to allow the pointer to return after a successful melee attack, after moving the mouse. |
+ | ;dsb_mouse_state() = x, y, button1, button2 | ||
+ | :Gets the current state of the mouse: its current x,y position relative to the entire game screen, and '''true''' or '''false''' for button1 or button2 currently being pressed (left mouse button and right mouse button respectively). | ||
+ | |||
+ | ;dsb_mouse_override(bmp) | ||
+ | :Overrides the current mouse cursor image with a new image. Pass '''nil''' or '''false''' to cancel the override. | ||
;<b>dsb_lock_game</b>(~[flag]) | ;<b>dsb_lock_game</b>(~[flag]) | ||
− | <b>dsb_unlock_game</b>(~[flag]) | + | ;<b>dsb_unlock_game</b>(~[flag]) |
:Functions to lock or unlock the game. Complete locking prevents most timers from running (though animations and delayed functions still will), processing any player input, or triggering anything. If you lock the game and forget to unlock it, it will be left in an unplayable state, so be very careful how you use this! Note that this takes effect immediately (that is, even before any queued moves), which may not always be what you want. You can also lock only certain parts of the game, using the [[DSB/Locking Flags|locking flags]]. | :Functions to lock or unlock the game. Complete locking prevents most timers from running (though animations and delayed functions still will), processing any player input, or triggering anything. If you lock the game and forget to unlock it, it will be left in an unplayable state, so be very careful how you use this! Note that this takes effect immediately (that is, even before any queued moves), which may not always be what you want. You can also lock only certain parts of the game, using the [[DSB/Locking Flags|locking flags]]. | ||
;<b>dsb_rand</b>(min, max) = integer | ;<b>dsb_rand</b>(min, max) = integer | ||
:Generates a random integer between min and max, inclusive. | :Generates a random integer between min and max, inclusive. | ||
− | You should <b>always</b> use this function for random number generation, not anything built into Lua. | + | :You should <b>always</b> use this function for random number generation, not anything built into Lua. |
+ | :While larger ranges will not cause errors per-se, the output of dsb_rand seems to be a 15 bit range (0-32767) modulused across the input range | ||
;<b>dsb_linesplit</b>(string, split) = lines, number_of_lines | ;<b>dsb_linesplit</b>(string, split) = lines, number_of_lines | ||
Line 520: | Line 614: | ||
;<b>dsb_rune_disable</b>(rune) <font color="red">(Deprecated)</font> | ;<b>dsb_rune_disable</b>(rune) <font color="red">(Deprecated)</font> | ||
:Enables or disables the specified magical rune for use in spells. All runes are enabled by default, just like in original DM. The rune is specified as an integer, where 1 = LO, 2 = UM, 7 = YA, and so on. | :Enables or disables the specified magical rune for use in spells. All runes are enabled by default, just like in original DM. The rune is specified as an integer, where 1 = LO, 2 = UM, 7 = YA, and so on. | ||
− | + | :These functions are now deprecated. You should manipulate the <b>g_disabled_runes</b> table directly. For example, disabling the VI rune (rune 8) is as simple as <code>g_disabled_runes[8] = false</code>. | |
− | These functions are now deprecated. You should manipulate the <b>g_disabled_runes</b> table directly. For example, disabling the VI rune (rune 8) is as simple as <code>g_disabled_runes | ||
;<b>dsb_game_end</b>(~[bool]) | ;<b>dsb_game_end</b>(~[bool]) | ||
:Shows a game ending screen. Normally it's a bit more fun than the screen you get when the party dies, but if you pass it a boolean 'true', it will just show the standard blue "The End" screen. | :Shows a game ending screen. Normally it's a bit more fun than the screen you get when the party dies, but if you pass it a boolean 'true', it will just show the standard blue "The End" screen. | ||
+ | |||
+ | ;<b>clone_arch</b>(object_arch) = new arch | ||
+ | :This function creates a new arch type, from the original passed in as a parameter. See a simple [http://www.dungeon-master.com/forum/viewtopic.php?f=53&t=28613&p=111165#p111165 example]. | ||
+ | |||
+ | ;<b>dsb_import_arch</b>(lua_filename,local_name)<font color="#999"> = none?</font> | ||
+ | :Loads and runs a named lua file relative to the dungeon's directory. The file is loaded with the ROOT_NAME variable set to the given local name, so that the code being loaded can use that to avoid interfering with the parent codebase. Can only be used from the objects.lua file. Several examples are found in the test_dungeon. [http://dungeon-master.com/forum/viewtopic.php?f=53&t=27277&p=83877&hilit=dsb_import_arch#p83877 Some][http://dungeon-master.com/forum/viewtopic.php?f=53&t=29188&p=128330&hilit=dsb_import_arch#p128330 more][http://dungeon-master.com/forum/viewtopic.php?f=53&t=28859&sid=c8dec8095c76d7ce5937980e94499ceb&p=130029#p130029 info] | ||
+ | |||
+ | ;dsb_include_file(shortname, filetype, filename) | ||
+ | :When compiling a DSB dungeon for distribution, most sounds and graphics are automatically compiled into a new '''graphics.dsb'''. Music however is normally left as a file to be streamed on-demand from the filesystem. This lowers the memory required by DSB and speeds up loading time. However, if you prefer, you can force music (and other files) to be included in the '''graphics.dsb''' by using this command. For example: '''dsb_include_file("MYMUSIC", "ogg", "mypath/mymusic.ogg")'''. | ||
==Pending Documentation== | ==Pending Documentation== | ||
;<b>dsb_override_floor</b>(???) = ??? | ;<b>dsb_override_floor</b>(???) = ??? | ||
;<b>dsb_override_roof</b>(???) = ??? | ;<b>dsb_override_roof</b>(???) = ??? | ||
− | |||
− | |||
− | |||
− | |||
;<b>dsb_cache_invalidate</b>(???) = ??? | ;<b>dsb_cache_invalidate</b>(???) = ??? | ||
;<b>dsb_tileptr_exch</b>(???) = ??? | ;<b>dsb_tileptr_exch</b>(???) = ??? | ||
− | |||
;<b>dsb_party_viewing</b>(???) = ??? | ;<b>dsb_party_viewing</b>(???) = ??? | ||
;<b>dsb_party_affecting</b>(???) = ??? | ;<b>dsb_party_affecting</b>(???) = ??? | ||
Line 545: | Line 642: | ||
;<b>dsb_wallset_flip_floor</b>(???) = ??? | ;<b>dsb_wallset_flip_floor</b>(???) = ??? | ||
;<b>dsb_wallset_flip_roof</b>(???) = ??? | ;<b>dsb_wallset_flip_roof</b>(???) = ??? | ||
− | |||
;<b>dsb_get_pendingspell</b>(???) = ??? | ;<b>dsb_get_pendingspell</b>(???) = ??? | ||
;<b>dsb_set_pendingspell</b>(???) = ??? | ;<b>dsb_set_pendingspell</b>(???) = ??? | ||
[[Category:DSB|Exposed functions]] | [[Category:DSB|Exposed functions]] |
Latest revision as of 12:51, 3 September 2024
Introduction
Functions are given in the form:
- function(arguments, ~[optional arguments]) = return value
- If the terminology doesn't make sense, check DSB/Basic DSB Terminology.
Functions without a dsb_ prefix are part of base/, not the core engine.
Iterators
- dsb_insts()
- This is an iterator used in Lua's for loops. To iterate over all instances of objects in a DSB dungeon, use something like:
for i in dsb_insts()
- dsb_in_obj(id)
- Another iterator; see above for usage. This one is used to iterate all over all instances that are inside the given instance.
Bitmaps and Drawing
- dsb_get_bitmap(name) = bitmap
- Searches the dungeon's directory for the bitmap, and then graphics.dsb, and finally the default graphics.dat. Returns a truecolor bitmap, but the bitmap can be 256 colors on disk to save space. Don't specify a file extension as DSB will figure it out.
- dsb_get_bitmap(name, relative_path) = bitmap
- Same as above but with subdirectories. Example: "path/to/actual/file.ext"
- dsb_get_mask_bitmap(name) = bitmap
- This function loads a bitmap that requires two distinct regions of transparency that are used at different times, such as see-through door decorations or magic windows. The region that is transparent when the image is first blitted is represented by color 0, whereas the region that is "see through" is in the usual magenta color. This requires a 256 color bitmap.
- dsb_new_bitmap(xsize, ysize) = bitmap
- Creates a brand new bitmap and returns a reference to it.
- dsb_destroy_bitmap(bitmap)
- Completely destroys a bitmap. Rarely needed, as Lua's garbage collector will automatically scoop up out-of-scope bitmaps. You should only invoke this by hand if you know for sure why you need it.
- dsb_clone_bitmap(bitmap) = bitmap
- Creates a "virtual bitmap" clone of the specified bitmap. It shares the same actual memory, but can have different offsets. This is useful if you, for example, have several wallitems for which you want to draw the same image on different parts of the wall.
- dsb_animate(bitmap, frames, frame_delay)
- Sets up a bitmap that is a series of frames for animation.
- dsb_bitmap_clear(bitmap, RGB)
- Clears a bitmap to the specified RGB value. An RGB is specified as a table of { R, G, B }.
- dsb_bitmap_blit(src_bmp, dest_bmp, x_src, y_src, x_dest, y_dest, width, height)
- dsb_bitmap_blit(src_bmp, dest_bmp, x_src, y_src, x_dest, y_dest, src_width, src_height, final_width, final_height)
- Blits one bitmap onto another.
- This function takes either 8 or 10 parameters. In the 10 parameter version, the last two parameters define the size of the final bitmap to be rendered. This allows you to scale bitmaps dynamically. There's no anti-aliasing, so this works best with simple pixel images.
- dsb_bitmap_draw(src_bmp, dest_bmp, x, y, flip)
- dsb_bitmap_draw(src_bmp, dest_bmp, x, y, src_width, src_height, final_width, final_height, flip)
- Draws the entire source bitmap on to the destination, taking any animation or offsets into account. Pass true to the last parameter to horizontally flip the bitmap. Pass only 5 parameters to draw a simple bitmap at x,y, or pass 9 parameters to scale the bitmap dynamically.
- dsb_bitmap_width(bitmap) = integer
- dsb_bitmap_height(bitmap) = integer
- Returns the dimension of the bitmap.
- dsb_bitmap_rect(bitmap, x_src, y_src, x_dest, y_dest, color, filled)
- Draws a rectangle. Pass true to filled for a filled rectangle.
- dsb_bitmap_textout(bitmap, font, string, x, y, alignment, color) = integer
- Renders text onto a bitmap in the specified font and color, with the specified alignment: (LEFT, RIGHT, CENTER, or MULTILINE). Returns the number of lines printed. If you use the MULTILINE version, call dsb_textformat() first to set the line length and height. The textformat settings are global so if you don't know what code may run between the dsb_textformat call and the dsb_bitmap_textout call, then you don't really know what format it will draw in.
- dsb_dungeon_view(lev, x, y, dir, light) = bitmap
- Return a rendering of the viewport.
- dsb_viewport_distort(effect)
- For viewport postprocessing
- dsb_get_pixel(bmp, x, y) = {R,G,B},[alpha]
- dsb_set_pixel(bmp, x, y, {R,G,B}, [alpha])
- These are used for per-pixel bitmap manipulation.
- If the pixel queried with dsb_get_pixel() has an alpha channel, then the function returns two values: the {R,G,B} table, and an extra parameter containing the alpha. If there is no alpha, this second one will be nil.
- Alpha values for both dsb_get_pixel() and dsb_set_pixel() are in the range 0-255, where 0 is fully transparent and 255 is fully opaque.
- Here is a short example of how you might use these function to tint a bitmap:
- http://dungeon-master.com/forum/viewtopic.php?f=53&t=28859&p=135634#p135634
- dsb_rgb_to_hsv({R,G,B}) = {H,S,V}
- dsb_hsv_to_rgb({H,S,V}) = {R,G,B}
- Converts color model.
- dsb_screen_bitmap() = bitmap
- Takes a screenshot of the entire Windows screen and assigns it to a bitmap you can use later. If you're running the game in fullscreen mode, this will allow you to screenshot the entire game window. If you're running in Windowed mode, this will screenshot your visible Windows screen from the top/left 0,0 coordinate (probably not very useful in your dungeon!)
Fonts and Text
- dsb_get_font(name, relative_path) = font
- Searches the same paths as dsb_get_bitmap, loading a font. Example with a subdirectory:
gfx["GAUDYMEDIEVALFONT"] = dsb_get_font("GAUDYMEDIEVAL", "fonts/gaudymedieval.pcx")
- dsb_textformat(chars_per_line, y_offset_per_line, max_lines)
- This controls the format of MULTILINE text output by dsb_bitmap_textout. The Y offsets are also used by the console (the text below the game view). By setting chars_per_line to something unreasonable, you can effectively disable word wrapping.
- dsb_write(RGB, string)
- Outputs the given text string in the given color to the console. (that is, a table of { R, G, B })
dsb_text_size(font, string) = width, height [DSB 0.54+]
- Returns the width and height in pixels of the supplied string for the specified font.
Sound and Music
- dsb_get_sound(name) = sound
- Searches the same paths as dsb_get_bitmap, loading a sound.
- dsb_sound(sound, ~[loop]) = chan_handle
- Plays the given sound. An optional boolean parameter allows you to specify if the sound should loop. Be careful, the only way to stop a looping sound is via dsb_stopsound, so don't lose the channel handle!
- dsb_music(sound, ~[loop]) = chan_handle
- Plays a sound file directly from disk instead of loading into memory first. This function only works with direct filenames, you can't send it a full path -- so your music file must be in the root of your dungeon directoy. If you use dsb_music, it will at least load it on demand and destroy it when it's finished, so your memory usage will be lower than if you loaded it directly as a sound.
- dsb_3dsound(sound, lev, x, y, ~[loop]) = chan_handle
- Plays the given sound as though it originated from the given location in the dungeon. An optional boolean parameter allows you to specify if the sound should loop. Note that base/util.lua also includes a useful function, explained next:
- local_sound(id, sound) = chan_handle
- Plays a sound that appears to originate from the location of a given instance.
- dsb_music_to_background(?) = ?
- Allows multiple music streams.
- dsb_stopsound(chan_handle)
- Stops the sound playing on a channel handle previously returned by a call to a sound playing function. As of DSB 0.70, passing a channel handle of -1 will stop all currently playing sounds (and release their handles).
- dsb_get_soundvol(chan_handle)
- Obtains the current volume of the sound, ranging from 0 to 100.
- dsb_set_soundvol(chan_handle, volume)
- Adjusts the volume of the sound, with the volume range from 0 to 100.
Levels and Wallsets
dsb_bottomlevel() DSB 0.71+
- Returns the deepest level of the dungeon, counting from 0 -- so a 10 level dungeon will return 9.
- dsb_level_getinfo(level) = x_size, y_size, light, xp_multiplier, wallset_name
- Returns the basic info about a level.
- dsb_level_tint(level, RGB, ~[level])
- Tells DSB to tint the dynamically scaled and shaded objects in a level a certain way. By default, this is {0, 0, 0}, causing the dungeon to fade to black, just like DM, but if the ambient light color is different, or you are outdoors and fade to a misty grey instead of black, you will probably want to change this. The third parameter is to control the level of tint applied. The default is 64 but a value of over 200 or so will make everything so dark you can't see anything.
- dsb_make_wallset(floor, roof, pers0, pers0alt, pers1, pers1alt, pers2, pers2alt, pers3, persl3alt, farwall3, farwall3alt, front1, front2, front3, patch1, patch2, patch3, patchside, window) = wallset
- Creates a wallset from the specified bitmaps. Wallsets in DM 2.x ([CSBwin]) are easiest to use with this command, as they have a single very long wall, as opposed to assembling the front view out of "left" and "front" bitmaps. (see the next command)
- dsb_make_wallset_ext(floor, roof, pers0, pers0alt, pers1, pers1alt, pers2, pers2alt, pers3, persl3alt, farwall3, farwall3alt, front1, front2, front3, left1, left1alt, left2, left2alt, left3, left3alt, patch1, patch2, patch3, patchside, window) = wallset
- Creates a wallset from the specified bitmaps. This command takes 6 more arguments: 6 "left side" bitmaps. If you're using a converted DM2, DSB for RTC users, or WHACK wallset, you'll find this command useful. From DSB 0.70 onwards, the window bitmap can be a table containing two different bitmaps: one for the hole part, and one for the magic glow, eg: {gfx.default_window_hole, gfx.window_glow_wall}
- dsb_level_wallset(level, wallset)
dsb_use_wallset(level, wallset) (Deprecated)
- Tells DSB to use the specified wallset on the specified level.
Note: this function was formerly known as "dsb_use_wallset," and that is still a synonym for it, for now. In new dungeons, please use the new name.
- dsb_alt_wallset(wallset, level, x, y, dir)
- Tells DSB to use the specified wallset only on the given direction of the given tile. If CENTER is specified, it will use that wallset on all directions of the given tile.
- dsb_get_alt_wallset(level, x, y, dir)
- Return the wallset at the given direction of the given tile. Use in conjunction with the Wall Graphics mode in ESB where you can paint alternate wallsets on individual faces of individual tiles.
- dsb_wallset_flip_floor(wallset, flip)
- Pass true to flip to automatically flip the floor every other step, like standard floors, or pass a bitmap to have a different bitmap show up when the floor is "flipped."
- dsb_wallset_flip_roof(wallset, flip)
- Pass true to flip to automatically flip the roof every other step, like standard floors, or pass a bitmap to have a different bitmap show up when the roof is "flipped."
- dsb_override_floor(bitmap_name, flip)
- Overrides the floor with the bitmap in the gfx table with the given name, regardless of what wallset is in use. Pass true to flip to automatically flip the floor every other step, like standard floors, or pass a second bitmap name to have a different bitmap show up when the floor is "flipped."
- dsb_override_roof(bitmap_name, flip)
- Overrides the roof with the bitmap in the gfx table with the given name, regardless of what wallset is in use. Pass true to flip to automatically flip the roof every other step, like standard roofs, or pass a second bitmap name to have a different bitmap show up when the roof is "flipped."
- dsb_text2map(level, x_size, y_size, light, xp_multiplier, maptable)
- Converts a table with a text-based map into a level. Each row of the table should represent a row of the dungeon, and contain a string with 0's or 1's representing walls and floors in that row. In this way, it is very similar to how dungeons are declared in an DSB for RTC users text file.
- dsb_image2map(level, filename, light, xp_multiplier) (Deprecated)
- Converts a bitmap image into a level. One pixel = one square. It must be a 256 color image, where color 0 represents walls, color 1 represents open space, and further colors can be used to represent various objects in the dungeon by means of a conversion table. This function is now mostly deprecated because everyone is using ESB anyway.
- dsb_get_cell(level, x, y) = boolean
- Returns a boolean specifying whether or not the given cell in the dungeon is a wall. Use dsb_fetch to find out anything else about what's there. Note that an out of bounds cell is not considered a wall.
- dsb_set_cell(level, x, y, value)
- Sets whether the given cell in the dungeon is a wall or open space. A value of nil, false, or 0 represents open space. A value of true or any other integer represents a wall.
- dsb_visited(level, x, y) = boolean
- Returns whether the party has visited the given dungeon cell. A wall will never be visited, unless it wasn't a wall at some point in the past.
- dsb_get_xp_multiplier(level) = integer
dsb_set_xp_multiplier(level, integer)
- Gets or sets the XP multiplier for a given level of the dungeon.
Characters
- dsb_add_champion(portrait_gfxname, first_name, last_name, health, stamina, mana, strength, dexterity, wisdom, vitality, anti-magic, anti-fire, luck, fighter_level, ninja_level, priest_level, wizard_level) = char_id
- Adds a character to the roster and returns his/her id number, which can then be used for adjusting various stats or putting items in his/her pack. Note that the internal representations of the three bars and the 7 statistics are 10 times what is actually displayed. (That is, 100 health in-game is represented by 1000)
- dsb_offer_champion(char_id, mode, take_function)
- Offers the given char_id, with the options specified by "mode" available.
- ~[1 = resurrect, 2 = reincarnate, 3 = both]. The take_function is a Lua function that is executed if the offered character is resurrected or reincarnated. It is typically used to clear out the champion's mirror, or do something else to denote that the character is no longer available.
- dsb_champion_toparty(ppos, char)
- Adds the specified character at the specified party position. (Unlike dsb_offer_champion the player is given no choice, the character is just added) It will fail silently if that position is already occupied.
- dsb_champion_fromparty(ppos)
- Removes anyone at the specified party position. It will fail silently if no one is there. If the party is reduced to nothing, the game will revert to "ghost mode."
- dsb_get_charname(char) = string
- Returns the character's name.
- dsb_get_chartitle(char) = string
- Returns the character's lastname or title.
- dsb_get_bar(char, bar) = integer
dsb_set_bar(char, bar, integer)
- Gets or sets the value of one of the character's three bars. (HEALTH, STAMINA or MANA)
- dsb_get_stat(char, stat) = integer
dsb_set_stat(char, stat, integer)
- Gets or sets the value of one of the character's stats. (STAT_STR, STAT_DEX, STAT_WIS, STAT_VIT, STAT_AMA, STAT_AFI, STAT_LUC)
- dsb_get_maxbar(char, bar) = integer
dsb_set_maxbar(char, bar, integer) dsb_get_maxstat(char, stat) = integer dsb_set_maxstat(char, stat, integer)
- As above, only pertaining to maximum values.
- do_damage(ppos, char, type, amount)
- This function will damage the given character at the given ppos the given amount of the given type (HEALTH, STAMINA, or MANA). The units specified here are as the player perceives them (that is, divided by ten from internal representations and the same scale used by monsters)
- Defined in base/damage.lua.
- dsb_get_load(char) = integer
dsb_get_maxload(char) = integer
- Returns the load or max load of a given character.
- dsb_get_food(char) = integer
dsb_set_food(char, integer) dsb_get_water(char) = integer dsb_set_water(char, integer)
- Get or set the character's food and water values.
- dsb_get_injury(char, location) = integer
dsb_set_injury(char, location, integer)
- Gets or sets the amount of injury a given location on the given character has sustained. This number is 0 if the location is uninjured and can go up to 100, but anything nonzero will highlight it in red and use the "bandaged" bitmap.
- dsb_replace_portrait(char, portrait_name)
- Replaces the portrait of a character with the given image. This can happen on-the-fly at any time. Note that the portrait must be specified as a string, not an entry in the gfx table. That is, pass "portrait", not gfx.portrait.
- dsb_get_portraitname(char) = portrait_name
- Retrieves the name of a character's portrait.
- dsb_set_portraitname(char, portrait_name)
- An alias for dsb_replace_portrait (for symmetry).
- dsb_replace_topimages(char, hands_image_name, portrait_background_image_name, death_image_name)
- Replaces the top "hands", "portrait background" and "death" images. Pass the image names nil to leave the image alone, or 0 to go back to the default. Remember that we pass the image parameters as strings, and not a direct reference to the gfx table. Example: dsb_replace_topimages(char, nil, nil, "frozen_face_halk")
- dsb_replace_charhand(char, hand_name)
- Replaces the "hand" of a character with the given image. This can happen on-the-fly at any time. Note that the image must be specified as a string, not an entry in the gfx table. That is, pass "hand_image", not gfx.hand_image.
- dsb_replace_inventory(char, inventory_image_name)
- Replaces the inventory background of a character with the given image. This can happen on-the-fly at any time. Note that the background image must be specified as a string, not an entry in the gfx table. That is, pass "inventory", not gfx.inventory.
- dsb_replace_methods(char, methods_table_name)
- Replaces the default attack methods of a character with the given table of methods, or function returning a table. This can happen on-the-fly at any time. Note that the method table or function must be specified by name as a string, not as an actual table. It must a single global variable (not be contained in any other table).
- dsb_xp_level(char, skill, subskill) = integer
dsb_xp_level_nobonus(char, skill, subskill) = integer
- These functions return the character's level of mastery at a certain skill (a class such as 'ninja') and subskill (or 0 for no subskill). The "nobonus" form does not take temporary XP or level-boosting items into account. All references to the dsb_xp_level call are wrapped by function determine_xp_level(char, class, subskill) so that it can be overridden.
- dsb_give_xp(char, skill, subskill, xp)
- Gives the specified amount of XP in the specified skill and subskill (or 0 for no subskill).
- Important: This function gives XP only. It doesn't deal with XP multipliers, leveling up, bonuses, or anything else.
- More useful to most designers will be the helper function xp_up.
- xp_up(char, skill, subskill, xp)
- This function takes XP multipliers, leveling up, etc. into account.
- Defined in base/xp.lua.
- dsb_get_xp(char, skill, subskill) = xp
dsb_set_xp(char, skill, subskill, xp)
- Gets or sets the character's amount of experience directly. Setting XP directly doesn't do anything with stats, leveling up or down, or anything of that sort, so it is of limited use unless you really know what you're doing.
- dsb_get_temp_xp(char, skill, subskill) = xp
dsb_set_temp_xp(char, skill, subskill, xp)
- Gets or sets a temporary XP bonus. This, too, is handled by xp_up automatically.
- dsb_get_bonus(char, skill, subskill) = integer
dsb_set_bonus(char, skill, subskill, integer)
- Gets or sets a level bonus associated with a given skill or subskill (or 0 for no subskill), such as what may be given by a magic item held in hand or worn around the neck.
The Party
Many of these commands include optional support for Multiple Parties. In a standard DM dungeon, you can ignore all of that.
- dsb_party_coords(~[party]) = level, x, y, facing
- Returns the ~[specified] party's location.
- dsb_party_at(level, x, y) = party
- Returns which party is at a specified location, or nil if no party is there.
- dsb_party_place(level, x, y, facing, ~[party])
- Places the ~[specified] party at a specific location.
- dsb_get_pfacing(ppos) = direction
dsb_set_pfacing(ppos, direction)
- Get or set the direction a given party position is facing relative to the rest of the party. (This changes when the members are attacked from monsters to the sides or behind)
- dsb_get_idle(ppos) = integer
dsb_set_idle(ppos, integer)
- Gets or sets the amount of time the given party position must be idle (that is, the attack method icons are ghosted). Note that these take party positions, not character numbers.
- dsb_get_leader() = ppos
- Returns the party position of the party's leader.
- dsb_ppos_char(ppos, ~[party]) = char
- Returns the character at the given party position, or nil if there isn't one.
If a party is specified, that party will be searched. If there is no party specified, only the current party will be searched. To search all parties, specify VARIABLE as the party.
- dsb_char_ppos(char) = ppos
- Returns the party position a given character occupies, or nil if he/she isn't in the party.
- dsb_ppos_tile(ppos, ~[party]) = tile_dir
- Returns the tile location that the given party position occupies.
A specific party can be optionally specified.
- dsb_tile_ppos(tile_dir, ~[party]) = ppos
- Returns the party position occupied by the given tile location, or nil if nobody is there.
A specific party can be optionally specified.
- dsb_get_sleepstate() = boolean
- Returns whether or not the party is asleep.
- dsb_wakeup()
- Wakes up the party if they are asleep.
- dsb_current_inventory>() = ppos
- If someone's inventory is being looked at, this returns the party position of the character that is being looked at. Otherwise, it returns nil.
- dsb_lastmethod(ppos) = method, location, inst
- Returns the last attack method invoked by the given ppos.
- dsb_party_scanfor(arch) = id
- Scans the entire party's inventory for a given arch. Returns the id for the first instance of that arch if it is found, or nil if nothing is found.
- dsb_get_caster() = ppos
- Returns the current spell caster.
Multiple Parties
dsb_get_mpartyflag(flag) = value dsb_set_mpartyflag(flag) dsb_clear_mpartyflag(flag) dsb_toggle_mpartyflag(flag)
- Gets, sets, clears, or toggles the value of a Multiple Parties flag.
dsb_set_exviewinst(char, monster_id)
- This will associate a given monster inst with a character. The monster must be in LIMBO. From then on, whenever that character is seen from a 3rd person perspective, that monster will be drawn to represent that character. Don't kill this monster or bad things will happen.
dsb_party_apush(party) dsb_party_apop(party)
- The game uses a "party stack" to keep track of which sub-party the various party-related commands affect. The currently viewed party is always at the bottom. When a party steps on a trigger, it is pushed onto the stack before the trigger is processed. This means things like dsb_party_coords will generally affect the "right" party. You can directly manipulate the stack with these commands, but be careful. If you're not sure what to do with these commands, you probably don't need them.
dsb_party_contains(ppos) = party_id
- Returns the party containing a given character ppos
Interacting with Insts
- dsb_spawn(object_arch, level, x, y, tile_location) = id
- Spawns a new instance at the specified coordinates and returns its id.
Note that if "level" is negative, various Special Values can be used.
The ID will be a value between 1 and 32767. If there are more than 32767 insts at a time then the system will crash. Insts that are removed from the dungeon will free up IDs for new insts. Since inst IDs can be thus recycled, it may not always be safe to assume a stored ID will always point to inst it started as.
- dsb_move(id, level, x, y, tile_location)
- Moves an instance to the specified location. The Special Values can also be used.
- dsb_reposition(id, tile_location)
- Moves an instance to a new tile location on the same tile. Useful for rearranging monsters.
Note: dsb_spawn etc. will not always immediately put the spawned/moved object into position. During the processing of a triggering event (wallitem or flooritem), all spawns and moves will be queued until the end of the processing in order to avoid changing the dungeon state while the triggering objects are still being iterated over. In most cases, the change will not be noticable, but you should be wary of this fact, especially if you are expecting to be able to manipulate the just-moved object in the same function.
- dsb_move_moncol(???) = ???
Allow moving a monster and automatically handle flyer collisions.
- dsb_get_coords(id) = level, x, y, tile_location
- Returns the coordinates of an instance. This is either the location in the dungeon, or, using special coordinates, its location in a character or monster's inventory, in limbo, etc.
- dsb_get_coords_prev(id) = level, x, y, tile_location
- Returns the object's coordinates before its most recent movement.
- dsb_fetch(level, x, y, tile_location) = id (or table of ids), ~[number]
- Checks a specified location and returns what's there. If this is a special coordinate, it is either nil or just an id number. If this is a dungeon location (that is, a level >= 0) or if the special specifier TABLE is used for tile_location, it will return a table of ids. -1 can also be used for the y coordinate when using a special coordinate to return a table of all matching ids, for example, IN_OBJ will give everything inside that object. In these cases, a number is also returned matching the number of instances fetched (but can be ignored if you choose)
- dsb_find_arch(id) = arch
- Determines the arch of the given instance id. This is often needed in order to access information about the object's general type.
- dsb_swap(id, new_arch)
- Totally destroys the targeted instance and creates a new one at its location with its id number and the new archetype. Things like exvars are not preserved.
- dsb_qswap(id, new_arch)
- Quick-swaps an instance to a new archetype. That is, it changes only the arch, but no internal variables or exvars. This means that if the new arch is a radically different type, strange things will probably happen and the game might crash. It's quite handy for making push-buttons that change appearance and such, though.
- dsb_delete(id)
- Completely destroys an instance from the dungeon.
In most cases, it is better to send the instance an M_DESTROY message instead.
- dsb_get_facedir(id) = direction
dsb_set_facedir(id, direction)
- Gets or sets the direction a monster is facing or a flying instance is currently travelling.
- dsb_shoot(id, level, x, y, direction, tile_pos, power, damage, delta, ~[damage_delta])
- Sends the specified instance flying through the air. It originates at the given level, x, y, and tile_pos, flying in the given direction. Power and damage are variables used by the game to control how far the object flies and how hard it hits. Delta represents how much is subtracted from power each subtile of flight. Delta is also subtracted from damage, unless an optional damage delta is specified instead. When the instance runs out of power, it falls to the ground (or vanishes if flying_only is set on its archetype)
- dsb_get_flystate(id) = power, direction, damage
- Returns the information on a flying instance.
- dsb_set_openshot(id)
- This is a minor hack used to specify that the instance has been shot in open space (by a champion or monster, instead of by a wall shooter, for example) and thus should not have collision detection immediately. If this is not set, the instance will instantly run into the character or monster that was supposed to have "launched" it.
- dsb_collide(id, lev, x, y, tile, direction) = { {id, tile}, ~[...] }
- Performs collision detection on a flying object for the specified location. This is useful when directly moving monsters around (e.g., via dsb_move) so that they will not apparently move "through" flying missiles.
- dsb_set_flyreps(id, repetitions)
- Allows you to set the number of update repetitions (default value is 1) that a flying object performs per tick. For example, a value of 8 will cause the id flying object to move 8 sub-tiles per tick, or 4 full tiles.
- dsb_get_gfxflag(id, flag) = value
dsb_set_gfxflag(id, flag) dsb_clear_gfxflag(id, flag) dsb_toggle_gfxflag(id, flag)
- Gets, sets, clears, or toggles the value of a Graphics Flag for a given instance.
- dsb_get_charge(id) = integer
dsb_set_charge(id, integer)
- Gets or sets the charge of a given instance. This is normally used by limited-use items but it can have other applications. It is used to set the size of clouds and spells, too. It must be a number from 0 to 63.
- dsb_get_crop(id) = integer
dsb_set_crop(id, integer)
- Gets or sets how much a door is cropped in its display. This is used when they open and close.
- dsb_spawnburst_begin()
dsb_spawnburst_end()
- Begins or ends a Spawnburst.
- dsb_push_mouse(id)
- A shortcut command to push the specified instance into the mouse hand.
- dsb_pop_mouse() = id
- A shortcut command to pop anything in the mouse hand out, returning its id at the same time.
- dsb_valid_inst(id) = ternary value
- Returns true if the instance exists, false if it doesn't but the id is valid, and nil if it is not a valid instance id.
- clone_arch(base_arch, changes) = new arch
- Creates a new arch type. See a simple example.
- The new arch will be the original arch, but with changes applied from a list of key/value pairs
- Note that this cannot clear a key from the original arch - any removals would need to be applied manually to the new arch
Monsters
Monsters are insts as well, and (almost?) all commands that affect insts will work just the same on monsters, but monsters have their own specialized functionality as well.
- dsb_get_hp(id) = integer
dsb_set_hp(id, integer)
- Gets or sets a monster's HP. Please note that this function has nothing to do with how to get or set a character's HP. In addition, the scale used by monster HP is not scaled up by a factor of 10.
- dsb_get_maxhp(id) = integer
dsb_set_maxhp(id, integer)
- Gets or sets a monster's max HP.
- dsb_set_tint(id, RGB, ~[intensity])
- Sets the 'tint' of a monster, to give it a glowing effect. Monsters flash when they are hit by various spells. There is finally an optional intensity level parameter, set at 127 by default with a range of 0 to 255. 0 Being completely black.
- dsb_ai(id, message, data) ~[= result]
- Sends an Monster AI message to the given monster.
If data is QUERY then the function will return information on the given value, rather than setting it. For example, dsb_ai(id, AI_FEAR, QUERY) will return the monster's current level of fear. Monster AI documentation.
- dsb_ai_boss(id) = boss_id
- Returns the given monster id's boss. The "boss" is the monster in each tile who controls when the entire group moves and attacks. This allows DSB monsters to all be distinct entities, but move in DM-style groups.
- dsb_ai_promote(id)
- Promotes the given monster id to be the boss of its tile.
- dsb_ai_subordinates(boss_id) = { {id, tile}, [...] }
- Returns all monsters who are subordinate to the given boss.
Messaging
- dsb_msg(delay, id, message, data, ~[sender])
- Sends the specified Messages to the specified instance after the specified delay. Messages are simply integers. The object responds to the message as specified by its msg_handler, defined in its archetype. See base/msg_handlers.lua for many examples of what can be done with message handlers. Normally it doesn't matter where a message comes from. However, it is possible to assert the sender of the message, in the rare cases where it is needed. (See DSB/Messages for more information on how to use messages)
- dsb_msg_chain(id, target_id)
- This causes the first instance to relay any messages it receives to the second instance. This is useful for making ceiling pits close at the same time floor pits do, and other situations where an instance should pass messages along.
- dsb_delay_msgs_to(id, delay)
- Delays all messages bound for a given instance by the specified delay.
- dsb_enable(id)
- Enables an instance. This will clear its INACTIVE flag as well as make sure any events, triggerings, etc. that should happen do happen. This function is easier and safer to use than setting the flag directly.
- dsb_disable(id)
- Disables an instance. This will set its INACTIVE flag and make sure that any objects on it stop triggering it.
- dsb_toggle(id)
- See the previous two.
- dsb_add_msgtype(code_name,int_value) = none?
- Adds a new message type to the system. Values above 100000 are reserved for the base code.
- Custom msg types will presumably still be handled the same way the built in ones are, so may be useful for triggering events on custom archs.
- Hmm. This could get messy if you combine msgtypes with importable archs...
Light
- dsb_get_light(handle) = lightlevel
dsb_set_light(handle, lightlevel)
- Gets or sets the light level on the given light handle, which is an integer from 0 to 9. The light level displayed is the sum of the dungeon level's base light level plus the 10 light handles. Currently, light handle 0 is used for light spells, handle 1 is used for torches, and 2 is used by illumulets.
Conditions
- Conditions (i.e., status variables) are added to the game by modifying the conditions table, which is defined in base/conditions.lua. See that file for examples.
- The scope of the condition is either PARTY (affects the whole party) or INDIVIDUAL (affects one person). You can also specify images for the condition, like a subrenderer_image or a portrait_image. PARTY conditions can instead have an overlay_image that goes over the entire game's viewport.
- If update_rate is > 0, the specified update_func will be called at the specified number of ticks. The function takes the following form:
function update_func(char, condition_strength) return new_condition_strength end
- dsb_add_condition(type, inventory_gfx, portrait_gfx, update_freq, function, [flags]) = condition_id (Deprecated)
- Adds a condition (status variable) to the list of those available, but see above.
- dsb_replace_condition(condition_id, type, inventory_gfx, portrait_gfx, update_freq, function) (Deprecated)
- Replaces the information for the condition with the given id with the new condition.
- dsb_get_condition(char, condition) = strength
- Returns the strength of the specified condition for the specified character (or, in the case of conditions for the whole party, pass PARTY as the character)
- dsb_set_condition(char, condition, strength)
- Sets the strength of the condition. See previous function.
Popups and Readouts
- dsb_damage_popup(ppos, damage_type, integer)
- Shows the amount of damage taken by a character in a little popup over the character's name or portrait. The type is either HEALTH, STAMINA, or MANA, and a different background icon is displayed for each. The amount of damage shown should be in units as the player perceives them, not internal (so, divided by ten from internal representations)-- the default functions in base/damage.lua take care of this for you.
- dsb_attack_damage(integer)
- This causes a number in a little explosion to appear in the area occupied by the attack icons. This is used for showing the amount of damage inflicted upon a monster by a melee attack.
- dsb_attack_text(string)
- This causes text to momentarily appear in the area occupied by the attack icons. This is used for things like "CAN'T REACH" or "NEED AMMO."
Fullscreen
- dsb_fullscreen(bitmap_or_func, click_func, update_func, mouse, { fade = true, game_draw = true }) (DSB < v0.76)
- dsb_fullscreen(bitmap_or_func, click_func, update_func, mouse, { fade = true, game_draw = true, keep_viewmode = true }) (DSB v0.76+)
- This engages the full-screen renderer, and is used for cut scenes or other interludes. If the first parameter passed is a bitmap, that bitmap will be displayed. If the first parameter is instead a function, that function will be executed every frame. The draw function will be passed the bitmap to draw to, the mouse's x location, and the mouse's y location, in the form:
draw_function(bitmap, mouse_x, mouse_y)
- The click_func, if provided, will be executed every time the mouse is clicked. It is of the form:
click_func(mouse_x, mouse_y, mouse_buttons)
- Update_func, if provided, will be executed every game tick. It takes no parameters.
- If mouse is nil or false, no mouse pointer will be drawn. If it is true, the standard "yellow arrow" mouse pointer will be drawn. If it is a bitmap, that bitmap will be drawn as the mouse pointer.
- There is an optional 5th parameter (a table of booleans):
fade
will quickly fade the fullscreen bitmap in from a black screengame_draw
allows you to have the game view drawn in the background. So, for example, for a fullscreen view that fades in and draws the game view.keep_viewmode
which will draw the inventory view if the renderer is invoked from an inventory (DSB v0.76+)
- The full-screen renderer will run until any of its associated functions returns something other than false or nil, and the game logic does not advance while in dsb_fullscreen.
Subrenderers and System Renderers
- dsb_subrenderer_target() = bitmap
- Returns a bitmap to be drawn upon. Use only in a Subrenderer.
- dsb_objzone(bitmap, id, number, x, y)
- Creates an object zone associated with the given id at the given x and y coordinates on the given subrenderer or system bitmap. This object zone can be used to access instances that are stored inside of the given instance. See the implementation of chests in base/objects.lua for more information and examples.
- dsb_msgzone(bitmap, id, number, x, y, width, height, msg, ~[data1, data2])
- Creates an object zone associated with the given id at the given x and y coordinates on the given subrenderer or system bitmap, with the given width and height. When it is clicked, the specified message will be sent to the instance. This can allow fairly complicated user interfaces in subrenderers.
- The third parameter, number, allows you to override/replace zones by specifying an existing handle. It also allows msgzones to have more information about where you clicked, because the zone number you clicked is passed as the msg's data parameter. If you don't care about any of this, just keep incrementing the number for every new zone. (See DSB/Messages for more information on how to use messages)
Global Data, Utility Functions, and Misc.
- dsb_get_gameflag(flag) = value
- dsb_set_gameflag(flag)
- dsb_clear_gameflag(flag)
- dsb_toggle_gameflag(flag)
- Gets, sets, clears, or toggles the value of a Global Flag.
- dsb_hide_mouse(~[bool])
- dsb_show_mouse()
- Functions to make the mouse pointer appear or disappear. dsb_hide_mouse Takes an optional parameter of true to allow the pointer to return after a successful melee attack, after moving the mouse.
- dsb_mouse_state() = x, y, button1, button2
- Gets the current state of the mouse: its current x,y position relative to the entire game screen, and true or false for button1 or button2 currently being pressed (left mouse button and right mouse button respectively).
- dsb_mouse_override(bmp)
- Overrides the current mouse cursor image with a new image. Pass nil or false to cancel the override.
- dsb_lock_game(~[flag])
- dsb_unlock_game(~[flag])
- Functions to lock or unlock the game. Complete locking prevents most timers from running (though animations and delayed functions still will), processing any player input, or triggering anything. If you lock the game and forget to unlock it, it will be left in an unplayable state, so be very careful how you use this! Note that this takes effect immediately (that is, even before any queued moves), which may not always be what you want. You can also lock only certain parts of the game, using the locking flags.
- dsb_rand(min, max) = integer
- Generates a random integer between min and max, inclusive.
- You should always use this function for random number generation, not anything built into Lua.
- While larger ranges will not cause errors per-se, the output of dsb_rand seems to be a 15 bit range (0-32767) modulused across the input range
- dsb_linesplit(string, split) = lines, number_of_lines
- A utility function that splits up a string into individual lines (placing the number of lines returned in number_of_lines) demarcated by the split character. "/" (slash) is a common choice for a a split character. See the implementation of scrolls in base/objects.lua for an example.
- dsb_forward(direction) = x, y
- A utility function that, given a direction, returns the x and y offsets of which way is "forward." One will always be 1 or -1, the other will always be 0.
- dsb_tileshift(location, direction) = location
- A utility function that shifts the specified location in the specified direction. If you don't know what this is for, you probably don't need it.
- dsb_lookup_global(string) = variable
- Returns the variable named by the specified string. If you don't know what this is for, you probably don't need it.
- dsb_delay_func(delay, function)
- Executes the given function after the given delay in ticks. References to Lua functions cannot be saved, so queued functions will not be saved. This should be something nonvital if the game is not locked, and should happen quickly. In most cases, using a message on a delay, which is saved, would work better.
- dsb_update_inventory_info()
- If the inventory_info has been changed, this lets the engine know. Note that this state is not saved.
- dsb_update_system()
- If the system strings or player colors have been changed, this lets the engine know. This may or may not be useful. With the moving of most inventory rendering into Lua-controlled subrenderers, this function has limited use.
- dsb_export(string)
- Normally, Lua global variables aren't saved in savegames, however, a few usually need to be. If you need to store a global variable, add it to the export list with this function. Note that dsb_export requires a string giving the name of the variable. Don't pass the variable itself! You should also note that if you have a very long export list, you're probably doing something that could be done more easily with specialized code or more careful use of instances with exvars. If you don't know what this is for, you probably don't need it.
- dsb_viewport(x, y)
- Sets the viewport. Odds are you should leave this one alone.
- dsb_rune_enable(rune) (Deprecated)
- dsb_rune_disable(rune) (Deprecated)
- Enables or disables the specified magical rune for use in spells. All runes are enabled by default, just like in original DM. The rune is specified as an integer, where 1 = LO, 2 = UM, 7 = YA, and so on.
- These functions are now deprecated. You should manipulate the g_disabled_runes table directly. For example, disabling the VI rune (rune 8) is as simple as
g_disabled_runes[8] = false
.
- dsb_game_end(~[bool])
- Shows a game ending screen. Normally it's a bit more fun than the screen you get when the party dies, but if you pass it a boolean 'true', it will just show the standard blue "The End" screen.
- clone_arch(object_arch) = new arch
- This function creates a new arch type, from the original passed in as a parameter. See a simple example.
- dsb_import_arch(lua_filename,local_name) = none?
- Loads and runs a named lua file relative to the dungeon's directory. The file is loaded with the ROOT_NAME variable set to the given local name, so that the code being loaded can use that to avoid interfering with the parent codebase. Can only be used from the objects.lua file. Several examples are found in the test_dungeon. Somemoreinfo
- dsb_include_file(shortname, filetype, filename)
- When compiling a DSB dungeon for distribution, most sounds and graphics are automatically compiled into a new graphics.dsb. Music however is normally left as a file to be streamed on-demand from the filesystem. This lowers the memory required by DSB and speeds up loading time. However, if you prefer, you can force music (and other files) to be included in the graphics.dsb by using this command. For example: dsb_include_file("MYMUSIC", "ogg", "mypath/mymusic.ogg").
Pending Documentation
- dsb_override_floor(???) = ???
- dsb_override_roof(???) = ???
- dsb_cache_invalidate(???) = ???
- dsb_tileptr_exch(???) = ???
- dsb_party_viewing(???) = ???
- dsb_party_affecting(???) = ???
- dsb_checksound(???) = ???
- dsb_get_gamelocks(???) = ???
- dsb_get_light_total(???) = ???
- dsb_set_light_totalmax(???) = ???
- dsb_get_exviewinst(???) = ???
- dsb_wallset_flip_floor(???) = ???
- dsb_wallset_flip_roof(???) = ???
- dsb_get_pendingspell(???) = ???
- dsb_set_pendingspell(???) = ???