Add HUD
This commit is contained in:
parent
727dec74e0
commit
70f1dddbbb
@ -11,6 +11,9 @@
|
|||||||
# Are GUIs enabled
|
# Are GUIs enabled
|
||||||
#ctf_gui = true
|
#ctf_gui = true
|
||||||
|
|
||||||
|
# Is the HUD enabled
|
||||||
|
#ctf_hud = true
|
||||||
|
|
||||||
# Team GUI on /team
|
# Team GUI on /team
|
||||||
#ctf_team_gui = true
|
#ctf_team_gui = true
|
||||||
|
|
||||||
|
@ -9,9 +9,13 @@ local function team_console_help(name)
|
|||||||
minetest.chat_send_player(name,"/team all - list all teams", false)
|
minetest.chat_send_player(name,"/team all - list all teams", false)
|
||||||
minetest.chat_send_player(name,"/team name - show details about team 'name'", false)
|
minetest.chat_send_player(name,"/team name - show details about team 'name'", false)
|
||||||
minetest.chat_send_player(name,"/team player name - get which team 'player' is in", false)
|
minetest.chat_send_player(name,"/team player name - get which team 'player' is in", false)
|
||||||
|
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
if privs and privs.team == true then
|
||||||
minetest.chat_send_player(name,"/team add name - add a team called name (admin only)", false)
|
minetest.chat_send_player(name,"/team add name - add a team called name (admin only)", false)
|
||||||
minetest.chat_send_player(name,"/team join player team - add 'player' to team 'team' (admin only)", false)
|
minetest.chat_send_player(name,"/team join player team - add 'player' to team 'team' (admin only)", false)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("team", {
|
minetest.register_chatcommand("team", {
|
||||||
description = "Open the team console, or run team command (see /team help)",
|
description = "Open the team console, or run team command (see /team help)",
|
||||||
@ -104,6 +108,7 @@ minetest.register_chatcommand("team", {
|
|||||||
ctf.players[name].team and
|
ctf.players[name].team and
|
||||||
ctf.setting("gui")
|
ctf.setting("gui")
|
||||||
) then
|
) then
|
||||||
|
minetest.chat_send_player(name, "Showing the Team GUI")
|
||||||
if ctf.setting("team_gui_initial") == "news" and ctf.setting("news_gui") then
|
if ctf.setting("team_gui_initial") == "news" and ctf.setting("news_gui") then
|
||||||
ctf.gui.team_board(name,ctf.players[name].team)
|
ctf.gui.team_board(name,ctf.players[name].team)
|
||||||
elseif ctf.setting("team_gui_initial") == "flags" and ctf.setting("flag_teleport_gui") then
|
elseif ctf.setting("team_gui_initial") == "flags" and ctf.setting("flag_teleport_gui") then
|
||||||
|
@ -16,31 +16,32 @@ function ctf.init()
|
|||||||
ctf.players = {}
|
ctf.players = {}
|
||||||
ctf.claimed = {}
|
ctf.claimed = {}
|
||||||
|
|
||||||
|
-- See minetest.conf.example in the root of this subgame
|
||||||
|
|
||||||
-- Settings: Feature enabling
|
-- Settings: Feature enabling
|
||||||
ctf._set("node_ownership", true)
|
ctf._set("node_ownership", true)
|
||||||
ctf._set("multiple_flags", true)
|
ctf._set("multiple_flags", true)
|
||||||
ctf._set("flag_capture_take",false) -- whether flags need to be taken to home flag when captured
|
ctf._set("flag_capture_take", false)
|
||||||
ctf._set("gui",true) -- whether GUIs are used
|
ctf._set("gui", true)
|
||||||
ctf._set("team_gui",true) -- GUI on /team is used
|
ctf._set("hud", true)
|
||||||
ctf._set("flag_teleport_gui",true) -- flag tab in /team
|
ctf._set("team_gui", true)
|
||||||
ctf._set("spawn_in_flag_teleport_gui",false) -- show spawn in the flag teleport team gui
|
ctf._set("flag_teleport_gui", true)
|
||||||
ctf._set("news_gui",true) -- news tab in /team
|
ctf._set("spawn_in_flag_teleport_gui", false)
|
||||||
|
ctf._set("news_gui", true)
|
||||||
ctf._set("diplomacy", true)
|
ctf._set("diplomacy", true)
|
||||||
ctf._set("flag_names",true) -- can flags be named
|
ctf._set("flag_names", true)
|
||||||
ctf._set("team_channel",true) -- do teams have their own chat channel
|
ctf._set("team_channel", true)
|
||||||
ctf._set("global_channel",true) -- Can players chat with other teams on /all. If team_channel is false, this does nothing.
|
ctf._set("global_channel", true)
|
||||||
ctf._set("players_can_change_team", true)
|
ctf._set("players_can_change_team", true)
|
||||||
|
|
||||||
-- Settings: Teams
|
-- Settings: Teams
|
||||||
ctf._set("allocate_mode", 0) -- how are players allocated to teams? 0: none, 1: random, 2: one of first two largest groups, 3 smallest group
|
ctf._set("allocate_mode", 0)
|
||||||
ctf._set("maximum_in_team", -1) -- Maximum number in team, obeyed by allocation and /join. Admins don't obey this
|
ctf._set("maximum_in_team", -1)
|
||||||
ctf._set("default_diplo_state", "war") -- what is the default diplomatic state? (war/peace/alliance)
|
ctf._set("default_diplo_state", "war")
|
||||||
--ctf._setb("delete_teams",false) -- (COMING SOON):should teams be deleted when they are defeated?
|
|
||||||
|
|
||||||
-- Settings: Misc
|
-- Settings: Misc
|
||||||
--ctf._set("on_game_end",0) -- (COMING SOON):what happens when the game ends?
|
ctf._set("flag_protect_distance", 25)
|
||||||
ctf._set("flag_protect_distance", 25) -- how far do flags protect?
|
ctf._set("team_gui_initial", "news")
|
||||||
ctf._set("team_gui_initial", "news") -- [news/flags/diplo/admin] - the starting tab
|
|
||||||
|
|
||||||
ctf.load()
|
ctf.load()
|
||||||
end
|
end
|
||||||
@ -62,6 +63,11 @@ function ctf.setting(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ctf.setting_bool(name)
|
||||||
|
local set = ctf.setting(name)
|
||||||
|
return minetest.is_yes(set)
|
||||||
|
end
|
||||||
|
|
||||||
function ctf.load()
|
function ctf.load()
|
||||||
local file = io.open(minetest.get_worldpath().."/ctf.txt", "r")
|
local file = io.open(minetest.get_worldpath().."/ctf.txt", "r")
|
||||||
if file then
|
if file then
|
||||||
@ -160,6 +166,11 @@ function ctf.join(name, team, force)
|
|||||||
|
|
||||||
if ctf.add_user(team, player) == true then
|
if ctf.add_user(team, player) == true then
|
||||||
minetest.chat_send_all(name.." has joined team "..team)
|
minetest.chat_send_all(name.." has joined team "..team)
|
||||||
|
|
||||||
|
if ctf.setting_bool("hud") then
|
||||||
|
ctf.hud.update(minetest.get_player_by_name(name))
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -252,10 +252,13 @@ minetest.register_node("ctf:flag",{
|
|||||||
on_construct = ctf.flag_func.on_construct,
|
on_construct = ctf.flag_func.on_construct,
|
||||||
after_place_node = ctf.flag_func.after_place_node
|
after_place_node = ctf.flag_func.after_place_node
|
||||||
})
|
})
|
||||||
local colors = {"red","green","blue"}
|
ctf.flag_colors = {
|
||||||
|
red = "0xFF0000",
|
||||||
|
green = "0x00FF00",
|
||||||
|
blue = "0x0000FF"
|
||||||
|
}
|
||||||
|
|
||||||
for i=1,#colors do
|
for color, _ in pairs(ctf.flag_colors) do
|
||||||
local color = colors[i]
|
|
||||||
minetest.register_node("ctf:flag_top_"..color,{
|
minetest.register_node("ctf:flag_top_"..color,{
|
||||||
description = "You are not meant to have this! - flag top",
|
description = "You are not meant to have this! - flag top",
|
||||||
drawtype="nodebox",
|
drawtype="nodebox",
|
||||||
|
92
mods/capturetheflag/ctf/hud.lua
Normal file
92
mods/capturetheflag/ctf/hud.lua
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
function hudkit()
|
||||||
|
return {
|
||||||
|
players = {},
|
||||||
|
|
||||||
|
add = function(self, player, id, def)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements then
|
||||||
|
self.players[name] = {}
|
||||||
|
elements = self.players[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
elements[id] = player:hud_add(def)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
|
||||||
|
change = function(self, player, id, stat, value)
|
||||||
|
if not player then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements or not elements[id] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
player:hud_change(elements[id], stat, value)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
|
||||||
|
remove = function(self, player, id)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements or not elements[id] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
player:hud_remove(elements[id])
|
||||||
|
elements[id] = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf.hud = hudkit()
|
||||||
|
|
||||||
|
function ctf.hud.update(player)
|
||||||
|
local player_data = ctf.player(player:get_player_name())
|
||||||
|
|
||||||
|
if not player_data or not player_data.team or not ctf.team(player_data.team) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local color = ctf.flag_colors[ctf.team(player_data.team).data.color]
|
||||||
|
if not color then
|
||||||
|
color = "0x000000"
|
||||||
|
end
|
||||||
|
|
||||||
|
if not ctf.hud:change(player, "ctf:hud_team", "text", player_data.team) then
|
||||||
|
return ctf.hud:add(player, "ctf:hud_team", {
|
||||||
|
hud_elem_type = "text",
|
||||||
|
position = {x = 1, y = 0},
|
||||||
|
scale = {x = 100, y = 100},
|
||||||
|
text = player_data.team,
|
||||||
|
number = color,
|
||||||
|
offset = {x=-100, y = 20}
|
||||||
|
})
|
||||||
|
else
|
||||||
|
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local count = 0
|
||||||
|
minetest.register_globalstep(function(delta)
|
||||||
|
count = count + delta
|
||||||
|
|
||||||
|
if count > 10 then
|
||||||
|
if not ctf.setting_bool("hud") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
count = 0
|
||||||
|
local players = minetest.get_connected_players()
|
||||||
|
|
||||||
|
for i = 1, #players do
|
||||||
|
ctf.hud.update(players[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
@ -8,9 +8,10 @@ ctf = {}
|
|||||||
dofile(minetest.get_modpath("ctf").."/core.lua")
|
dofile(minetest.get_modpath("ctf").."/core.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/area.lua")
|
dofile(minetest.get_modpath("ctf").."/area.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/gui.lua")
|
|
||||||
dofile(minetest.get_modpath("ctf").."/cli.lua")
|
|
||||||
dofile(minetest.get_modpath("ctf").."/flag.lua")
|
dofile(minetest.get_modpath("ctf").."/flag.lua")
|
||||||
|
dofile(minetest.get_modpath("ctf").."/cli.lua")
|
||||||
|
dofile(minetest.get_modpath("ctf").."/gui.lua")
|
||||||
|
dofile(minetest.get_modpath("ctf").."/hud.lua")
|
||||||
|
|
||||||
-- Init
|
-- Init
|
||||||
ctf.init()
|
ctf.init()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user