From 19ed0485c1034ca80ade9b2da8e280be10cd9b7a Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Tue, 20 Jun 2023 11:41:04 -0400 Subject: [PATCH] improve killme detection and feature sintax of code --- commands.lua | 42 ++++++++++++++++++++------------------- init.lua | 56 +++++++++++++++++++++++++++------------------------- mod.conf | 4 ++-- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/commands.lua b/commands.lua index b76f7e6..00231f1 100644 --- a/commands.lua +++ b/commands.lua @@ -11,27 +11,29 @@ ---------------------------------------------------------------------------- -minetest.register_chatcommand("killme", { - description = "Kill yourself to respawn", - func = function(name) - local player = minetest.get_player_by_name(name) - if player then - if minetest.settings:get_bool("enable_damage") and player:is_player() then - player:set_hp(0) - return true - else - for _, callback in pairs(core.registered_on_respawnplayers) do - if callback(player) then - return true +if not governing.modkillme then + minetest.register_chatcommand("killme", { + description = "Kill player or yourselft to respawn", + func = function(name) + local player = minetest.get_player_by_name(name) + if player then + if minetest.settings:get_bool("enable_damage") and player:is_player() then + player:set_hp(0) + return true + else + for _, callback in pairs(minetest.registered_on_respawnplayers) do + if callback(player) then + return true + end end + -- There doesn't seem to be a way to get a default spawn pos from the lua API + return false, "No static_spawnpoint defined" end - - -- There doesn't seem to be a way to get a default spawn pos from the lua API - return false, "No static_spawnpoint defined" + else + -- Show error message if used when not logged in, eg: from IRC mod + return false, "You need to be online to be killed!" end - else - -- Show error message if used when not logged in, eg: from IRC mod - return false, "You need to be online to be killed!" end - end -}) + }) +end + diff --git a/init.lua b/init.lua index b72c170..04d284a 100644 --- a/init.lua +++ b/init.lua @@ -12,39 +12,37 @@ ---------------------------------------------------------------------------- local modname = "governing" -local modpath = minetest.get_modpath(modname) +local modpath = minetest.get_modpath("governing") local modstor = minetest.get_mod_storage() local worlddir = minetest.get_worldpath() local modmail = minetest.get_modpath("mail") +local modgeoip = minetest.get_modpath("geoip") local moddefault = minetest.get_modpath("default") local modkillme = minetest.get_modpath("killme") local modcommand = minetest.get_modpath("game_commands") - - -if not killme_mod or not command_mod - +local modcreative = minetest.get_modpath("creative") local S if minetest.get_translator ~= nil then - S = minetest.get_translator(modname) -- 5.x translation function + S = minetest.get_translator(modname) -- 5.x translation function else - if minetest.get_modpath("intllib") then - dofile(minetest.get_modpath("intllib") .. "/init.lua") - if intllib.make_gettext_pair then - gettext, ngettext = intllib.make_gettext_pair() -- new gettext method - else - gettext = intllib.Getter() -- old text file method - end - S = gettext - else -- boilerplate function - S = function(str, ...) - local args = {...} - return str:gsub("@%d+", function(match) - return args[tonumber(match:sub(2))] - end) - end - end + if minetest.get_modpath("intllib") then + dofile(minetest.get_modpath("intllib") .. "/init.lua") + if intllib.make_gettext_pair then + gettext, ngettext = intllib.make_gettext_pair() -- new gettext method + else + gettext = intllib.Getter() -- old text file method + end + S = gettext + else -- boilerplate function + S = function(str, ...) + local args = {...} + return str:gsub("@%d+", function(match) + return args[tonumber(match:sub(2))] + end) + end + end end local creative_mode_cache = minetest.settings:get_bool("creative_mode") @@ -56,18 +54,22 @@ governing.modname = modname -- name of the mod governing.modpath = modpath -- path of the mod governing.modstor = modstor -- request of storage for the mod governing.worlddir = worlddir -- path of the world were the mod is running +governing.modgeoip = modgeoip -- path of the mail mod if available for sending messages internaly on private governing.modmail = modmail -- path of the mail mod if available for sending messages internaly on private governing.moddefault = moddefault -- path of default mod if availalbe governing.modkillme = modkillme -- if killme is present as mod if available governing.modcommand = modcommand -- if same killme and commands is present as mod if available function governing.is_creative(name) - return minetest.check_player_privs(name, {creative = true}) or creative_mode_cache + if creative then + return creative.is_creative(name) + else + return minetest.check_player_privs(name, {creative = true}) or creative_mode_cache + end end -if not goberning.modkillme and not goberning.moddefault then - dofile(goberning.modpath.."/commands.lua") -end +--dofile(governing.modpath.."/geoip.lua") +dofile(governing.modpath.."/commands.lua") -print("[MOD] governor mod loaded" ) +print("[MOD] governing mod loaded" ) diff --git a/mod.conf b/mod.conf index 9696f3c..9825a73 100644 --- a/mod.conf +++ b/mod.conf @@ -1,2 +1,2 @@ -name = goberning -depends = default +name = governing +optional_depends = default