inventory, proper respawning and huds

This commit is contained in:
chmodsayshello 2022-10-06 10:36:27 +02:00
parent 9ec8b56722
commit 98bb55d528
5 changed files with 141 additions and 6 deletions

43
hud.lua Normal file
View File

@ -0,0 +1,43 @@
function create_huds(arena)
local function create(player)
scoreboard_blue = minetest.get_player_by_name(player):hud_add({
hud_elem_type = "text",
position = {x = 1, y = 0},
offset = {x=-600, y = 50},
scale = {x = 1, y = 1},
text = "0",
number = 0x0001FF,
})
scoreboard_red = minetest.get_player_by_name(player):hud_add({
hud_elem_type = "text",
position = {x = 1, y = 0},
offset = {x=-400, y = 50},
scale = {x = 400, y = 1},
text = "0",
number = 0xFF0000
})
temp = {red=scoreboard_red,blue=scoreboard_blue}
arena.huds[player] =temp
end
for playername in pairs(arena.players) do
create(playername)
end
end
function update_huds(arena, player)
local playername = player:get_player_name()
player:hud_change(arena.huds[playername].blue, "text", tostring(arena.teams[team_id_blue].goals))
player:hud_change(arena.huds[playername].red, "text", tostring(arena.teams[team_id_red].goals))
end
function remove_all_huds(arena)
for playername in pairs(arena.players) do
local current_player = minetest.get_player_by_name(playername)
current_player:hud_remove(arena.huds[playername].red)
current_player:hud_remove(arena.huds[playername].blue)
end
end

View File

@ -1,4 +1,4 @@
--20221002_1a --20221004_2c
local S = minetest.get_translator("the_bridge") local S = minetest.get_translator("the_bridge")
@ -26,6 +26,8 @@ arena_lib.register_minigame("the_bridge", {
the_bridge_area_pos_1 = {x = 0, y = 0, z = 0}, the_bridge_area_pos_1 = {x = 0, y = 0, z = 0},
the_bridge_area_pos_2 = {x = 0, y = 0, z = 0}, the_bridge_area_pos_2 = {x = 0, y = 0, z = 0},
mapdata = nil, mapdata = nil,
finished = false,
huds = {}
}, },
in_game_physics = { in_game_physics = {
speed = player_speed, speed = player_speed,
@ -41,6 +43,11 @@ arena_lib.register_minigame("the_bridge", {
goals = 0 goals = 0
}, },
--[[player_properties = {
scoreboard_red = nil,
scoreboard_blue = nil,
},--]]
}) })
if not minetest.get_modpath("lib_chatcmdbuilder") then if not minetest.get_modpath("lib_chatcmdbuilder") then
@ -48,6 +55,7 @@ if not minetest.get_modpath("lib_chatcmdbuilder") then
end end
dofile(minetest.get_modpath("the_bridge") .. "/setup.lua") dofile(minetest.get_modpath("the_bridge") .. "/setup.lua")
dofile(minetest.get_modpath("the_bridge") .. "/hud.lua")
dofile(minetest.get_modpath("the_bridge") .. "/the_bridge.lua") dofile(minetest.get_modpath("the_bridge") .. "/the_bridge.lua")

View File

@ -1,2 +1,2 @@
author = chmodsayshello author = chmodsayshello
depends = arena_lib, walkover depends = arena_lib, walkover, default

View File

