forked from mtcontrib/factions
Added HUD which displays name of faction whose land you're in
This commit is contained in:
parent
169076e8fe
commit
4d28033aa2
33
factions.lua
33
factions.lua
@ -24,17 +24,11 @@ factions.factions = {}
|
|||||||
factions.chunks = {}
|
factions.chunks = {}
|
||||||
factions.players = {}
|
factions.players = {}
|
||||||
|
|
||||||
factions.print = function(text)
|
|
||||||
print("factions: " .. dump(text))
|
|
||||||
end
|
|
||||||
|
|
||||||
factions.dbg_lvl1 = function() end --factions.print -- errors
|
|
||||||
factions.dbg_lvl2 = function() end --factions.print -- non cyclic trace
|
|
||||||
factions.dbg_lvl3 = function() end --factions.print -- cyclic trace
|
|
||||||
|
|
||||||
factions.factions = {}
|
factions.factions = {}
|
||||||
--- settings
|
--- settings
|
||||||
factions.lower_laimable_height = -512
|
factions.lower_laimable_height = -512
|
||||||
|
factions.power_per_chunk = 0.
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
||||||
@ -118,14 +112,14 @@ end
|
|||||||
function factions.Faction.claim_chunk(self, chunkpos)
|
function factions.Faction.claim_chunk(self, chunkpos)
|
||||||
factions.chunks[chunkpos] = self.name
|
factions.chunks[chunkpos] = self.name
|
||||||
self.land[chunkpos] = true
|
self.land[chunkpos] = true
|
||||||
self.decrease_power(factions.power_per_chunk)
|
self:decrease_power(factions.power_per_chunk)
|
||||||
self:on_claim_chunk(chunkpos)
|
self:on_claim_chunk(chunkpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
function factions.Faction.unclaim_chunk(self, chunkpos)
|
function factions.Faction.unclaim_chunk(self, chunkpos)
|
||||||
factions.chunks[chunkpos] = nil
|
factions.chunks[chunkpos] = nil
|
||||||
self.land[chunkpos] = nil
|
self.land[chunkpos] = nil
|
||||||
self.increase_power(factions.power_per_chunk)
|
self:increase_power(factions.power_per_chunk)
|
||||||
self:on_unclaim_chunk(chunkpos)
|
self:on_unclaim_chunk(chunkpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
@ -396,8 +390,29 @@ minetest.register_on_dieplayer(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
local lastUpdate = 0.
|
||||||
|
|
||||||
minetest.register_globalstep(
|
minetest.register_globalstep(
|
||||||
function(dtime)
|
function(dtime)
|
||||||
|
lastUpdate = lastUpdate + dtime
|
||||||
|
if lastUpdate > .5 then
|
||||||
|
local playerslist = minetest.get_connected_players()
|
||||||
|
for i in pairs(playerslist) do
|
||||||
|
local player = playerslist[i]
|
||||||
|
local chunkpos = factions.get_chunk_pos(player:getpos())
|
||||||
|
local faction = factions.chunks[chunkpos]
|
||||||
|
player:hud_remove("factionLand")
|
||||||
|
player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
|
name = "factionLand",
|
||||||
|
number = 0xFFFFFF,
|
||||||
|
position = {x=0.1, y = .98},
|
||||||
|
text = faction or "Wilderness",
|
||||||
|
scale = {x=1, y=1},
|
||||||
|
alignment = {x=0, y=0},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
minetest.register_on_joinplayer(
|
minetest.register_on_joinplayer(
|
||||||
|
Loading…
Reference in New Issue
Block a user