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
|
||||||
|
|
||||||
|
@ -4,13 +4,17 @@ minetest.register_privilege("team",{
|
|||||||
})
|
})
|
||||||
|
|
||||||
local function team_console_help(name)
|
local function team_console_help(name)
|
||||||
minetest.chat_send_player(name,"Try:",false)
|
minetest.chat_send_player(name,"Try:", false)
|
||||||
minetest.chat_send_player(name,"/team - show team panel",false)
|
minetest.chat_send_player(name,"/team - show team panel", false)
|
||||||
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)
|
||||||
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)
|
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 join player team - add 'player' to team 'team' (admin only)", false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("team", {
|
minetest.register_chatcommand("team", {
|
||||||
@ -21,7 +25,7 @@ minetest.register_chatcommand("team", {
|
|||||||
local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)")
|
local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)")
|
||||||
if test then
|
if test then
|
||||||
print("is a player request "..test)
|
print("is a player request "..test)
|
||||||
|
|
||||||
if ctf.player(test) then
|
if ctf.player(test) then
|
||||||
if ctf.player(test).team then
|
if ctf.player(test).team then
|
||||||
if ctf.player(test).auth then
|
if ctf.player(test).auth then
|
||||||
@ -62,7 +66,7 @@ minetest.register_chatcommand("team", {
|
|||||||
end
|
end
|
||||||
minetest.chat_send_player(name, ">> "..k.." ("..numFlags.." flags, "..numPlayers.." players)")
|
minetest.chat_send_player(name, ">> "..k.." ("..numFlags.." flags, "..numPlayers.." players)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif ctf.team(param) then
|
elseif ctf.team(param) then
|
||||||
minetest.chat_send_player(name,"Team "..param..":",false)
|
minetest.chat_send_player(name,"Team "..param..":",false)
|
||||||
local count = 0
|
local count = 0
|
||||||
@ -79,11 +83,11 @@ minetest.register_chatcommand("team", {
|
|||||||
local privs = minetest.get_player_privs(name)
|
local privs = minetest.get_player_privs(name)
|
||||||
if privs and privs.team == true then
|
if privs and privs.team == true then
|
||||||
local player = ctf.player(tplayer)
|
local player = ctf.player(tplayer)
|
||||||
|
|
||||||
if not player then
|
if not player then
|
||||||
player = {name=tplayer}
|
player = {name=tplayer}
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctf.add_user(tteam,tplayer) == true then
|
if ctf.add_user(tteam,tplayer) == true then
|
||||||
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
||||||
end
|
end
|
||||||
@ -97,13 +101,14 @@ minetest.register_chatcommand("team", {
|
|||||||
minetest.chat_send_player(name,"'"..param.."' is an invalid parameter to /team",false)
|
minetest.chat_send_player(name,"'"..param.."' is an invalid parameter to /team",false)
|
||||||
team_console_help(name)
|
team_console_help(name)
|
||||||
end
|
end
|
||||||
if (
|
if (
|
||||||
ctf and
|
ctf and
|
||||||
ctf.players and
|
ctf.players and
|
||||||
ctf.players[name] and
|
ctf.players[name] and
|
||||||
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
|
||||||
@ -113,7 +118,7 @@ minetest.register_chatcommand("team", {
|
|||||||
elseif ctf.setting("team_gui_initial") == "admin" then
|
elseif ctf.setting("team_gui_initial") == "admin" then
|
||||||
ctf.gui.team_settings(name,ctf.players[name].team)
|
ctf.gui.team_settings(name,ctf.players[name].team)
|
||||||
elseif ctf.setting("news_gui") then
|
elseif ctf.setting("news_gui") then
|
||||||
ctf.gui.team_board(name,ctf.players[name].team)
|
ctf.gui.team_board(name,ctf.players[name].team)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -145,7 +150,7 @@ minetest.register_chatcommand("list_teams", {
|
|||||||
end
|
end
|
||||||
minetest.chat_send_player(name, ">> "..k.." ("..numItems2.." flags, "..numItems.." players)",false)
|
minetest.chat_send_player(name, ">> "..k.." ("..numItems2.." flags, "..numItems.." players)",false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -262,7 +267,7 @@ if chatplus then
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not top then
|
if not top then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -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("diplomacy",true)
|
ctf._set("news_gui", true)
|
||||||
ctf._set("flag_names",true) -- can flags be named
|
ctf._set("diplomacy", true)
|
||||||
ctf._set("team_channel",true) -- do teams have their own chat channel
|
ctf._set("flag_names", true)
|
||||||
ctf._set("global_channel",true) -- Can players chat with other teams on /all. If team_channel is false, this does nothing.
|
ctf._set("team_channel", true)
|
||||||
ctf._set("players_can_change_team",true)
|
ctf._set("global_channel", 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
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
ctf.flag_func = {
|
ctf.flag_func = {
|
||||||
on_punch_top = function(pos, node, puncher)
|
on_punch_top = function(pos, node, puncher)
|
||||||
pos.y=pos.y-1
|
pos.y=pos.y-1
|
||||||
|
|
||||||
ctf.flag_func.on_punch(pos,node,puncher)
|
ctf.flag_func.on_punch(pos,node,puncher)
|
||||||
end,
|
end,
|
||||||
on_rightclick_top = function(pos, node, clicker)
|
on_rightclick_top = function(pos, node, clicker)
|
||||||
pos.y=pos.y-1
|
pos.y=pos.y-1
|
||||||
|
|
||||||
local flag = ctf.area.get_flag(pos)
|
local flag = ctf.area.get_flag(pos)
|
||||||
if not flag then
|
if not flag then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if flag.claimed then
|
if flag.claimed then
|
||||||
if ctf.setting("flag_capture_take") then
|
if ctf.setting("flag_capture_take") then
|
||||||
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
||||||
@ -22,15 +22,15 @@ ctf.flag_func = {
|
|||||||
flag.claimed = nil
|
flag.claimed = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf.gui.flag_board(clicker:get_player_name(),pos)
|
ctf.gui.flag_board(clicker:get_player_name(),pos)
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
local flag = ctf.area.get_flag(pos)
|
local flag = ctf.area.get_flag(pos)
|
||||||
if not flag then
|
if not flag then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if flag.claimed then
|
if flag.claimed then
|
||||||
if ctf.setting("flag_capture_take") then
|
if ctf.setting("flag_capture_take") then
|
||||||
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
||||||
@ -40,7 +40,7 @@ ctf.flag_func = {
|
|||||||
minetest.chat_send_player(player,"Oops! This flag should not be captured. Reverting.")
|
minetest.chat_send_player(player,"Oops! This flag should not be captured. Reverting.")
|
||||||
flag.claimed = nil
|
flag.claimed = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ctf.gui.flag_board(clicker:get_player_name(),pos)
|
ctf.gui.flag_board(clicker:get_player_name(),pos)
|
||||||
end,
|
end,
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
@ -48,12 +48,12 @@ ctf.flag_func = {
|
|||||||
if not puncher or not player then
|
if not puncher or not player then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local flag = ctf.area.get_flag(pos)
|
local flag = ctf.area.get_flag(pos)
|
||||||
if not flag then
|
if not flag then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if flag.claimed then
|
if flag.claimed then
|
||||||
if ctf.setting("flag_capture_take") then
|
if ctf.setting("flag_capture_take") then
|
||||||
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
||||||
@ -73,7 +73,7 @@ ctf.flag_func = {
|
|||||||
if ctf.players and ctf.team(team) and ctf.player(player) and ctf.player(player).team then
|
if ctf.players and ctf.team(team) and ctf.player(player) and ctf.player(player).team then
|
||||||
if ctf.player(player).team ~= team then
|
if ctf.player(player).team ~= team then
|
||||||
local diplo = ctf.diplo.get(team,ctf.player(player).team)
|
local diplo = ctf.diplo.get(team,ctf.player(player).team)
|
||||||
|
|
||||||
if not diplo then
|
if not diplo then
|
||||||
diplo = ctf.setting("default_diplo_state")
|
diplo = ctf.setting("default_diplo_state")
|
||||||
end
|
end
|
||||||
@ -82,7 +82,7 @@ ctf.flag_func = {
|
|||||||
minetest.chat_send_player(player,"You are at peace with this team!")
|
minetest.chat_send_player(player,"You are at peace with this team!")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--ctf.post(team,{msg=flag_name.." has been captured by "..ctf.player(player).team,icon="flag_red"})
|
--ctf.post(team,{msg=flag_name.." has been captured by "..ctf.player(player).team,icon="flag_red"})
|
||||||
--ctf.post(ctf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"})
|
--ctf.post(ctf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"})
|
||||||
--ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..ctf.player(player).team,icon="flag_red"})
|
--ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..ctf.player(player).team,icon="flag_red"})
|
||||||
@ -93,11 +93,11 @@ ctf.flag_func = {
|
|||||||
if flag_name and flag_name~="" then
|
if flag_name and flag_name~="" then
|
||||||
minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..ctf.player(player).team..")")
|
minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..ctf.player(player).team..")")
|
||||||
ctf.post(team,{msg=flag_name.." has been taken by "..ctf.player(player).team,icon="flag_red"})
|
ctf.post(team,{msg=flag_name.." has been taken by "..ctf.player(player).team,icon="flag_red"})
|
||||||
ctf.post(ctf.player(player).team,{msg=player.." snatched '"..flag_name.."' from "..team,icon="flag_green"})
|
ctf.post(ctf.player(player).team,{msg=player.." snatched '"..flag_name.."' from "..team,icon="flag_green"})
|
||||||
else
|
else
|
||||||
minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has taken by "..player.." (team "..ctf.player(player).team..")")
|
minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has taken by "..player.." (team "..ctf.player(player).team..")")
|
||||||
ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been taken by "..ctf.player(player).team,icon="flag_red"})
|
ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been taken by "..ctf.player(player).team,icon="flag_red"})
|
||||||
ctf.post(ctf.player(player).team,{msg=player.." snatched flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"})
|
ctf.post(ctf.player(player).team,{msg=player.." snatched flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"})
|
||||||
end
|
end
|
||||||
flag.claimed = {
|
flag.claimed = {
|
||||||
team = ctf.player(player).team,
|
team = ctf.player(player).team,
|
||||||
@ -128,7 +128,7 @@ ctf.flag_func = {
|
|||||||
-- Clicking on their team's flag
|
-- Clicking on their team's flag
|
||||||
if ctf.setting("flag_capture_take") then
|
if ctf.setting("flag_capture_take") then
|
||||||
ctf.flag_func._flagret(player)
|
ctf.flag_func._flagret(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(puncher:get_player_name(),"You are not part of a team!")
|
minetest.chat_send_player(puncher:get_player_name(),"You are not part of a team!")
|
||||||
@ -152,7 +152,7 @@ ctf.flag_func = {
|
|||||||
end
|
end
|
||||||
fteam.spawn = nil
|
fteam.spawn = nil
|
||||||
local fpos = {x=ctf.claimed[i].x,y=ctf.claimed[i].y,z=ctf.claimed[i].z}
|
local fpos = {x=ctf.claimed[i].x,y=ctf.claimed[i].y,z=ctf.claimed[i].z}
|
||||||
if ctf.setting("multiple_flags") == true then
|
if ctf.setting("multiple_flags") == true then
|
||||||
ctf.area.delete_flag(fteam.data.name,fpos)
|
ctf.area.delete_flag(fteam.data.name,fpos)
|
||||||
ctf.area.add_flag(ctf.claimed[i].claimed.team,fpos)
|
ctf.area.add_flag(ctf.claimed[i].claimed.team,fpos)
|
||||||
else
|
else
|
||||||
@ -173,7 +173,7 @@ ctf.flag_func = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
|
||||||
if not meta then
|
if not meta then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -181,7 +181,7 @@ ctf.flag_func = {
|
|||||||
if ctf.players and ctf.players[placer:get_player_name()] and ctf.players[placer:get_player_name()].team then
|
if ctf.players and ctf.players[placer:get_player_name()] and ctf.players[placer:get_player_name()].team then
|
||||||
local team = ctf.players[placer:get_player_name()].team
|
local team = ctf.players[placer:get_player_name()].team
|
||||||
meta:set_string("infotext", team.."'s flag")
|
meta:set_string("infotext", team.."'s flag")
|
||||||
|
|
||||||
-- add flag
|
-- add flag
|
||||||
ctf.area.add_flag(team,pos)
|
ctf.area.add_flag(team,pos)
|
||||||
|
|
||||||
@ -202,20 +202,20 @@ ctf.flag_func = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
ctf.save()
|
ctf.save()
|
||||||
|
|
||||||
local pos2 = {
|
local pos2 = {
|
||||||
x=pos.x,
|
x=pos.x,
|
||||||
y=pos.y+1,
|
y=pos.y+1,
|
||||||
z=pos.z
|
z=pos.z
|
||||||
}
|
}
|
||||||
|
|
||||||
if not ctf.team(team).data.color then
|
if not ctf.team(team).data.color then
|
||||||
ctf.team(team).data.color = "red"
|
ctf.team(team).data.color = "red"
|
||||||
ctf.save()
|
ctf.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.env:set_node(pos2,{name="ctf:flag_top_"..ctf.team(team).data.color})
|
minetest.env:set_node(pos2,{name="ctf:flag_top_"..ctf.team(team).data.color})
|
||||||
|
|
||||||
local meta2 = minetest.env:get_meta(pos2)
|
local meta2 = minetest.env:get_meta(pos2)
|
||||||
|
|
||||||
meta2:set_string("infotext", team.."'s flag")
|
meta2:set_string("infotext", team.."'s flag")
|
||||||
@ -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",
|
||||||
@ -352,12 +355,12 @@ minetest.register_abm({
|
|||||||
ctf.save()
|
ctf.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
if flag_team_data.claimed then
|
if flag_team_data.claimed then
|
||||||
minetest.env:set_node(top,{name="ctf:flag_captured_top"})
|
minetest.env:set_node(top,{name="ctf:flag_captured_top"})
|
||||||
else
|
else
|
||||||
minetest.env:set_node(top,{name="ctf:flag_top_"..ctf.team(flag_team_data.team).data.color})
|
minetest.env:set_node(top,{name="ctf:flag_top_"..ctf.team(flag_team_data.team).data.color})
|
||||||
end
|
end
|
||||||
|
|
||||||
topmeta = minetest.env:get_meta(top)
|
topmeta = minetest.env:get_meta(top)
|
||||||
if flag_name and flag_name ~= "" then
|
if flag_name and flag_name ~= "" then
|
||||||
topmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
|
topmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
|
||||||
@ -365,4 +368,4 @@ minetest.register_abm({
|
|||||||
topmeta:set_string("infotext", flag_team_data.team.."'s flag")
|
topmeta:set_string("infotext", flag_team_data.team.."'s flag")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
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