@ -39,10 +39,12 @@ arena_lib.on_load("the_bridge", function(arena)
arena_lib.force_arena_ending("the_bridge", arena) arena_lib.force_arena_ending("the_bridge", arena)
minetest.log("warning","The Bridge is not supposed to run without any teams!") minetest.log("warning","The Bridge is not supposed to run without any teams!")
end --this game is not supposed to be used without teams! end --this game is not supposed to be used without teams!
create_huds(arena)
after_goal(arena) --gives all players their items and teleports them to spawners
send_message(arena,S("GO!")) send_message(arena,S("GO!"))
end) end)
arena_lib.on_enable("the_bridge", function(arena, p_name) arena_lib.on_enable("the_bridge", function(arena, p_name)
savemap(arena.the_bridge_area_pos_1,arena.the_bridge_area_pos_2,arena) savemap(arena.the_bridge_area_pos_1,arena.the_bridge_area_pos_2,arena)
return true return true
@ -56,3 +58,9 @@ arena_lib.on_disable("the_bridge", function(arena, p_name)
restore_map(arena) restore_map(arena)
return true return true
end) end)
arena_lib.on_quit("the_bridge", function(arena, p_name, is_spectator, reason)
player = minetest.get_player_by_name(p_name)
player:hud_remove(arena.huds[p_name].blue)
player:hud_remove(arena.huds[p_name].red)
end)

View File

@ -1,19 +1,35 @@
local S = minetest.get_translator("the_bridge") local S = minetest.get_translator("the_bridge")
local function after_goal(arena) local function set_player_inventory(player)
local stonestack = ItemStack("default:stone 99")
local pickstack = ItemStack("the_bridge:diapick")
local swordstack = ItemStack("the_bridge:stonesword")
local gapplestack = ItemStack("the_bridge:gapple 16")
local inv = player:get_inventory()
local hotbar = {swordstack,pickstack,gapplestack,stonestack,stonestack,stonestack}
inv:set_list("main", hotbar)
end
function after_goal(arena) --global because its called once outside of this file
restore_map(arena)
local players_team_red = arena_lib.get_players_in_team(arena, team_id_red, true) local players_team_red = arena_lib.get_players_in_team(arena, team_id_red, true)
local players_team_blue = arena_lib.get_players_in_team(arena, team_id_blue, true) local players_team_blue = arena_lib.get_players_in_team(arena, team_id_blue, true)
for player_index in ipairs(players_team_red) do for player_index in ipairs(players_team_red) do
local player = players_team_red[player_index] local player = players_team_red[player_index]
set_player_inventory(player)
player:set_hp(20) player:set_hp(20)
player:set_pos(arena_lib.get_random_spawner(arena, team_id_red)) player:set_pos(arena_lib.get_random_spawner(arena, team_id_red))
update_huds(arena,player)
end end
for player_index in ipairs(players_team_blue) do for player_index in ipairs(players_team_blue) do
local player = players_team_blue[player_index] local player = players_team_blue[player_index]
set_player_inventory(player)
player:set_hp(20) player:set_hp(20)
player:set_pos(arena_lib.get_random_spawner(arena, team_id_blue)) player:set_pos(arena_lib.get_random_spawner(arena, team_id_blue))
update_huds(arena,player)
end end
end end
@ -26,6 +42,8 @@ local goalfunc = function(pos, node, player)
if nodename == "the_bridge:goal_area_red" then if nodename == "the_bridge:goal_area_red" then
arena.teams[team_id_red].goals = arena.teams[team_id_red].goals +1 arena.teams[team_id_red].goals = arena.teams[team_id_red].goals +1
if arena.teams[team_id_red].goals >= 5 and arena.in_game then if arena.teams[team_id_red].goals >= 5 and arena.in_game then
if arena.finished then return end
arena.finished = true
arena_lib.load_celebration("the_bridge", arena, team_id_red) arena_lib.load_celebration("the_bridge", arena, team_id_red)
return return
end end
@ -34,6 +52,8 @@ local goalfunc = function(pos, node, player)
elseif nodename == "the_bridge:goal_area_blue" then elseif nodename == "the_bridge:goal_area_blue" then
arena.teams[team_id_blue].goals = arena.teams[team_id_blue].goals +1 arena.teams[team_id_blue].goals = arena.teams[team_id_blue].goals +1
if arena.teams[team_id_blue].goals >= 5 and arena.in_game then if arena.teams[team_id_blue].goals >= 5 and arena.in_game then
if arena.finished then return end
arena.finished = true
arena_lib.load_celebration("the_bridge", arena, team_id_blue) arena_lib.load_celebration("the_bridge", arena, team_id_blue)
return return
end end
@ -41,9 +61,34 @@ local goalfunc = function(pos, node, player)
end end
end end
arena_lib.on_death("the_bridge", function(arena, p_name, reason)
local players_team_red = arena_lib.get_players_in_team(arena, team_id_red, false)
local players_team_blue = arena_lib.get_players_in_team(arena, team_id_blue, false)
for player_index in ipairs(players_team_red) do
if players_team_red[player_index] == p_name then
minetest.get_player_by_name(p_name):set_pos(arena_lib.get_random_spawner(arena, team_id_red))
end
end
for player_index in ipairs(players_team_blue) do
if players_team_blue[player_index] == p_name then
minetest.get_player_by_name(p_name):set_pos(arena_lib.get_random_spawner(arena, team_id_blue))
end
end
set_player_inventory(minetest.get_player_by_name(p_name))
minetest.get_player_by_name(p_name):set_hp(20)
end)
arena_lib.on_celebration("the_bridge", function(arena, winners)
remove_all_huds(arena)
end)
-- __________________
--__________________/Node Registration\____________
minetest.register_node("the_bridge:goal_area_red",{ minetest.register_node("the_bridge:goal_area_red",{
description = S("Red Goal"), description = S("Red Goal"),
drawtype = "glasslike", drawtype = "glasslike",
@ -86,3 +131,34 @@ minetest.register_node("the_bridge:void", {
drop = "", drop = "",
damage_per_second = 40, damage_per_second = 40,
}) })
minetest.register_tool("the_bridge:stonesword", {
description = S("Stone Sword"),
inventory_image = "default_tool_stonesword.png",
tool_capabilities = {
full_punch_interval = 1.2,
max_drop_level=0,
damage_groups = {fleshy=8},
},
})
minetest.register_tool("the_bridge:diapick", {
description = S("Diamond Pickaxe"),
inventory_image = "default_tool_diamondpick.png",
tool_capabilities = {
full_punch_interval = 0.9,
max_drop_level=3,
groupcaps={
cracky = {times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=0, maxlevel=3},
},
},
})
local gappleeat = minetest.item_eat(8,"")
minetest.register_craftitem("the_bridge:gapple",{
on_place = gappleeat,
on_secondary_use = gappleeat,
description = S("Golden Apple"),
inventory_image = "default_apple.png^[colorize:#ead535",
})