master
rubenwardy 2014-12-28 17:07:30 +00:00
parent 727dec74e0
commit 70f1dddbbb
6 changed files with 178 additions and 63 deletions

View File

@ -11,6 +11,9 @@
# Are GUIs enabled
#ctf_gui = true
# Is the HUD enabled
#ctf_hud = true
# Team GUI on /team
#ctf_team_gui = true

View File

@ -4,13 +4,17 @@ minetest.register_privilege("team",{
})
local function team_console_help(name)
minetest.chat_send_player(name,"Try:",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 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 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,"Try:", 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 name - show details about team 'name'", 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 join player team - add 'player' to team 'team' (admin only)", false)
end
end
minetest.register_chatcommand("team", {
@ -104,6 +108,7 @@ minetest.register_chatcommand("team", {
ctf.players[name].team and
ctf.setting("gui")
) then
minetest.chat_send_player(name, "Showing the Team GUI")
if ctf.setting("team_gui_initial") == "news" and ctf.setting("news_gui") then
ctf.gui.team_board(name,ctf.players[name].team)
elseif ctf.setting("team_gui_initial") == "flags" and ctf.setting("flag_teleport_gui") then

View File

@ -16,31 +16,32 @@ function ctf.init()
ctf.players = {}
ctf.claimed = {}
-- See minetest.conf.example in the root of this subgame
-- Settings: Feature enabling
ctf._set("node_ownership",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("gui",true) -- whether GUIs are used
ctf._set("team_gui",true) -- GUI on /team is used
ctf._set("flag_teleport_gui",true) -- flag tab in /team
ctf._set("spawn_in_flag_teleport_gui",false) -- show spawn in the flag teleport team gui
ctf._set("news_gui",true) -- news tab in /team
ctf._set("diplomacy",true)
ctf._set("flag_names",true) -- can flags be named
ctf._set("team_channel",true) -- do teams have their own chat channel
ctf._set("global_channel",true) -- Can players chat with other teams on /all. If team_channel is false, this does nothing.
ctf._set("players_can_change_team",true)
ctf._set("node_ownership", true)
ctf._set("multiple_flags", true)
ctf._set("flag_capture_take", false)
ctf._set("gui", true)
ctf._set("hud", true)
ctf._set("team_gui", true)
ctf._set("flag_teleport_gui", true)
ctf._set("spawn_in_flag_teleport_gui", false)
ctf._set("news_gui", true)
ctf._set("diplomacy", true)
ctf._set("flag_names", true)
ctf._set("team_channel", true)
ctf._set("global_channel", true)
ctf._set("players_can_change_team", true)
-- 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("maximum_in_team", -1) -- Maximum number in team, obeyed by allocation and /join. Admins don't obey this
ctf._set("default_diplo_state", "war") -- what is the default diplomatic state? (war/peace/alliance)
--ctf._setb("delete_teams",false) -- (COMING SOON):should teams be deleted when they are defeated?
ctf._set("allocate_mode", 0)
ctf._set("maximum_in_team", -1)
ctf._set("default_diplo_state", "war")
-- Settings: Misc
--ctf._set("on_game_end",0) -- (COMING SOON):what happens when the game ends?
ctf._set("flag_protect_distance", 25) -- how far do flags protect?
ctf._set("team_gui_initial", "news") -- [news/flags/diplo/admin] - the starting tab
ctf._set("flag_protect_distance", 25)
ctf._set("team_gui_initial", "news")
ctf.load()
end
@ -62,6 +63,11 @@ function ctf.setting(name)
end
end
function ctf.setting_bool(name)
local set = ctf.setting(name)
return minetest.is_yes(set)
end
function ctf.load()
local file = io.open(minetest.get_worldpath().."/ctf.txt", "r")
if file then
@ -160,6 +166,11 @@ function ctf.join(name, team, force)
if ctf.add_user(team, player) == true then
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
end
return false

View File

@ -252,10 +252,13 @@ minetest.register_node("ctf:flag",{
on_construct = ctf.flag_func.on_construct,
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
local color = colors[i]
for color, _ in pairs(ctf.flag_colors) do
minetest.register_node("ctf:flag_top_"..color,{
description = "You are not meant to have this! - flag top",
drawtype="nodebox",

View 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)

View File

@ -8,9 +8,10 @@ ctf = {}
dofile(minetest.get_modpath("ctf").."/core.lua")
dofile(minetest.get_modpath("ctf").."/diplomacy.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").."/cli.lua")
dofile(minetest.get_modpath("ctf").."/gui.lua")
dofile(minetest.get_modpath("ctf").."/hud.lua")
-- Init
ctf.init()