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.players = table.players
for i = 1, #ctf.registered_on_load do
ctf.registered_on_load[i](table)
-- Convert old data
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
return
end

View File

@ -38,7 +38,8 @@ function ctf.create_team(name, data)
data = data,
spawn = nil,
players = {},
applications = {}
applications = {},
power = 0
}
for i = 1, #ctf.registered_on_new_team do
@ -284,6 +285,8 @@ function ctf.join(name, team, force, by)
player.team = team
team_data.players[player.name] = player
ctf.team(team).power = ctf.team(team).power + 1
ctf.needs_save = true
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 <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)
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)")
end
if privs and privs.ctf_team_mgr == true then
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)")
minetest.chat_send_player(name, "/team join <name> <team> - add 'player' to team 'team' (ctf_admin only)")
minetest.chat_send_player(name, "/team removeply <name> - add 'player' to team 'team' (ctf_admin only)")
end
end
@ -35,20 +33,26 @@ minetest.register_chatcommand("team", {
local j_name, j_tname = string.match(param, "^join ([%a%d_-]+) ([%a%d_]+)")
local l_name = string.match(param, "^removeplr ([%a%d_-]+)")
if create then
local privs = minetest.get_player_privs(name)
if privs and privs.ctf_admin then
if ctf and ctf.players and ctf.players[name] and not ctf.players[name].team and not ctf.team(create) then
if (
string.match(create, "([%a%b_]-)")
and create ~= ""
and create ~= nil
and ctf.team({name=create, add_team=true})
) 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.."'"
else
return false, "Error adding team '"..create.."'"
end
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
elseif remove then
local privs = minetest.get_player_privs(name)
@ -98,25 +102,25 @@ minetest.register_chatcommand("team", {
end
elseif j_name and j_tname then
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
return true, "Successfully added " .. j_name .. " to " .. j_tname
else
return false, "Failed to add " .. j_name .. " to " .. j_tname
end
else
return true, "You are not a ctf_team_mgr!"
return true, "You are not a ctf_admin!"
end
elseif l_name then
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
return true, "Removed player " .. l_name
else
return false, "Failed to remove player."
end
else
return false, "You are not a ctf_team_mgr!"
return false, "You are not a ctf_admin!"
end
elseif param=="help" then
team_console_help(name)
@ -155,7 +159,7 @@ minetest.register_chatcommand("apply", {
end
end
})
--[[
minetest.register_chatcommand("join", {
params = "player name",
description = "Add to team",
@ -178,6 +182,7 @@ minetest.register_chatcommand("join", {
end
end
})
--]]
minetest.register_chatcommand("teamkick", {
params = "player name",
description = "Kick player from your team",
@ -191,6 +196,9 @@ minetest.register_chatcommand("teamkick", {
return false, param.. " is a team owner or recruiter!"
else
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 .. "!"
else
return false, "Failed to kick " .. param.. "!"
@ -208,6 +216,9 @@ minetest.register_chatcommand("teamleave", {
local team = ctf.player(name).team
if ctf.player(name).team ~= nil 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 .. "!"
else
return false, "Failed to leave " .. team.. "!"

View File

@ -152,6 +152,11 @@ function ctf_flag.update(pos)
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
function ctf_flag.get(pos)
if not pos then

View File

@ -180,6 +180,7 @@ ctf_flag = {
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Unowned flag")
minetest.get_node_timer(pos):start(5)
end,
after_place_node = function(pos, placer)
local name = placer:get_player_name()
@ -196,13 +197,15 @@ ctf_flag = {
local tplayer = ctf.player_or_nil(name)
if tplayer and ctf.team(tplayer.team) then
if not minetest.check_player_privs(name, {ctf_place_flag=true}) then
minetest.chat_send_player(name, "You're not allowed to place flags! Reported to admin for investigation.")
if ctf.player(name).auth == false then
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"})
if minetest.global_exists("chatplus") then
chatplus.send_mail("*SERVER*", minetest.setting_get("name"),
"player " .. name .. " attempted to place flag!")
end
return
end
@ -245,6 +248,10 @@ ctf_flag = {
local meta2 = minetest.get_meta(pos2)
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
minetest.chat_send_player(name, "You are not part of a team!")
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_rightclick = ctf_flag.on_rightclick,
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({
output = "ctf_flag:flag",
recipe = {
@ -33,7 +34,7 @@ minetest.register_craft({
{"default:stick", ""}
}
})
--]]
for color, _ in pairs(ctf.flag_colors) do
minetest.register_node("ctf_flag:flag_top_"..color,{
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
})
--[[
minetest.register_abm({
nodenames = {"group:flag_bottom"},
inteval = 5,
chance = 1,
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)
if ctf.team(team).power then
ctf.team(team).power = ctf.team(team).power + 1
end
minetest.set_node(pos,{name="air"})
pos.y=pos.y+1
minetest.set_node(pos,{name="air"})
player:get_inventory():add_item('main', 'ctf_flag:flag')
ctf.needs_save = true
return true
end
end)