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", {
@ -21,7 +25,7 @@ minetest.register_chatcommand("team", {
local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)")
if test then
print("is a player request "..test)
if ctf.player(test) then
if ctf.player(test).team then
if ctf.player(test).auth then
@ -62,7 +66,7 @@ minetest.register_chatcommand("team", {
end
minetest.chat_send_player(name, ">> "..k.." ("..numFlags.." flags, "..numPlayers.." players)")
end
end
end
elseif ctf.team(param) then
minetest.chat_send_player(name,"Team "..param..":",false)
local count = 0
@ -79,11 +83,11 @@ minetest.register_chatcommand("team", {
local privs = minetest.get_player_privs(name)
if privs and privs.team == true then
local player = ctf.player(tplayer)
if not player then
player = {name=tplayer}
end
if ctf.add_user(tteam,tplayer) == true then
minetest.chat_send_all(tplayer.." has joined team "..tteam)
end
@ -97,13 +101,14 @@ minetest.register_chatcommand("team", {
minetest.chat_send_player(name,"'"..param.."' is an invalid parameter to /team",false)
team_console_help(name)
end
if (
if (
ctf and
ctf.players and
ctf.players[name] and
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
@ -113,7 +118,7 @@ minetest.register_chatcommand("team", {
elseif ctf.setting("team_gui_initial") == "admin" then
ctf.gui.team_settings(name,ctf.players[name].team)
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
@ -145,7 +150,7 @@ minetest.register_chatcommand("list_teams", {
end
minetest.chat_send_player(name, ">> "..k.." ("..numItems2.." flags, "..numItems.." players)",false)
end
end
end
end,
})
@ -262,7 +267,7 @@ if chatplus then
end
return false
end
if not top then
return false
end

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

@ -1,17 +1,17 @@
ctf.flag_func = {
on_punch_top = function(pos, node, puncher)
pos.y=pos.y-1
ctf.flag_func.on_punch(pos,node,puncher)
end,
on_rightclick_top = function(pos, node, clicker)
pos.y=pos.y-1
local flag = ctf.area.get_flag(pos)
if not flag then
return
end
if flag.claimed then
if ctf.setting("flag_capture_take") then
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
@ -22,15 +22,15 @@ ctf.flag_func = {
flag.claimed = nil
end
end
ctf.gui.flag_board(clicker:get_player_name(),pos)
end,
on_rightclick = function(pos, node, clicker)
on_rightclick = function(pos, node, clicker)
local flag = ctf.area.get_flag(pos)
if not flag then
return
end
if flag.claimed then
if ctf.setting("flag_capture_take") then
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.")
flag.claimed = nil
end
end
end
ctf.gui.flag_board(clicker:get_player_name(),pos)
end,
on_punch = function(pos, node, puncher)
@ -48,12 +48,12 @@ ctf.flag_func = {
if not puncher or not player then
return
end
local flag = ctf.area.get_flag(pos)
if not flag then
return
end
if flag.claimed then
if ctf.setting("flag_capture_take") then
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.player(player).team ~= team then
local diplo = ctf.diplo.get(team,ctf.player(player).team)
if not diplo then
diplo = ctf.setting("default_diplo_state")
end
@ -82,7 +82,7 @@ ctf.flag_func = {
minetest.chat_send_player(player,"You are at peace with this team!")
return
end
--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(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
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(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
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(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
flag.claimed = {
team = ctf.player(player).team,
@ -128,7 +128,7 @@ ctf.flag_func = {
-- Clicking on their team's flag
if ctf.setting("flag_capture_take") then
ctf.flag_func._flagret(player)
end
end
end
else
minetest.chat_send_player(puncher:get_player_name(),"You are not part of a team!")
@ -152,7 +152,7 @@ ctf.flag_func = {
end
fteam.spawn = nil
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.add_flag(ctf.claimed[i].claimed.team,fpos)
else
@ -173,7 +173,7 @@ ctf.flag_func = {
end
local meta = minetest.env:get_meta(pos)
if not meta then
return
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
local team = ctf.players[placer:get_player_name()].team
meta:set_string("infotext", team.."'s flag")
-- add flag
ctf.area.add_flag(team,pos)
@ -202,20 +202,20 @@ ctf.flag_func = {
end
ctf.save()
local pos2 = {
x=pos.x,
y=pos.y+1,
z=pos.z
}
if not ctf.team(team).data.color then
ctf.team(team).data.color = "red"
ctf.save()
end
minetest.env:set_node(pos2,{name="ctf:flag_top_"..ctf.team(team).data.color})
local meta2 = minetest.env:get_meta(pos2)
meta2:set_string("infotext", team.."'s flag")
@ -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",
@ -352,12 +355,12 @@ minetest.register_abm({
ctf.save()
end
if flag_team_data.claimed then
if flag_team_data.claimed then
minetest.env:set_node(top,{name="ctf:flag_captured_top"})
else
minetest.env:set_node(top,{name="ctf:flag_top_"..ctf.team(flag_team_data.team).data.color})
end
topmeta = minetest.env:get_meta(top)
if flag_name and flag_name ~= "" then
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")
end
end
})
})

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