Add pro-only area in chest

This commit is contained in:
rubenwardy 2017-10-12 01:19:23 +01:00
parent 4514afdfe4
commit 82529b56e3
5 changed files with 70 additions and 20 deletions

View file

@ -41,6 +41,7 @@ local function calc_scores(players)
return one.score > two.score return one.score > two.score
end) end)
end end
ctf_stats.calc_scores = calc_scores
function ctf_stats.get_formspec(title, players) function ctf_stats.get_formspec(title, players)
calc_scores(players) calc_scores(players)

View file

@ -53,7 +53,8 @@ function ctf_stats.player(name)
kills = 0, kills = 0,
deaths = 0, deaths = 0,
captures = 0, captures = 0,
attempts = 0 attempts = 0,
score = -1,
} }
ctf_stats.players[name] = player ctf_stats.players[name] = player
end end

View file

@ -2,3 +2,4 @@ ctf
ctf_flag ctf_flag
ctf_match ctf_match
ctf_barrier ctf_barrier
ctf_stats

View file

@ -35,18 +35,16 @@ function ctf.get_spawn(tname)
end end
end end
local function get_is_player_pro(player)
local chest_formspec = local players = {}
"size[8,9]" .. for pname, pstat in pairs(ctf_stats.players) do
default.gui_bg .. pstat.name = pname
default.gui_bg_img .. pstat.color = nil
default.gui_slots .. table.insert(players, pstat)
"list[current_name;main;0,0.3;8,4;]" .. end
"list[current_player;main;0,4.85;8,1;]" .. ctf_stats.calc_scores(players)
"list[current_player;main;0,6.08;8,3;8]" .. return ctf_stats.player(player:get_player_name()).score > 0
"listring[current_name;main]" .. end
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
local colors = {"red", "blue"} local colors = {"red", "blue"}
for _, color in pairs(colors) do for _, color in pairs(colors) do
@ -66,19 +64,68 @@ for _, color in pairs(colors) do
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", chest_formspec)
meta:set_string("infotext", "Chest") meta:set_string("infotext", "Chest")
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 8*4) inv:set_size("main", 5*4)
inv:set_size("pro", 3*4)
end,
on_rightclick = function(pos, node, player)
local chestinv = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z
local is_pro = get_is_player_pro(player)
local formspec =
"size[8,9]" ..
"label[0,-0.2;" .. minetest.formspec_escape("Any player can take from here, including enemies") .. "]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[" .. chestinv .. ";main;0,0.3;5,4;]" ..
"background[5,-0.2;3.15,4.7;ctf_team_base_pro_only.png;false]" ..
"list[" .. chestinv .. ";pro;5,0.3;3,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]"
if is_pro then
formspec = formspec .. "listring[current_name;pro]" ..
"label[5,-0.2;" .. minetest.formspec_escape("Pro players only (score 200+)") .. "]"
else
formspec = formspec .. "listring[current_name;pro]" ..
"label[5,-0.2;" .. minetest.formspec_escape("You need more score (200+)") .. "]"
end
formspec = formspec ..
"listring[current_name;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
minetest.show_formspec(player:get_player_name(), "ctf_team_base:chest", formspec)
end,
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if (from_list ~= "pro" and to_list ~= "pro") or get_is_player_pro(player) then
return count
else
return 0
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname ~= "pro" or get_is_player_pro(player) then
return stack:get_count()
else
return 0
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname ~= "pro" or get_is_player_pro(player) then
return stack:get_count()
else
return 0
end
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
return false return false
end, end,
on_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
minetest.log("action", player:get_player_name() ..
" moves stuff in chest at " .. minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() .. minetest.log("action", player:get_player_name() ..
" moves " .. (stack:get_name() or "stuff") .. " " .. (stack:get_count() or 0) .. " to chest at " .. minetest.pos_to_string(pos)) " moves " .. (stack:get_name() or "stuff") .. " " .. (stack:get_count() or 0) .. " to chest at " .. minetest.pos_to_string(pos))

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B