Merge pull request #1 from Coder12a/master

Add simple power system and allow players to create teams.  (Power system will probably be modified in the future.)
This commit is contained in:
Billy S 2018-12-06 11:57:40 -05:00 committed by GitHub
commit 591e5ec434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 26 deletions

View File

@ -209,8 +209,14 @@ function ctf.load()
ctf.teams = table.teams ctf.teams = table.teams
ctf.players = table.players ctf.players = table.players
for i = 1, #ctf.registered_on_load do -- Convert old data
ctf.registered_on_load[i](table) for teamname,unused in pairs(ctf.teams) do
if not ctf.teams[teamname].power then
ctf.teams[teamname].power = 0
for player,unused in pairs(ctf.teams[teamname].players) do
ctf.teams[teamname].power = ctf.teams[teamname].power + 1
end
end
end end
return return
end end

View File

@ -38,7 +38,8 @@ function ctf.create_team(name, data)
data = data, data = data,
spawn = nil, spawn = nil,
players = {}, players = {},
applications = {} applications = {},
power = 0
} }
for i = 1, #ctf.registered_on_new_team do for i = 1, #ctf.registered_on_new_team do
@ -284,6 +285,8 @@ function ctf.join(name, team, force, by)
player.team = team player.team = team
team_data.players[player.name] = player team_data.players[player.name] = player
ctf.team(team).power = ctf.team(team).power + 1
ctf.needs_save = true ctf.needs_save = true
minetest.log("action", name .. " joined team " .. team) minetest.log("action", name .. " joined team " .. team)

View File

