The death screen can be customized to remove the respawn button. You could count the number of deaths and simply don't show it when the number exceeds a maximum.
I don't think you can prevent saving, but you can prevent reloading... kind of. There is no clean way to do this, but it could be achieved by scripting and using the database. I'd do the following:
- In the starting area of the module generate a unique ID (some long random number will do). This will be unique for each session or play-through (i.e same across multiple saves)
- The ID needs to be saved on the module (or alternatively on the player character) as a local variable. (SetLocalInt)
- In the database you need to create a entry: ID = number of deaths. (SetCampaignInt)
- Each time a player dies increment the number of deaths and save it in the database
- When the player attempts to reload a previous save, check the number of saves in the database for this session. If it exceeds your maximum, just kill him or teleport him into a separate area where he can't do anything.
This way the player can save and reload normally as long as he hasn't reached the max number of deaths. He can also start a new game with the same character because a new ID will be assigned in the starting area.
Thought about this a bit more.
Concept is interesting. Limit number of deaths in singleplayer as well.
However this won't be any more effective than write in module description "You can die max 5 times in this module, if you die more times game is over."
Naturally, the load game function must be available.Mainly because player should not be expected to finish your module in one session. Second because player can get stuck/bugged or something.
And if loading is possible, then player can load game before he dies bypassing your concept entirely. Oh, I am going to die, reload.
If player doesn't want to follow the module rules, and in this case its very likely to happen because if player played module 2 hours and then just dies before end, he is not going to play it again from start, then he will simply not follow the rules and cheat. Whether he deteles database or load game before he dies doesn't matter.
So this won't work and module builder needs to plan around this. If you want to add extra difficulty by limiting how many times players dies, do it the other way around. Instead of ending module if players respawn 5 times, create a "perfection" achievement in the end of the module which will be calculated from how many times player died. Even then, player can cheat it obviously, but it will be less desired and builder doesn't have to worry about it too.