diff options
author | Tai @ Flex <dch.tai@gmail.com> | 2016-11-26 07:20:23 +0000 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2016-12-19 16:36:37 +0000 |
commit | 6080ff065ea89e899f356ba723ea2467b6d32ccb (patch) | |
tree | 7cae444532994bafbb711f18e6b3af48fa3c4bcd /api.md | |
parent | 23f81f6278af2269bb11f41ec424936b05c2655f (diff) |
Add API for adding areas to HUD
Diffstat (limited to 'api.md')
-rw-r--r-- | api.md | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ +Areas mod API +=== + +API list +--- + + * `areas.registerHudHandler(handler)` - Registers a handler to add items to the Areas HUD. See [HUD](#hud). + + +HUD +--- + +If you are making a protection mod or a similar mod that adds invisible regions +to the world, and you would like then to show up in the areas HUD element, you +can register a callback to show your areas. + +HUD handler specification: + + * `handler(pos, list)` + * `pos` - The position to check. + * `list` - The list of area HUD elements, this should be modified in-place. + +The area list item is a table containing a list of tables with the following fields: + + * `id` - An identifier for the area. This should be a unique string in the format `mod:id`. + * `name` - The name of the area. + * `owner` - The player name of the region owner, if any. + +All of the fields are optional but at least one of them must be set. + +### Example + + local function areas_hud_handler(pos, areas) + local val = find_my_protection(pos) + + if val then + table.insert(areas, { + id = "mod:"..val.id, + name = val.name, + owner = val.owner, + }) + end + end + + areas:registerHudHandler(areas_hud_handler) |