Allow players to craft and place flags.

Also add simple power system. flag placment cost one power. You get one power per player.
This commit is contained in:
Coder12a 2018-12-05 17:11:38 -06:00
parent 4ade3489ea
commit f4f6351851
6 changed files with 34 additions and 12 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

@ -43,7 +43,7 @@ minetest.register_chatcommand("team", {
and ctf.team({name=create, add_team=true})
) then
ctf.join(name, create, false, name)
ctf.player(param).auth = true
ctf.player(name).auth = true
minetest.chat_send_all(name.." was upgraded to an admin of "..create)
return true, "Added team '"..create.."'"
else
@ -204,6 +204,7 @@ minetest.register_chatcommand("teamkick", {
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.. "!"
@ -223,6 +224,7 @@ minetest.register_chatcommand("teamleave", {
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

@ -197,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
@ -246,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

@ -25,7 +25,7 @@ minetest.register_node("ctf_flag:flag", {
after_place_node = ctf_flag.after_place_node,
on_timer = ctf_flag.flag_tick
})
--[[
minetest.register_craft({
output = "ctf_flag:flag",
recipe = {
@ -34,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",

View File

@ -173,12 +173,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
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)