Imported from trollstream "ContentDB"
commit
43fe93c5d6
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Coder12
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,14 @@
|
|||
# death_timer
|
||||
This mod adds a spawn cooldown for players. on death and respawn the player will be held in place by a entity, the player will be hidden, interact will be revoked, and also if the player leaves they will not be able to rejoin on till the countdown is over.
|
||||
|
||||
Feature list:
|
||||
- Players are forced to wait an amount of time on re-spawn.
|
||||
- On death players are cloaked and their interact privilege is removed.
|
||||
- Players are held in place by a entity.
|
||||
- Temp death bans on players that leave and try to rejoin when the countdown is still going.
|
||||
|
||||
# config
|
||||
The respawn cooldown.
|
||||
```
|
||||
death_timer.timeout = 8
|
||||
```
|
|
@ -0,0 +1,154 @@
|
|||
local death_timer = {}
|
||||
local players = {}
|
||||
|
||||
local timeout = tonumber(minetest.settings:get("death_timer.timeout")) or 8
|
||||
local cloaking_mod = minetest.global_exists("cloaking")
|
||||
|
||||
function death_timer.show(player, name)
|
||||
if not cloaking_mod then
|
||||
local p = players[name]
|
||||
if p and p.properties then
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
local props = p.properties
|
||||
player:set_properties({
|
||||
visual_size = props.visual_size,
|
||||
["selectionbox"] = props["selectionbox"],
|
||||
})
|
||||
end
|
||||
p.properties = nil
|
||||
players[name] = p
|
||||
end
|
||||
elseif minetest.get_player_by_name(name) then
|
||||
cloaking.unhide_player(name)
|
||||
end
|
||||
end
|
||||
function death_timer.hide(player, name)
|
||||
if not cloaking_mod then
|
||||
if not players[name].properties then
|
||||
players[name].properties = player:get_properties()
|
||||
end
|
||||
player:set_properties({
|
||||
visual_size = {x = 0, y = 0},
|
||||
["selectionbox"] = {0, 0, 0, 0, 0, 0},
|
||||
})
|
||||
else
|
||||
cloaking.hide_player(name)
|
||||
end
|
||||
end
|
||||
function death_timer.create_deathholder(player, name)
|
||||
local obj = players[name].obj
|
||||
if not obj then
|
||||
obj = minetest.add_entity({x = 0, y = 0, z = 0}, "death_timer:death")
|
||||
end
|
||||
if player then
|
||||
player:set_attach(obj, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
obj:get_luaentity().owner = name
|
||||
obj:set_pos(player:get_pos())
|
||||
players[name].obj = obj
|
||||
end
|
||||
end
|
||||
function death_timer.formspec(name, text)
|
||||
local formspec = "size[11,5.5]bgcolor[#320000b4;true]" ..
|
||||
"label[5.15,1.35;Wait" ..
|
||||
"]button_exit[4,3;3,0.5;death_button;" .. text .."]"
|
||||
minetest.show_formspec(name, "death_timer:death_screen", formspec)
|
||||
end
|
||||
|
||||
minetest.register_entity("death_timer:death", {
|
||||
is_visible = false,
|
||||
on_step = function(self, dtime)
|
||||
self.timer= self.timer + dtime
|
||||
if self.timer >= 10 then
|
||||
self.timer = 0
|
||||
if not (self.owner and minetest.get_player_by_name(self.owner)) then
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_activate = function(self, staticdata)
|
||||
self.timer = 0
|
||||
self.object:set_armor_groups({immortal = 1, ignore = 1, do_not_delete = 1})
|
||||
end
|
||||
})
|
||||
|
||||
function death_timer.create_loop(player, name)
|
||||
if not players[name].loop then
|
||||
players[name].loop = true
|
||||
death_timer.loop(player, name)
|
||||
end
|
||||
end
|
||||
function death_timer.loop(player, name)
|
||||
local p = players[name]
|
||||
if not p.time or p.time < 1 then
|
||||
death_timer.show(player, name)
|
||||
death_timer.formspec(name, "Play")
|
||||
local obj = p.obj
|
||||
if obj then
|
||||
obj:set_detach()
|
||||
obj:remove()
|
||||
obj = nil
|
||||
end
|
||||
if p.interact then
|
||||
local privs = minetest.get_player_privs(name)
|
||||
privs.interact = p.interact
|
||||
minetest.set_player_privs(name, privs)
|
||||
end
|
||||
players[name] = nil
|
||||
elseif p then
|
||||
p.time = p.time - 1
|
||||
death_timer.formspec(name, p.time)
|
||||
minetest.after(1, death_timer.loop, player, name)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_prejoinplayer(function(name, ip)
|
||||
local p = players[name]
|
||||
if p and p.time and p.time > 0 then
|
||||
return "You have to wait out the death ban for " .. p.time .. " seconds."
|
||||
end
|
||||
end)
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if players[name] and players[name].obj then
|
||||
players[name].obj:set_detach()
|
||||
players[name].obj:remove()
|
||||
players[name].obj = nil
|
||||
end
|
||||
end)
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local p = players[name]
|
||||
local privs = minetest.get_player_privs(name)
|
||||
if not p then
|
||||
p = {time = timeout}
|
||||
else
|
||||
p.time = timeout
|
||||
end
|
||||
p.interact = privs.interact
|
||||
players[name] = p
|
||||
death_timer.hide(player, name)
|
||||
privs.interact = nil
|
||||
minetest.set_player_privs(name, privs)
|
||||
end)
|
||||
minetest.register_on_mods_loaded(function()
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
if player:get_hp() < 1 or not players[name] then
|
||||
return
|
||||
end
|
||||
minetest.after(0, function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
death_timer.create_deathholder(player, name)
|
||||
minetest.after(1, death_timer.create_loop, player, name)
|
||||
end, name)
|
||||
end)
|
||||
end)
|
||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||
local p = players[player:get_player_name()]
|
||||
if p and p.time and p.time > 1 then
|
||||
return 100
|
||||
end
|
||||
return hp_change
|
||||
end, true)
|
|
@ -0,0 +1,3 @@
|
|||
name = death_timer
|
||||
description = This mod will force players to wait when they die.
|
||||
optional_depends = cloaking
|
|
@ -0,0 +1,2 @@
|
|||
# The respawn cooldown.
|
||||
death_timer.timeout (Timeout) int 8
|
Loading…
Reference in New Issue