TheBridge/the_bridge.lua

219 lines
6.9 KiB
Lua
Raw Normal View History

2022-10-03 12:30:47 +02:00
local S = minetest.get_translator("the_bridge")
2022-10-06 10:36:27 +02:00
local function set_player_inventory(player)
2022-10-12 16:33:42 +02:00
local stonestack = ItemStack("the_bridge:stone")
2022-10-06 10:36:27 +02:00
local pickstack = ItemStack("the_bridge:diapick")
local swordstack = ItemStack("the_bridge:stonesword")
local gapplestack = ItemStack("the_bridge:gapple 16")
2022-10-10 20:51:26 +02:00
local stickstack = ItemStack("the_bridge:knockback_stick")
2022-10-06 10:36:27 +02:00
local inv = player:get_inventory()
2022-10-12 16:33:42 +02:00
local hotbar = {swordstack,pickstack,gapplestack,stickstack,stonestack}
if minetest.get_modpath("grapple") then
table.insert(hotbar,ItemStack("grapple:grapple"))
end
2022-10-06 10:36:27 +02:00
inv:set_list("main", hotbar)
end
function after_goal(arena) --global because its called once outside of this file
restore_map(arena)
2022-10-09 21:19:33 +02:00
local players_team_red = arena_lib.get_players_in_team(arena, arena.team_id_red, true)
local players_team_blue = arena_lib.get_players_in_team(arena, arena.team_id_blue, true)
2022-10-03 12:30:47 +02:00
for player_index in ipairs(players_team_red) do
local player = players_team_red[player_index]
2022-10-06 10:36:27 +02:00
set_player_inventory(player)
2022-10-03 12:30:47 +02:00
player:set_hp(20)
2022-10-09 21:19:33 +02:00
player:set_pos(arena_lib.get_random_spawner(arena, arena.team_id_red))
2022-10-06 10:36:27 +02:00
update_huds(arena,player)
2022-10-06 22:12:37 +02:00
minetest.sound_play("ding", {
to_player = player:get_player_name(),
gain = 2.0,
})
2022-10-03 12:30:47 +02:00
end
for player_index in ipairs(players_team_blue) do
local player = players_team_blue[player_index]
2022-10-06 10:36:27 +02:00
set_player_inventory(player)
2022-10-03 12:30:47 +02:00
player:set_hp(20)
2022-10-09 21:19:33 +02:00
player:set_pos(arena_lib.get_random_spawner(arena, arena.team_id_blue))
2022-10-06 10:36:27 +02:00
update_huds(arena,player)
2022-10-06 22:12:37 +02:00
minetest.sound_play("ding", {
to_player = player:get_player_name(),
gain = 2.0,
})
2022-10-03 12:30:47 +02:00
end
if not arena.setup then return end
2022-10-22 20:24:00 +02:00
time = os.clock()
while (os.clock() < time +3) do end
arena.scoring = false
2022-10-03 12:30:47 +02:00
end
local goalfunc = function(pos, node, player)
if not player then return end
arena = arena_lib.get_arena_by_player(player:get_player_name())
if not arena then return end
nodename = node.name
if nodename == "the_bridge:goal_area_red" then
2022-10-22 20:24:00 +02:00
if arena.scoring then return end
2022-10-09 21:19:33 +02:00
local temp = arena.teams[arena.team_id_red].goals +1
arena.teams[arena.team_id_red].goals = temp
if temp > 4 and arena.in_game then
2022-10-06 10:36:27 +02:00
if arena.finished then return end
2022-10-09 21:19:33 +02:00
arena_lib.load_celebration("the_bridge", arena, arena.team_id_red)
2022-10-06 10:36:27 +02:00
arena.finished = true
2022-10-03 12:30:47 +02:00
return
end
after_goal(arena)
elseif nodename == "the_bridge:goal_area_blue" then
2022-10-22 20:24:00 +02:00
if arena.scoring then return end
2022-10-09 21:19:33 +02:00
local temp = arena.teams[arena.team_id_blue].goals +1
arena.teams[arena.team_id_blue].goals = temp
if temp > 4 and arena.in_game then
2022-10-06 10:36:27 +02:00
if arena.finished then return end
2022-10-09 21:19:33 +02:00
arena_lib.load_celebration("the_bridge", arena, arena.team_id_blue)
2022-10-06 10:36:27 +02:00
arena.finished = true
2022-10-03 12:30:47 +02:00
return
end
after_goal(arena)
end
end
2022-10-06 10:36:27 +02:00
arena_lib.on_death("the_bridge", function(arena, p_name, reason)
2022-10-09 21:19:33 +02:00
local players_team_red = arena_lib.get_players_in_team(arena, arena.team_id_red, false)
local players_team_blue = arena_lib.get_players_in_team(arena, arena.team_id_blue, false)
2022-10-06 10:36:27 +02:00
for player_index in ipairs(players_team_red) do
if players_team_red[player_index] == p_name then
2022-10-09 21:19:33 +02:00
minetest.get_player_by_name(p_name):set_pos(arena_lib.get_random_spawner(arena, arena.team_id_red))
2022-10-06 10:36:27 +02:00
end
end
for player_index in ipairs(players_team_blue) do
if players_team_blue[player_index] == p_name then
2022-10-09 21:19:33 +02:00
minetest.get_player_by_name(p_name):set_pos(arena_lib.get_random_spawner(arena, arena.team_id_blue))
2022-10-06 10:36:27 +02:00
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)
2022-10-03 12:30:47 +02:00
minetest.register_node("the_bridge:goal_area_red",{
description = S("Red Goal"),
drawtype = "glasslike",
tiles = {"^[colorize:#d9405e"},
paramtype = "light",
sunlight_propagates = true,
walkable = true,
pointable = false,
2022-10-03 12:30:47 +02:00
diggable = false,
buildable_to = false,
drop = "",
on_walk_over=goalfunc,
})
2022-10-08 21:38:14 +02:00
minetest.register_node("the_bridge:stone", {
description = S("Stone"),
tiles = {"default_stone.png"},
groups = {cracky = 3, stone = 1},
2022-10-08 21:40:48 +02:00
drop = "the_bridge:stone",
2022-10-08 21:38:14 +02:00
legacy_mineral = true,
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.above
2022-10-08 21:46:34 +02:00
minetest.set_node(pos , {name="the_bridge:stone"})
2022-10-08 21:38:14 +02:00
end
end,
on_dig = function(pos, node, digger)
2022-10-08 21:49:47 +02:00
minetest.remove_node(pos)
2022-10-08 21:38:14 +02:00
end,
})
2022-10-03 12:30:47 +02:00
minetest.register_node("the_bridge:goal_area_blue",{
description = S("Blue Goal"),
drawtype = "glasslike",
tiles = {"^[colorize:#3548da"},
paramtype = "light",
sunlight_propagates = true,
walkable = true,
2022-10-09 17:26:46 +02:00
pointable = true,
2022-10-03 12:30:47 +02:00
diggable = false,
buildable_to = false,
drop = "",
on_walk_over=goalfunc,
})
minetest.register_node("the_bridge:void", {
description = S("The Bridge void"),
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = true,
2022-10-09 17:26:46 +02:00
pointable = true,
2022-10-03 12:30:47 +02:00
diggable = false,
buildable_to = false,
drop = "",
2022-10-07 15:20:15 +02:00
on_walk_over=function(pos, node, player)
player:set_hp(0)
end,
2022-10-03 12:30:47 +02:00
})
2022-10-06 10:36:27 +02:00
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={
2022-10-09 21:19:33 +02:00
cracky = {times={[1]=2.0, [2]=1.0, [3]=1.0}, uses=0, maxlevel=3},
2022-10-06 10:36:27 +02:00
},
},
})
2022-10-09 21:19:33 +02:00
local gappleeat = minetest.item_eat(6,"")
2022-10-06 10:36:27 +02:00
minetest.register_craftitem("the_bridge:gapple",{
on_place = gappleeat,
on_secondary_use = gappleeat,
2022-10-09 12:05:31 +02:00
on_use=gappleeat,
2022-10-06 10:36:27 +02:00
description = S("Golden Apple"),
inventory_image = "default_apple.png^[colorize:#ead535",
2022-10-07 15:20:15 +02:00
})
2022-10-09 21:19:33 +02:00
minetest.register_craftitem("the_bridge:knockback_stick",{
inventory_image = "default_stick.png",
on_use = function(itemstack, user, pointed_thing) --parts of the code inside of this function are from https://gitlab.com/zughy-friends-minetest/sumo/-/blob/master/items.lua
if not pointed_thing then return end
if not minetest.is_player(pointed_thing.ref) then return end
dir = user:get_look_dir()
2022-10-22 18:50:58 +02:00
vel_vector = vector.multiply(dir,12)
2022-10-22 20:25:10 +02:00
vel_vector.y = 0.5 --hardcoded so you cant launch a player up like 20 blocks
2022-10-22 18:45:15 +02:00
pointed_thing.ref:add_player_velocity(vel_vector)
2022-10-09 21:19:33 +02:00
end,
})