if srb2p return end

addHook("PlayerThink", function(player)
	if player.mo and player.mo.skin == "mecha"
	and player.mo.valid
	and not (player.powers[pw_carry] == CR_NIGHTSMODE)
		if player.playerstate == PST_LIVE
			if player.mo.mechalives == nil
				player.mo.mechalives = 8
			end
			if player.mo.mechalives <= 0
				S_StopSound(player.mo)
				P_KillMobj(player.mo)
			end
			if player.mo.mechalives > 8
				player.mo.mechalives = 8
			end
			if player.powers[pw_super]
			and player.mo.mechalives < 8
				player.mo.mechalives = $1 + 1
			end
		elseif player.playerstate == PST_DEAD
			if player.mo.mechalives == nil
				player.mo.mechalives = 0
			end
			if player.mo.mechalives > 0
				player.mo.mechalives = 0
			end
		end
	end
end)

addHook("MobjDamage", function(mo, inf, source)
	if mo and mo.skin == "mecha"
	and mo.player
	and mo.player.playerstate == PST_LIVE
	and not (mo.player.powers[pw_carry] == CR_NIGHTSMODE)
	and not mo.player.powers[pw_shield] //With shield Damage is not work!
		if inf
		and inf.valid
		end
		if mo.player.rings > 0
			mo.mechalives = $1 - 1
		else
			mo.mechalives = $1 - 1
			P_DoPlayerPain(mo.player, source, inf)
			P_PlayerWeaponPanelOrAmmoBurst(mo.player)
			P_PlayerEmeraldBurst(mo.player)
			P_PlayerFlagBurst(mo.player)
			P_PlayRinglossSound(mo)
			if source
			and source.valid
			and source.player
				P_AddPlayerScore(source.player, 50)
			end
			return true
		end
	end
end, MT_PLAYER)

local function hudstuff(v, player, cam)
	if (player.mo and player.mo.skin == "mecha" and player.mo.mechalives != nil)
		v.drawString(32, 168, "Boss's Lives: " + player.mo.mechalives, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_REDMAP)
		v.drawFill(32, 256, player.mo.mechalives/3, 32)
	end
end

hud.add(hudstuff, player)