forked from nalc/random_messages
Support for a default messages file
Hi ! I use your mod on a local server, it's great for displaying tips and news ! But since I'm too lazy to copy-paste the random_messages file from one world to an other, I made this change so if the random_messages file is not in the world folder, it look for a template in the mod folder before the 'blame the admin' last resort. Anyway I thought it could be useful for others
This commit is contained in:
parent
b6b076a5a3
commit
1b7ea87932
19
init.lua
19
init.lua
@ -5,6 +5,8 @@ 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())
|
||||||
|
|
||||||
@ -47,14 +49,27 @@ 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")
|
||||||
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n")
|
if not default_input then
|
||||||
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n")
|
-- blame the admin if not found
|
||||||
|
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")
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user