A rewrite of the node_ownership Minetest mod with many new features. https://content.minetest.net/packages/ShadowNinja/areas/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.0KB

  1. -- This is inspired by the landrush mod by Bremaweb
  2. local S = minetest.get_translator("areas")
  3. areas.hud = {}
  4. areas.hud.refresh = 0
  5. minetest.register_globalstep(function(dtime)
  6. areas.hud.refresh = areas.hud.refresh + dtime
  7. if areas.hud.refresh > areas.config["tick"] then
  8. areas.hud.refresh = 0
  9. else
  10. return
  11. end
  12. for _, player in pairs(minetest.get_connected_players()) do
  13. local name = player:get_player_name()
  14. local pos = vector.round(player:get_pos())
  15. pos = vector.apply(pos, function(p)
  16. return math.max(math.min(p, 2147483), -2147483)
  17. end)
  18. local areaStrings = {}
  19. for id, area in pairs(areas:getAreasAtPos(pos)) do
  20. local faction_info = area.faction_open and areas.factions_available and
  21. factions.get_player_faction(area.owner)
  22. area.faction_open = faction_info
  23. table.insert(areaStrings, ("%s [%u] (%s%s%s)")
  24. :format(area.name, id, area.owner,
  25. area.open and S(":open") or "",
  26. faction_info and ":"..faction_info or ""))
  27. end
  28. for i, area in pairs(areas:getExternalHudEntries(pos)) do
  29. local str = ""
  30. if area.name then str = area.name .. " " end
  31. if area.id then str = str.."["..area.id.."] " end
  32. if area.owner then str = str.."("..area.owner..")" end
  33. table.insert(areaStrings, str)
  34. end
  35. local areaString = S("Areas:")
  36. if #areaStrings > 0 then
  37. areaString = areaString.."\n"..
  38. table.concat(areaStrings, "\n")
  39. end
  40. local hud = areas.hud[name]
  41. if not hud then
  42. hud = {}
  43. areas.hud[name] = hud
  44. hud.areasId = player:hud_add({
  45. hud_elem_type = "text",
  46. name = "Areas",
  47. number = 0xFFFFFF,
  48. position = {x=0, y=1},
  49. offset = {x=8, y=-8},
  50. text = areaString,
  51. scale = {x=200, y=60},
  52. alignment = {x=1, y=-1},
  53. })
  54. hud.oldAreas = areaString
  55. return
  56. elseif hud.oldAreas ~= areaString then
  57. player:hud_change(hud.areasId, "text", areaString)
  58. hud.oldAreas = areaString
  59. end
  60. end
  61. end)
  62. minetest.register_on_leaveplayer(function(player)
  63. areas.hud[player:get_player_name()] = nil
  64. end)