Disable damage for players with the creative priv (#40)

Co-authored-by: Maksim <MoNTE48@mail.ua>
This commit is contained in:
luk3yx 2022-05-21 07:53:29 +12:00 committed by Maksim
parent f06952af92
commit a4511b1a23

View File

@ -44,3 +44,36 @@ function minetest.handle_node_drops(pos, drops, digger)
end end
end end
end end
-- Disable damage for players with creative mode
if minetest.settings:get_bool("enable_damage") then
local function set_player_immortal(player, immortal)
local groups = player:get_armor_groups()
groups.immortal = immortal and 1 or nil
player:set_armor_groups(groups)
end
minetest.register_on_joinplayer(function(player)
if minetest.check_player_privs(player, "creative") then
set_player_immortal(player, true)
end
end)
minetest.register_on_priv_grant(function(name, _, priv)
if priv ~= "creative" then return true end
local player = minetest.get_player_by_name(name)
if player then
set_player_immortal(player, true)
end
return true
end)
minetest.register_on_priv_revoke(function(name, _, priv)
if priv ~= "creative" then return true end
local player = minetest.get_player_by_name(name)
if player then
set_player_immortal(player, false)
end
return true
end)
end