sumo-cd2025/minigame_manager.lua
MisterE123 27f69735ac remove death from game
A survival server that was interested in having this game pointed out that death is expensive in survival. So I removed death from the game with a hp_change modifier. If the damage applied while in game would not cause death, then it is applied as normal. If it would cause death, then full health is restored, but the player is eliminated. A benefit of this approach is that the player no longer needs to see the you died message which really is not appropriate for this type of game.
2021-01-28 16:35:34 +00:00

158 lines
4.4 KiB
Lua

local function send_message(arena,num_str)
arena_lib.HUD_send_msg_all("title", arena, num_str, 1,nil,0xFF0000)
--arena_lib.HUD_send_msg_all(HUD_type, arena, msg, <duration>, <sound>, <color>)
end
arena_lib.on_load("sumo", function(arena)
send_message(arena,'3')
minetest.after(1, function(arena)
send_message(arena,'2')
minetest.after(1, function(arena)
send_message(arena,'1')
local item = ItemStack("sumo:pushstick")
for pl_name, stats in pairs(arena.players) do
local player = minetest.get_player_by_name(pl_name)
player:get_inventory():set_stack("main", 1, item)
local message = 'Controls: '..
minetest.colorize('Red', '[Punch]: ')..
minetest.colorize('Green', 'Push other players ')..
minetest.colorize('Red', '[Punch]+[Aux1 (e)]: ')..
minetest.colorize('Green', 'Exchange places ')..
minetest.colorize('Red', '[Punch]+[Sneak]: ')..
minetest.colorize('Green', 'Push harder ')..
minetest.colorize('Red', '[Place]: ')..
minetest.colorize('Green', 'Vault ')..
minetest.colorize('Red', '[Place]+[Aux1 (e)]: ')..
minetest.colorize('Green', '2 sec speed boost. ') ..
'Cooldowns Apply!'
minetest.chat_send_player(pl_name,message)
end
minetest.after(1, function(arena)
arena_lib.HUD_send_msg_all("title", arena, "Fight!", 1,nil,0x00FF00)
end, arena)
end, arena)
end, arena)
end)
--this is necessary beacuse it is required by arena_lib for timed games
arena_lib.on_time_tick('sumo', function(arena)
if arena.in_game and not arena.in_celebration then
local c = 0x00FF00
if arena.current_time < 60 then
c = 0xFFFF00
end
if arena.current_time < 10 then
c = 0xFF0000
end
if arena.current_time < arena.initial_time - 5 then
arena_lib.HUD_send_msg_all('hotbar', arena, arena.current_time, 1,nil,c)
end
end
end)
minetest.register_on_player_hpchange(function(player, hp_change)
local pl_name = player:get_player_name()
if arena_lib.is_player_in_arena(pl_name, 'sumo') then
local arena = arena_lib.get_arena_by_player(pl_name)
local hp = player:get_hp()
if arena.in_celebration then --protect winners from damage
return 0
end
if hp + hp_change <= 0 then --dont ever kill players, but if a damage *would* kill them, then eliminate them, and set their health back to normal
arena_lib.HUD_hide('hotbar', p_name)
arena_lib.remove_player_from_arena(pl_name, 1)
player:set_hp(20)
return 0
else
return hp_change --if it would not kill players then apply damage as normal
end
else
return hp_change
end
end, true)
--if the game times out
arena_lib.on_timeout('sumo', function(arena)
local winner_names = {}
for p_name, p_stats in pairs(arena.players) do
table.insert(winner_names, p_name)
end
arena_lib.load_celebration('sumo', arena, winner_names)
end)
arena_lib.on_death('sumo', function(arena, p_name, reason)
arena_lib.HUD_hide('hotbar', p_name)
if not arena.in_celebration then
arena_lib.remove_player_from_arena(p_name, 1)
end
end)
arena_lib.on_celebration('sumo', function(arena, winner_name)
arena_lib.HUD_hide('hotbar', arena)
end)
arena_lib.on_quit('sumo', function(arena, pl_name, is_forced)
arena_lib.HUD_hide('hotbar', pl_name)
end)
arena_lib.on_eliminate('sumo', function(arena, p_name)
minetest.sound_play('sumo_lose', {
to_player = p_name,
gain = 2.0,
})
--minetest.chat_send_all(dump(arena))
local count = 0
local sound = 'sumo_elim'
for p_name,data in pairs(arena.players) do
count = count + 1
end
if count == 1 then
sound = 'sumo_win'
end
for p_name, stats in pairs(arena.players) do
minetest.sound_play(sound, {
to_player = p_name,
gain = 2.0,
})
end
end)
--remove stick if in inv when joinplayer
minetest.register_on_joinplayer(function(player)
local inv = player:get_inventory()
local stack = ItemStack("sumo:pushstick")
local taken = inv:remove_item("main", stack)
end)