Display when cheats are enabled on-screen

Without this, some players are likely to enable
certain privs and abilities without knowing that
they're cheats and will break the designed
gameplay.  Similarly, server admins may be likely
to use the same default_privs for a nodecore server
as they might for an MTG or even creative server,
causing accidental cheating as well.  Adding this
messages makes it hard to be unaware that your
game is at least misconfigured.
This commit is contained in:
Aaron Suen 2021-06-23 22:46:07 -04:00
parent 568a5be648
commit bf8d8e5877
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,50 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore, pairs
= minetest, nodecore, pairs
-- LUALOCALS > ---------------------------------------------------------
local cheatmsg = nodecore.translate("CHEATS ENABLED")
local cheats = {
fly = true,
bring = true,
teleport = true,
pulverize = true,
noclip = true,
fast = true,
ncdqd = true,
give = true,
["debug"] = true,
basic_debug = true,
keepinv = true
}
local function privcheck(player)
local cheating
local privs = minetest.get_player_privs(player:get_player_name())
for k in pairs(cheats) do
cheating = cheating or privs[k]
end
nodecore.hud_set(player, {
label = "cheats",
hud_elem_type = "text",
position = {x = 0.5, y = 1},
text = cheating and cheatmsg or "",
number = 0xFF00C0,
alignment = {x = 0, y = -1},
offset = {x = 0, y = -4}
})
end
local function privcheck_delay(name)
minetest.after(0, function()
local player = minetest.get_player_by_name(name)
return player and privcheck(player)
end)
end
minetest.register_on_priv_grant(privcheck_delay)
minetest.register_on_priv_revoke(privcheck_delay)
minetest.register_on_joinplayer(function(player)
return privcheck_delay(player:get_player_name())
end)

View File

@ -10,4 +10,5 @@ include("breath")
include("hotbar")
include("touchtip")
include("pretrans")
include("cheats")
include("hints")