diff options
author | ShadowNinja <noreply@gmail.com> | 2013-09-26 10:30:36 -0400 |
---|---|---|
committer | ShadowNinja <noreply@gmail.com> | 2013-09-26 10:30:36 -0400 |
commit | 0c20a1b616fb1bc72e6db9fad061b12ee044602a (patch) | |
tree | 6b249b66049ff045756ec850436f1ee7df6271ba | |
parent | 17b32663b76428f84937ab79fab38259e6a1a831 (diff) |
Show area owners on the hud (inspired by landrush)
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | chatcommands.lua | 23 | ||||
-rw-r--r-- | hud.lua | 38 | ||||
-rw-r--r-- | init.lua | 1 |
4 files changed, 39 insertions, 26 deletions
@@ -67,9 +67,6 @@ Chat commands For example: /find_areas [Cc]astle To find castles. - * /list\_owners - Lists the owners of your position. - * /remove\_area <ID> Removes a area that you own. Any sub-areas of that area are made sub-areas of the removed area's parent, if it exists. Otherwise they will have no diff --git a/chatcommands.lua b/chatcommands.lua index 341e70c..b1dcfd8 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -169,29 +169,6 @@ minetest.register_chatcommand("rename_area", { end}) -minetest.register_chatcommand("list_owners", { - params = "", - description = "List the owners of your position", - privs = {}, - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - minetest.chat_send_player(name, - "Unable to find your position.") - return - end - local pos = vector.round(player:getpos()) - local owners = areas:getNodeOwners(pos) - if #owners > 0 then - minetest.chat_send_player(name, - "Owners: "..table.concat(owners, ", ")) - else - minetest.chat_send_player(name, - "Your position is unowned.") - end -end}) - - minetest.register_chatcommand("find_areas", { params = "<regexp>", description = "Find areas using a Lua regular expression", @@ -0,0 +1,38 @@ +-- This is inspired by the landrush mod by Bremaweb + +areas.hud = {} + +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local pos = vector.round(player:getpos()) + local owners = areas:getNodeOwners(pos) + local ownerString = table.concat(owners, ", ") + if not areas.hud[name] then + areas.hud[name] = {} + areas.hud[name].ownersId = player:hud_add({ + hud_elem_type = "text", + name = "AreaOwners", + number = 0xFFFFFF, + position = {x=0, y=1}, + offset = {x=5, y=-40}, + direction = 0, + text = "Area owners: "..ownerString, + scale = {x=200, y=40}, + alignment = {x=1, y=1}, + }) + areas.hud[name].oldOwners = ownerString + return + end + if areas.hud[name].oldOwners ~= ownerString then + player:hud_change(areas.hud[name].ownersId, "text", + "Area owners: "..ownerString) + areas.hud[name].oldOwners = ownerString + end + end +end) + +minetest.register_on_leaveplayer(function(player) + areas.hud[player:get_player_name()] = nil +end) + @@ -14,6 +14,7 @@ dofile(areas.modpath.."/chatcommands.lua") dofile(areas.modpath.."/pos.lua") dofile(areas.modpath.."/interact.lua") dofile(areas.modpath.."/legacy.lua") +dofile(areas.modpath.."/hud.lua") areas:load() |