@ -14,15 +14,13 @@ local function team_console_help(name)
minetest.chat_send_player(name, "/team <team> - show details about team 'name'") minetest.chat_send_player(name, "/team <team> - show details about team 'name'")
minetest.chat_send_player(name, "/team <name> - get which team 'player' is in") minetest.chat_send_player(name, "/team <name> - get which team 'player' is in")
minetest.chat_send_player(name, "/team player <name> - get which team 'player' is in") minetest.chat_send_player(name, "/team player <name> - get which team 'player' is in")
minetest.chat_send_player(name, "/team add <team> - add a team called name")
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.ctf_admin == true then if privs and privs.ctf_admin == true then
minetest.chat_send_player(name, "/team add <team> - add a team called name (ctf_admin only)")
minetest.chat_send_player(name, "/team remove <team> - add a team called name (ctf_admin only)") minetest.chat_send_player(name, "/team remove <team> - add a team called name (ctf_admin only)")
end minetest.chat_send_player(name, "/team join <name> <team> - add 'player' to team 'team' (ctf_admin only)")
if privs and privs.ctf_team_mgr == true then minetest.chat_send_player(name, "/team removeply <name> - add 'player' to team 'team' (ctf_admin only)")
minetest.chat_send_player(name, "/team join <name> <team> - add 'player' to team 'team' (ctf_team_mgr only)")
minetest.chat_send_player(name, "/team removeply <name> - add 'player' to team 'team' (ctf_team_mgr only)")
end end
end end
@ -35,20 +33,26 @@ minetest.register_chatcommand("team", {
local j_name, j_tname = string.match(param, "^join ([%a%d_-]+) ([%a%d_]+)") local j_name, j_tname = string.match(param, "^join ([%a%d_-]+) ([%a%d_]+)")
local l_name = string.match(param, "^removeplr ([%a%d_-]+)") local l_name = string.match(param, "^removeplr ([%a%d_-]+)")
if create then if create then
local privs = minetest.get_player_privs(name) if ctf and ctf.players and ctf.players[name] and not ctf.players[name].team and not ctf.team(create) then
if privs and privs.ctf_admin then
if ( if (
string.match(create, "([%a%b_]-)") string.match(create, "([%a%b_]-)")
and create ~= "" and create ~= ""
and create ~= nil and create ~= nil
and ctf.team({name=create, add_team=true}) and ctf.team({name=create, add_team=true})
) then ) then
ctf.join(name, create, false, name)
ctf.player(name).auth = true
minetest.chat_send_all(name.." was upgraded to an admin of "..create)
return true, "Added team '"..create.."'" return true, "Added team '"..create.."'"
else else
return false, "Error adding team '"..create.."'" return false, "Error adding team '"..create.."'"
end end
else else
return false, "You are not a ctf_admin!" if ctf.team(create) then
return false, "There is already a team with the name "..create
else
return false, "You need to leave your current team to create a new one."
end
end end
elseif remove then elseif remove then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
@ -98,25 +102,25 @@ minetest.register_chatcommand("team", {
end end
elseif j_name and j_tname then elseif j_name and j_tname then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.ctf_team_mgr then if privs and privs.ctf_admin then
if ctf.join(j_name, j_tname, true, name) then if ctf.join(j_name, j_tname, true, name) then
return true, "Successfully added " .. j_name .. " to " .. j_tname return true, "Successfully added " .. j_name .. " to " .. j_tname
else else
return false, "Failed to add " .. j_name .. " to " .. j_tname return false, "Failed to add " .. j_name .. " to " .. j_tname
end end
else else
return true, "You are not a ctf_team_mgr!" return true, "You are not a ctf_admin!"
end end
elseif l_name then elseif l_name then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.ctf_team_mgr then if privs and privs.ctf_admin then
if ctf.remove_player(l_name) then if ctf.remove_player(l_name) then
return true, "Removed player " .. l_name return true, "Removed player " .. l_name
else else
return false, "Failed to remove player." return false, "Failed to remove player."
end end
else else
return false, "You are not a ctf_team_mgr!" return false, "You are not a ctf_admin!"
end end
elseif param=="help" then elseif param=="help" then
team_console_help(name) team_console_help(name)
@ -155,7 +159,7 @@ minetest.register_chatcommand("apply", {
end end
end end
}) })
--[[
minetest.register_chatcommand("join", { minetest.register_chatcommand("join", {
params = "player name", params = "player name",
description = "Add to team", description = "Add to team",
@ -178,6 +182,7 @@ minetest.register_chatcommand("join", {
end end
end end
}) })
--]]
minetest.register_chatcommand("teamkick", { minetest.register_chatcommand("teamkick", {
params = "player name", params = "player name",
description = "Kick player from your team", description = "Kick player from your team",
@ -191,6 +196,9 @@ minetest.register_chatcommand("teamkick", {
return false, param.. " is a team owner or recruiter!" return false, param.. " is a team owner or recruiter!"
else else
if ctf.remove_player(param) then if ctf.remove_player(param) then
ctf.player(param).auth = false
ctf.player(param).recuiter = false
ctf.team(team).power = ctf.team(team).power - 1
return true, "Kicked " .. param .. " from " .. team .. "!" return true, "Kicked " .. param .. " from " .. team .. "!"
else else
return false, "Failed to kick " .. param.. "!" return false, "Failed to kick " .. param.. "!"
@ -208,6 +216,9 @@ minetest.register_chatcommand("teamleave", {
local team = ctf.player(name).team local team = ctf.player(name).team
if ctf.player(name).team ~= nil then if ctf.player(name).team ~= nil then
if ctf.remove_player(name) then if ctf.remove_player(name) then
ctf.player(name).auth = false
ctf.player(name).recuiter = false
ctf.team(team).power = ctf.team(team).power - 1
return true, "You have left " .. team .. "!" return true, "You have left " .. team .. "!"
else else
return false, "Failed to leave " .. team.. "!" return false, "Failed to leave " .. team.. "!"

View File

@ -152,6 +152,11 @@ function ctf_flag.update(pos)
end end
end end
function ctf_flag.flag_tick(pos)
ctf_flag.update(pos)
minetest.get_node_timer(pos):start(5)
end
-- get a flag from a team -- get a flag from a team
function ctf_flag.get(pos) function ctf_flag.get(pos)
if not pos then if not pos then

View File

@ -180,6 +180,7 @@ ctf_flag = {
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Unowned flag") meta:set_string("infotext", "Unowned flag")
minetest.get_node_timer(pos):start(5)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local name = placer:get_player_name() local name = placer:get_player_name()
@ -196,13 +197,15 @@ ctf_flag = {
local tplayer = ctf.player_or_nil(name) local tplayer = ctf.player_or_nil(name)
if tplayer and ctf.team(tplayer.team) then if tplayer and ctf.team(tplayer.team) then
if not minetest.check_player_privs(name, {ctf_place_flag=true}) then if ctf.player(name).auth == false then
minetest.chat_send_player(name, "You're not allowed to place flags! Reported to admin for investigation.") minetest.chat_send_player(name, "You're not allowed to place flags!")
minetest.set_node(pos, {name="air"})
return
end
if ctf.team(tplayer.team).power and ctf.team(tplayer.team).power < 1 then
minetest.chat_send_player(name, "You need more members to be-able to place more flags.")
minetest.set_node(pos, {name="air"}) minetest.set_node(pos, {name="air"})
if minetest.global_exists("chatplus") then
chatplus.send_mail("*SERVER*", minetest.setting_get("name"),
"player " .. name .. " attempted to place flag!")
end
return return
end end
@ -245,6 +248,10 @@ ctf_flag = {
local meta2 = minetest.get_meta(pos2) local meta2 = minetest.get_meta(pos2)
meta2:set_string("infotext", tname.."'s flag") meta2:set_string("infotext", tname.."'s flag")
if ctf.team(tplayer.team).power then
ctf.team(tplayer.team).power = ctf.team(tplayer.team).power - 1
end
else else
minetest.chat_send_player(name, "You are not part of a team!") minetest.chat_send_player(name, "You are not part of a team!")
minetest.set_node(pos, {name="air"}) minetest.set_node(pos, {name="air"})

View File

@ -22,9 +22,10 @@ minetest.register_node("ctf_flag:flag", {
on_punch = ctf_flag.on_punch, on_punch = ctf_flag.on_punch,
on_rightclick = ctf_flag.on_rightclick, on_rightclick = ctf_flag.on_rightclick,
on_construct = ctf_flag.on_construct, on_construct = ctf_flag.on_construct,
after_place_node = ctf_flag.after_place_node after_place_node = ctf_flag.after_place_node,
on_timer = ctf_flag.flag_tick
}) })
--[[
minetest.register_craft({ minetest.register_craft({
output = "ctf_flag:flag", output = "ctf_flag:flag",
recipe = { recipe = {
@ -33,7 +34,7 @@ minetest.register_craft({
{"default:stick", ""} {"default:stick", ""}
} }
}) })
--]]
for color, _ in pairs(ctf.flag_colors) do for color, _ in pairs(ctf.flag_colors) do
minetest.register_node("ctf_flag:flag_top_"..color,{ minetest.register_node("ctf_flag:flag_top_"..color,{
description = "You are not meant to have this! - flag top", description = "You are not meant to have this! - flag top",
@ -85,9 +86,11 @@ minetest.register_node("ctf_flag:flag_captured_top",{
on_rightclick = ctf_flag.on_rightclick_top on_rightclick = ctf_flag.on_rightclick_top
}) })
--[[
minetest.register_abm({ minetest.register_abm({
nodenames = {"group:flag_bottom"}, nodenames = {"group:flag_bottom"},
inteval = 5, inteval = 5,
chance = 1, chance = 1,
action = ctf_flag.update action = ctf_flag.update
}) })
--]]

View File

@ -174,11 +174,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
ctf_flag.delete(team,pos) ctf_flag.delete(team,pos)
if ctf.team(team).power then
ctf.team(team).power = ctf.team(team).power + 1
end
minetest.set_node(pos,{name="air"}) minetest.set_node(pos,{name="air"})
pos.y=pos.y+1 pos.y=pos.y+1
minetest.set_node(pos,{name="air"}) minetest.set_node(pos,{name="air"})
player:get_inventory():add_item('main', 'ctf_flag:flag') player:get_inventory():add_item('main', 'ctf_flag:flag')
ctf.needs_save = true
return true return true
end end
end) end)