mirror of
https://github.com/arsdragonfly/random_messages.git
synced 2025-06-30 15:10:53 +02:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
bbbccb401c |
0
README.txt
Normal file → Executable file
0
README.txt
Normal file → Executable file
62
init.lua
Normal file → Executable file
62
init.lua
Normal file → Executable file
@ -5,27 +5,12 @@ arsdragonfly@gmail.com
|
|||||||
--]]
|
--]]
|
||||||
--Time between two subsequent messages.
|
--Time between two subsequent messages.
|
||||||
local MESSAGE_INTERVAL = 0
|
local MESSAGE_INTERVAL = 0
|
||||||
-- Added default messages file
|
|
||||||
local default_messages_file = "default_random_messages"
|
|
||||||
|
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
random_messages = {}
|
random_messages = {}
|
||||||
random_messages.messages = {} --This table contains all messages.
|
random_messages.messages = {} --This table contains all messages.
|
||||||
|
|
||||||
local S
|
|
||||||
if minetest.get_translator ~= nil then
|
|
||||||
S = minetest.get_translator("random_messages")
|
|
||||||
else
|
|
||||||
S = function(str, ...)
|
|
||||||
local args={...}
|
|
||||||
return str:gsub(
|
|
||||||
"@%d+",
|
|
||||||
function(match) return args[tonumber(match:sub(2))] end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function table.count( t )
|
function table.count( t )
|
||||||
local i = 0
|
local i = 0
|
||||||
for k in pairs( t ) do i = i + 1 end
|
for k in pairs( t ) do i = i + 1 end
|
||||||
@ -41,8 +26,14 @@ function table.random( t )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function random_messages.initialize() --Set the interval in minetest.conf.
|
||||||
|
minetest.setting_set("random_messages_interval",120)
|
||||||
|
minetest.setting_save();
|
||||||
|
return 120
|
||||||
|
end
|
||||||
|
|
||||||
function random_messages.set_interval() --Read the interval from minetest.conf(set it if it doesn'st exist)
|
function random_messages.set_interval() --Read the interval from minetest.conf(set it if it doesn'st exist)
|
||||||
MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval") or 120)
|
MESSAGE_INTERVAL = tonumber(minetest.setting_get("random_messages_interval")) or random_messages.initialize()
|
||||||
end
|
end
|
||||||
|
|
||||||
function random_messages.check_params(name,func,params)
|
function random_messages.check_params(name,func,params)
|
||||||
@ -56,28 +47,14 @@ end
|
|||||||
|
|
||||||
function random_messages.read_messages()
|
function random_messages.read_messages()
|
||||||
local line_number = 1
|
local line_number = 1
|
||||||
-- define input
|
|
||||||
local input = io.open(minetest.get_worldpath().."/random_messages","r")
|
local input = io.open(minetest.get_worldpath().."/random_messages","r")
|
||||||
-- no input file found
|
|
||||||
if not input then
|
if not input then
|
||||||
-- look for default file
|
|
||||||
local default_input = io.open(minetest.get_modpath("random_messages").."/"..default_messages_file,"r")
|
|
||||||
local output = io.open(minetest.get_worldpath().."/random_messages","w")
|
local output = io.open(minetest.get_worldpath().."/random_messages","w")
|
||||||
if not default_input then
|
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n")
|
||||||
-- blame the admin if not found
|
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n")
|
||||||
output:write(S("Blame the server admin! He/She has probably not edited the random messages yet.").."\n")
|
|
||||||
output:write(S("Tell your dumb admin that this line is in (worldpath)/random_messages").."\n")
|
|
||||||
return
|
|
||||||
else
|
|
||||||
-- or write default_input content in worldpath message file
|
|
||||||
local content = default_input:read("*all")
|
|
||||||
output:write(content)
|
|
||||||
end
|
|
||||||
io.close(output)
|
io.close(output)
|
||||||
io.close(default_input)
|
|
||||||
input = io.open(minetest.get_worldpath().."/random_messages","r")
|
input = io.open(minetest.get_worldpath().."/random_messages","r")
|
||||||
end
|
end
|
||||||
-- we should have input by now, so lets read it
|
|
||||||
for line in input:lines() do
|
for line in input:lines() do
|
||||||
random_messages.messages[line_number] = line
|
random_messages.messages[line_number] = line
|
||||||
line_number = line_number + 1
|
line_number = line_number + 1
|
||||||
@ -126,21 +103,16 @@ end
|
|||||||
random_messages.set_interval()
|
random_messages.set_interval()
|
||||||
random_messages.read_messages()
|
random_messages.read_messages()
|
||||||
|
|
||||||
local TIMER = 0
|
local function step()
|
||||||
if random_messages.messages[1] then
|
random_messages.show_message()
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.after(MESSAGE_INTERVAL, step)
|
||||||
TIMER = TIMER + dtime;
|
|
||||||
if TIMER > MESSAGE_INTERVAL then
|
|
||||||
random_messages.show_message()
|
|
||||||
TIMER = 0
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
minetest.after(0, step)
|
||||||
|
|
||||||
local register_chatcommand_table = {
|
local register_chatcommand_table = {
|
||||||
params = "viewmessages | removemessage <number> | addmessage <number>",
|
params = "viewmessages | removemessage <number> | addmessage <number>",
|
||||||
privs = {server = true},
|
privs = {server = true},
|
||||||
description = S("View and/or alter the server's random messages"),
|
description = "View and/or alter the server's random messages",
|
||||||
func = function(name,param)
|
func = function(name,param)
|
||||||
local t = string.split(param, " ")
|
local t = string.split(param, " ")
|
||||||
if t[1] == "viewmessages" then
|
if t[1] == "viewmessages" then
|
||||||
@ -151,7 +123,7 @@ local register_chatcommand_table = {
|
|||||||
function (params)
|
function (params)
|
||||||
if not tonumber(params[2]) or
|
if not tonumber(params[2]) or
|
||||||
random_messages.messages[tonumber(params[2])] == nil then
|
random_messages.messages[tonumber(params[2])] == nil then
|
||||||
return false,S("ERROR: No such message.")
|
return false,"ERROR: No such message."
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
@ -159,12 +131,12 @@ local register_chatcommand_table = {
|
|||||||
random_messages.remove_message(t[2])
|
random_messages.remove_message(t[2])
|
||||||
elseif t[1] == "addmessage" then
|
elseif t[1] == "addmessage" then
|
||||||
if not t[2] then
|
if not t[2] then
|
||||||
minetest.chat_send_player(name,S("ERROR: No message."))
|
minetest.chat_send_player(name,"ERROR: No message.")
|
||||||
else
|
else
|
||||||
random_messages.add_message(t)
|
random_messages.add_message(t)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name,S("ERROR: Invalid command."))
|
minetest.chat_send_player(name,"ERROR: Invalid command.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
# textdomain: random_messages
|
|
||||||
|
|
||||||
Blame the server admin! He/She has probably not edited the random messages yet.=Tirez les oreilles à l'administrateur du serveur. Il/elle n'a pas encore modifié les messages aléatoires.
|
|
||||||
Tell your dumb admin that this line is in (worldpath)/random_messages=Dites à votre administrateur à la noix que cette ligne se trouve dans (worldpath)/random_messages
|
|
||||||
View and/or alter the server's random messages=Afficher et/ou modifier les messages aléatoires du serveur
|
|
||||||
ERROR: No such message.=ERREUR : ce message est inexistant.
|
|
||||||
ERROR: No message.=ERREUR : pas de message.
|
|
||||||
ERROR: Invalid command.=ERREUR : Commande invalide.
|
|
@ -1,8 +0,0 @@
|
|||||||
# textdomain: random_messages
|
|
||||||
|
|
||||||
Blame the server admin! He/She has probably not edited the random messages yet.=
|
|
||||||
Tell your dumb admin that this line is in (worldpath)/random_messages=
|
|
||||||
View and/or alter the server's random messages=
|
|
||||||
ERROR: No such message.=
|
|
||||||
ERROR: No message.=
|
|
||||||
ERROR: Invalid command.=
|
|
3
mod.conf
3
mod.conf
@ -1,3 +0,0 @@
|
|||||||
name = random_messages
|
|
||||||
description = Configure your random messages.
|
|
||||||
author = arsdragonfly
|
|
@ -1,2 +0,0 @@
|
|||||||
# Default is 120 seconds.
|
|
||||||
random_messages_interval (Time between two subsequent messages) int 120
|
|
Reference in New Issue
Block a user