From f89780695e3f078e82db5edc023c52820815ec19 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 24 May 2022 17:41:18 +0200 Subject: [PATCH] Add /gamemode command for per player gamemode --- mods/HUD/mcl_inventory/init.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index f2cb2e523..fd3d39799 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -177,7 +177,35 @@ minetest.register_on_joinplayer(function(player) return_fields(player, "enchanting_lapis") end) -if minetest.is_creative_enabled("") then - dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") + +dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") + +local mt_is_creative_enabled = minetest.is_creative_enabled + +function minetest.is_creative_enabled(name) + if mt_is_creative_enabled(name) then return true end + local p = minetest.get_player_by_name(name) + if p then + return p:get_meta():get_string("gamemode_creative") == "true" + end + return false end +minetest.register_chatcommand("gamemode",{ + privs = { server = true }, + func = function(n,param) + local p = minetest.get_player_by_name(n) + if not p then return end + local m = p:get_meta() + local gm = "survival" + if param == "creative" then + m:set_string("gamemode_creative","true") + gm = "creative" + set_inventory(p) + elseif param == "survival" then + m:set_string("gamemode_creative","") + set_inventory(p) + end + minetest.chat_send_player(n,S("Gamemode for player ")..n..S(": "..gm)) + end +})