forked from mtcontrib/random_messages
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
5682172106 | |||
0895cf7ce4 | |||
bb61f68038 | |||
48c2553798 | |||
e4c5ba1c85 | |||
7db0c9c50b | |||
17d2fd9f75 | |||
24974e109b | |||
e9e5bb7bef | |||
365ffd23ad | |||
1c507021bf | |||
55e197dc6e | |||
12f23d449e | |||
31e1cd5d27 | |||
1b7ea87932 | |||
b6b076a5a3 |
65
init.lua
65
init.lua
@ -5,12 +5,27 @@ arsdragonfly@gmail.com
|
||||
--]]
|
||||
--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.
|
||||
|
||||
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 )
|
||||
local i = 0
|
||||
for k in pairs( t ) do i = i + 1 end
|
||||
@ -26,14 +41,8 @@ function table.random( t )
|
||||
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)
|
||||
MESSAGE_INTERVAL = tonumber(minetest.setting_get("random_messages_interval")) or random_messages.initialize()
|
||||
MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval") or 120)
|
||||
end
|
||||
|
||||
function random_messages.check_params(name,func,params)
|
||||
@ -47,14 +56,28 @@ end
|
||||
|
||||
function random_messages.read_messages()
|
||||
local line_number = 1
|
||||
-- define input
|
||||
local input = io.open(minetest.get_worldpath().."/random_messages","r")
|
||||
-- no input file found
|
||||
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")
|
||||
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n")
|
||||
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n")
|
||||
if not default_input then
|
||||
-- blame the admin if not found
|
||||
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(default_input)
|
||||
input = io.open(minetest.get_worldpath().."/random_messages","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
|
||||
@ -104,18 +127,20 @@ random_messages.set_interval()
|
||||
random_messages.read_messages()
|
||||
|
||||
local TIMER = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
TIMER = TIMER + dtime;
|
||||
if TIMER > MESSAGE_INTERVAL then
|
||||
random_messages.show_message()
|
||||
TIMER = 0
|
||||
end
|
||||
end)
|
||||
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
|
||||
|
||||
local register_chatcommand_table = {
|
||||
params = "viewmessages | removemessage <number> | addmessage <number>",
|
||||
privs = {server = true},
|
||||
description = "View and/or alter the server's random messages",
|
||||
description = S("View and/or alter the server's random messages"),
|
||||
func = function(name,param)
|
||||
local t = string.split(param, " ")
|
||||
if t[1] == "viewmessages" then
|
||||
@ -126,7 +151,7 @@ local register_chatcommand_table = {
|
||||
function (params)
|
||||
if not tonumber(params[2]) or
|
||||
random_messages.messages[tonumber(params[2])] == nil then
|
||||
return false,"ERROR: No such message."
|
||||
return false,S("ERROR: No such message.")
|
||||
end
|
||||
return true
|
||||
end,
|
||||
@ -134,12 +159,12 @@ local register_chatcommand_table = {
|
||||
random_messages.remove_message(t[2])
|
||||
elseif t[1] == "addmessage" then
|
||||
if not t[2] then
|
||||
minetest.chat_send_player(name,"ERROR: No message.")
|
||||
minetest.chat_send_player(name,S("ERROR: No message."))
|
||||
else
|
||||
random_messages.add_message(t)
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name,"ERROR: Invalid command.")
|
||||
minetest.chat_send_player(name,S("ERROR: Invalid command."))
|
||||
end
|
||||
end
|
||||
}
|
||||
|
8
locale/random_messages.fr.tr
Normal file
8
locale/random_messages.fr.tr
Normal file
@ -0,0 +1,8 @@
|
||||
# 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.
|
8
locale/template.txt
Normal file
8
locale/template.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# 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
Normal file
3
mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = random_messages
|
||||
description = Configure your random messages.
|
||||
author = arsdragonfly
|
2
settingtypes.txt
Normal file
2
settingtypes.txt
Normal file
@ -0,0 +1,2 @@
|
||||
# Default is 120 seconds.
|
||||
random_messages_interval (Time between two subsequent messages) int 120
|
Reference in New Issue
Block a user