Disable damage for players with the creative priv (#40)
Co-authored-by: Maksim <MoNTE48@mail.ua>
This commit is contained in:
parent
f06952af92
commit
a4511b1a23
@ -44,3 +44,36 @@ function minetest.handle_node_drops(pos, drops, digger)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user