diff --git a/mods/random_messages/README.txt b/mods/random_messages/README.txt new file mode 100644 index 00000000..fe21ec3d --- /dev/null +++ b/mods/random_messages/README.txt @@ -0,0 +1,10 @@ +RandomMessages mod by arsdragonfly. +Put your messages in (world directory)/random_messages,1 message per line. +Messages can be all kinds of hints, mod usage, etc. +In minetest.conf, random_messages_interval decides how often a message is sent. +Released under CC0. +Special thanks to: +Michael Rasmussen (michael@jamhome.us) +Enjoy it! ^_^ +arsdragonfly@gmail.com +6/19/2013 diff --git a/mods/random_messages/depends.txt b/mods/random_messages/depends.txt new file mode 100644 index 00000000..331d858c --- /dev/null +++ b/mods/random_messages/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/mods/random_messages/init.lua b/mods/random_messages/init.lua new file mode 100644 index 00000000..c8124982 --- /dev/null +++ b/mods/random_messages/init.lua @@ -0,0 +1,63 @@ +--[[ +RandomMessages mod by arsdragonfly. +arsdragonfly@gmail.com +6/19/2013 +--]] +--Time between two subsequent messages. +local MESSAGE_INTERVAL = 0 + +math.randomseed(os.time()) + +random_messages = {} +random_messages.messages = {} --This table contains all messages. + +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() +end + +function random_messages.read_messages() + local line_number = 1 + local input = io.open(minetest.get_worldpath().."/random_messages","r") + if not input then + 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") + io.close(output) + input = io.open(minetest.get_worldpath().."/random_messages","r") + end + 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) + if random_messages.messages[message_number] then + minetest.chat_send_all(random_messages.messages[message_number]) + end +end + +function random_messages.show_message() + random_messages.display_message(math.random(#random_messages.messages)) +end + +--When server starts: +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) +