Add MC version of Random_messages mod

master
MoNTE48 2021-11-23 01:33:24 +02:00
parent 5218684993
commit dc802d5481
6 changed files with 295 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# RandomMessages mod
Put your messages in (world directory)/random_messages,1 message per line.
Messages can be all kinds of hints, mod usage, etc.
Add/Remove messages on the fly:
/random_messages viewmessages
to see all the messages.
/random_messages addmessage blah blah blah
to add the random message blah blah blah
/random_messages removemessage 2
to remove the 2nd random message in /random_messages viewmessages
In minetest.conf, random_messages_interval decides how often a message is sent.
License: MIT.
Special thanks to:
Michael Rasmussen (michael@jamhome.us)
Enjoy it! ^_^
arsdragonfly@gmail.com
6/19/2013
Patched by MultiCraft Development Team.

177
random_messages/init.lua Normal file
View File

@ -0,0 +1,177 @@
--[[
RandomMessages mod by arsdragonfly.
arsdragonfly@gmail.com
6/19/2013
]]
local modpath = minetest.get_modpath("random_messages")
-- Time between two subsequent messages.
local MESSAGE_INTERVAL = 0
-- Added default messages file
local default_messages_file = "default_random_messages"
math.randomseed(os.time())
random_messages = {}
random_messages.messages = {} -- This table contains all messages.
-- Intllib
local S = intllib.make_gettext_pair()
local worldpath = minetest.get_worldpath()
local random_messages_path = worldpath .. "/random_messages"
function random_messages.initialize() -- Set the interval in minetest.conf.
minetest.settings:set("random_messages_interval", 120)
minetest.settings:write()
return 120
end
-- Read the interval from minetest.conf (set it if it doesn'st exist)
function random_messages.set_interval(delay)
if delay then
MESSAGE_INTERVAL = delay
minetest.settings:set("random_messages_interval", delay)
minetest.settings:write()
return
end
MESSAGE_INTERVAL =
tonumber(minetest.settings:get("random_messages_interval")) or
random_messages.initialize()
end
function random_messages.check_params(name, func, params)
local stat, msg = func(params)
if not stat then
minetest.chat_send_player(name,msg)
return false
end
return true
end
function random_messages.read_messages()
local line_number = 1
-- define input
local input = io.open(random_messages_path, "r")
-- no input file found
if not input then
-- look for default file
local default_input = io.open(modpath .. "/" .. default_messages_file, "r")
local output = io.open(random_messages_path, "w")
if not default_input then
-- blame the admin if not found
output:write(S("Blame the server admin! He has probably not edited the random messages yet.\n"))
output:write(S("Tell your admin that this line is in (worldpath)/random_messages\n"))
else
-- or write default_input content in worldpath message file
local content = default_input:read("*all")
output:write(content)
end
io.close(output)
if default_input then
io.close(default_input)
end
input = io.open(random_messages_path, "r")
end
-- we should have input by now, so lets read it
for line in input:lines() do
random_messages.messages[line_number] = line
line_number = line_number + 1
end
io.close(input)
end
function random_messages.display_message(message_number)
local msg = random_messages.messages[message_number] or message_number
if msg then
local C = default.colors
msg = C.ruby .. S("Server") .. C.white .. ": " .. C.gold .. msg
minetest.chat_send_all(msg)
end
end
function random_messages.show_message()
random_messages.display_message(math.random(#random_messages.messages))
end
function random_messages.list_messages()
local str = ""
for k, v in pairs(random_messages.messages) do
str = str .. k .. " | " .. v .. "\n"
end
return str
end
function random_messages.remove_message(k)
table.remove(random_messages.messages,k)
random_messages.save_messages()
end
function random_messages.add_message(t)
table.insert(random_messages.messages, table.concat(t, " ", 2))
random_messages.save_messages()
end
function random_messages.save_messages()
local output = io.open(random_messages_path, "w")
for _, v in pairs(random_messages.messages) do
output:write(v .. "\n")
end
io.close(output)
end
-- When server starts:
random_messages.set_interval()
random_messages.read_messages()
local TIMER = 0
if random_messages.messages[1] then
minetest.register_globalstep(function(dtime)
TIMER = TIMER + dtime
if TIMER > MESSAGE_INTERVAL then
random_messages.show_message()
TIMER = 0
end
end)
end
minetest.register_chatcommand("random_messages", {
params = S("list | remove <number> | add <message>"),
privs = {moderator = true},
description = S("View an change the server's random messages"),
func = function(name, param)
local t = string.split(param, " ")
if t[1] == "list" then
minetest.chat_send_player(name, random_messages.list_messages())
elseif t[1] == "remove" then
local number = tonumber(t[2])
if not number or random_messages.messages[number] == nil then
return false, S("ERROR: No such message.")
end
random_messages.remove_message(t[2])
return true, S("Message removed.")
elseif t[1] == "add" then
if not t[2] then
minetest.chat_send_player(name, S("ERROR: No message."))
else
random_messages.add_message(t)
return true, S("Message added.")
end
elseif t[1] == "delay" then
local number = tonumber(t[2])
if not number then
minetest.chat_send_player(name, S("ERROR: Can't set delay."))
else
random_messages.set_interval(number)
return true, S("Delay changed.")
end
else
minetest.chat_send_player(name, S("ERROR: Invalid command."))
end
end
})
minetest.register_chatcommand_alias("rmsg", "random_messages")

View File

@ -0,0 +1,50 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-08-04 15:04+0200\n"
"PO-Revision-Date: 2017-08-04 15:05+0200\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.12\n"
"Last-Translator: fat115 <fat115@framasoft.org>\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Language: fr\n"
#: init.lua
msgid ""
"Blame the server admin! He/She has probably not edited the random messages "
"yet.\n"
msgstr ""
"Tirez les oreilles à l'administrateur du serveur. Il/elle n'a pas encore "
"modifié les messages aléatoires.\n"
#: init.lua
msgid ""
"Tell your dumb admin that this line is in (worldpath)/random_messages\n"
msgstr ""
"Dites à votre administrateur à la noix que cette ligne se trouve dans "
"(worldpath)/random_messages\n"
#: init.lua
msgid "View and/or alter the server's random messages"
msgstr "Afficher et/ou modifier les messages aléatoires du serveur"
#: init.lua
msgid "ERROR: No such message."
msgstr "ERREUR : ce message est inexistant."
#: init.lua
msgid "ERROR: No message."
msgstr "ERREUR : pas de message."
#: init.lua
msgid "ERROR: Invalid command."
msgstr "ERREUR : Commande invalide."

View File

@ -0,0 +1,2 @@
# textdomain: dye
Server:=Сервер:

View File

@ -0,0 +1,44 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-08-04 15:04+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: init.lua
msgid ""
"Blame the server admin! He/She has probably not edited the random messages "
"yet.\n"
msgstr ""
#: init.lua
msgid "Tell your dumb admin that this line is in (worldpath)/random_messages\n"
msgstr ""
#: init.lua
msgid "View and/or alter the server's random messages"
msgstr ""
#: init.lua
msgid "ERROR: No such message."
msgstr ""
#: init.lua
msgid "ERROR: No message."
msgstr ""
#: init.lua
msgid "ERROR: Invalid command."
msgstr ""

1
random_messages/mod.conf Normal file
View File

@ -0,0 +1 @@
name = random_messages