tnttag-cd2025/auto.lua
2022-10-05 19:47:57 +02:00

120 lines
3.5 KiB
Lua

local S = minetest.get_translator("tnttag")
function tnttag.add_tnthead(p_name)
local player = minetest.get_player_by_name(p_name)
if player then
local tnthead = minetest.add_entity(player:get_pos(), "tnttag:tnt_if_tagged", nil)
tnthead:set_attach(player, "Head", {x=0, y=10, z=0})
tnthead.p_name = p_name
end
end
function tnttag.remove_tnthead(p_name)
local player = minetest.get_player_by_name(p_name)
if player then
local children = player:get_children()
for _,child in pairs(hildren) do
if child:get_luaentity().name == "tnttag:tnt_if_tagged" then
child:remove()
end
end
end
end
function tnttag.newwave(arena)
local new_tagger
local real_new_tagger = {}
arena.current_wave = arena.current_wave+1
tnttag.update_wave_counter_hud(arena)
local p_count = 0
for _ in pairs(arena.players) do
p_count = p_count + 1
end
if arena.current_wave == arena.waves then
new_tagger = tnttag.get_new_tagger_count(arena, p_count-1)
else
new_tagger = tnttag.get_new_tagger(arena, 0.4)
end
local count = 0
for _, p_name in pairs(new_tagger) do
if p_count-count > (arena.waves-arena.current_wave)+1 then --für die bessere lessbarkeit/for better readability
tnttag.tagplayer(p_name, arena)
table.insert(real_new_tagger, p_name)
count = count + 1
end
end
for p_name,_ in pairs(arena.players) do
player = minetest.get_player_by_name(p_name)
player:set_pos(arena_lib.get_random_spawner(arena, arena.players[p_name]))--WARNING: Tagged and Untagged player on same spawn-point
minetest.chat_send_player(p_name, table.concat(real_new_tagger,", ").." are new tagger!")
end
end
function tnttag.pause(arena)--future
end
arena_lib.on_load("tnttag", function(arena)
arena.original_player_amount = arena.players_amount
for p_name, stats in pairs(arena.players) do
tnttag.generate_HUD(arena, p_name)
arena.players[p_name].tnt_if_tagged = minetest.add_entity(minetest.get_player_by_name(p_name):get_pos(), "tnttag:tnt_if_tagged", nil)
arena.players[p_name].tnt_if_tagged:set_attach(minetest.get_player_by_name(p_name), "Head", {x=0, y=10, z=0})
end
end)
arena_lib.on_start("tnttag", function(arena)
arena.current_time = arena.wavetime*arena.waves
tnttag.newwave(arena)
end)
arena_lib.on_quit("tnttag", function(arena, p_name, is_spectator, reason)
if not is_spectator then
--arena.players[p_name].tnt_if_tagged:remove()
tnttag.remove_HUD(arena, p_name)
end
end)
arena_lib.on_eliminate("tnttag", function(arena, p_name)
--arena.players[p_name].tnt_if_tagged:remove()
tnttag.remove_HUD(arena, p_name)
end)
arena_lib.on_celebration("tnttag", function(arena, winner)
arena.current_time = 0
arena.players[winner].tnt_if_tagged:remove()
tnttag.remove_HUD(arena, winner)
end)
arena_lib.on_time_tick("tnttag", function(arena)
tnttag.update_wave_timer_hud(arena)
if arena.current_time%arena.wavetime == 0 then
for p_name in pairs(arena.players) do
if arena.players[p_name].tagged then
explode_player(p_name, arena)
end
end
tnttag.newwave(arena)
end
end)
arena_lib.on_timeout("tnttag", function(arena)
for p_name in pairs(arena.players) do
if arena.players[p_name].tagged then
explode_player(p_name, arena)
end
end
end)
function explode_player(p_name, arena)
arena_lib.HUD_send_msg("title", p_name, "You exploded!",1, nil--[[sound?]], 0xFF3300)
arena_lib.remove_player_from_arena(p_name, 1)
for pl_name,_ in pairs(arena.players) do
minetest.chat_send_player(pl_name,p_name.." exploded!")
end
end
--arena_lib.is_player_in_queue(player, "tnttag")
--arena_lib.get_arena_by_player(player)