localized default file and signs generation

This commit is contained in:
xisd 2017-01-14 15:18:39 +01:00
parent b6b076a5a3
commit 2fb5705ac6
4 changed files with 271 additions and 18 deletions

18
README.txt Normal file → Executable file
View File

@ -1,3 +1,21 @@
This is a fork of RandomMessages mod by arsdragonfly.
What does it do?
Same as the original mod, see below for chat command details
* Display chat messages (hints, mod usage, etc.) from file : (world directory)/random_messages
+ Import messages from a default file located in mod directory
+ Support the use of localized suffix (e.g : messages.fr.txt)
+ Place signs around the world with messages on it
+ Cofiguration file (config.lua) to turn on/off the chat messages or the signs and other options
Optional but recommanded mods : signs_lib (to use the yard sign)
Chat messages are disabled by default : edit config.lua to use chat messages
_____________________________________________________
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.

26
config.lua Normal file
View File

@ -0,0 +1,26 @@
random_messages.options = {}
-- True / False : Should messages be displayed on chat
random_messages.options.display_chat_messages = false
-- True / False : Should signs with messages be places around the world
random_messages.options.place_messages_signs = true
--Time between two subsequent messages.
-- 0 to use default (120)
random_messages.options.messages_interval = 300
-- Default messages file name
random_messages.options.default_messages_file_name = "messages"
-- Signs optiosn
random_messages.options.signs = {
-- height limits for signs to be places
h_min = -200,
h_max = 200,
-- Increase this value will to see more signs in the world
signs_per_chunk= 1,
}

208
init.lua Normal file → Executable file
View File

@ -2,14 +2,33 @@
RandomMessages mod by arsdragonfly.
arsdragonfly@gmail.com
6/19/2013
xisd : 14/01/2017
--]]
--Time between two subsequent messages.
local MESSAGE_INTERVAL = 0
local modname = minetest.get_current_modname()
math.randomseed(os.time())
random_messages = {}
random_messages.messages = {} --This table contains all messages.
random_messages.options = {} -- Options are stored in this table
random_messages.messages = {} -- This table contains all messages.
-- Read config file
dofile(core.get_modpath(modname).."/config.lua")
--Time between two subsequent messages.
-- 0 to use default (120)
local MESSAGE_INTERVAL = random_messages.options.messages_interval
-- Added default messages file
local default_messages_file_name = random_messages.options.default_messages_file_name or "messages"
local display_chat_messages = random_messages.options.display_chat_messages
local place_messages_signs = random_messages.options.place_messages_signs
-- Define langage (code from intllib mod)
local LANG = minetest.setting_get("language")
if not (LANG and (LANG ~= "")) then LANG = os.getenv("LANG") end
if not (LANG and (LANG ~= "")) then LANG = "en" end
LANG = LANG:sub(1, 2)
function table.count( t )
local i = 0
@ -47,18 +66,36 @@ end
function random_messages.read_messages()
local line_number = 1
local input = io.open(minetest.get_worldpath().."/random_messages","r")
-- Defizne input
local input = io.open(minetest.get_worldpath()..'/'..modname,"r")
-- no input file found (in the world folder)
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")
-- look a localized default file in (in the mod folder)
local default_input = io.open(core.get_modpath(modname)..'/'..default_messages_file_name..'.'..LANG..'.txt',"r")
local output = io.open(minetest.get_worldpath()..'/'..modname,"w")
if not default_input then
-- localised file not found, look for a generic default file (in the mod folder)
default_input = io.open(minetest.get_modpath(modname)..'/'..default_messages_file_name..'.txt',"r")
end
if not default_input then
-- Now we're out of options, blame the admin
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)
input = io.open(minetest.get_worldpath().."/random_messages","r")
if default_input then io.close(default_input) end
input = io.open(minetest.get_worldpath()..'/'..modname,"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
-- close it
io.close(input)
end
@ -92,7 +129,7 @@ function random_messages.add_message(t)
end
function random_messages.save_messages()
local output = io.open(minetest.get_worldpath().."/random_messages","w")
local output = io.open(minetest.get_worldpath()..'/'..modname,"w")
for k,v in pairs(random_messages.messages) do
output:write(v .. "\n")
end
@ -103,14 +140,16 @@ end
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 display_chat_messages then
local TIMER = 0
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>",
@ -118,7 +157,7 @@ local register_chatcommand_table = {
description = "View and/or alter the server's random messages",
func = function(name,param)
local t = string.split(param, " ")
if t[1] == "viewmessages" then
if t[1] == "viewmessages" or nil then
minetest.chat_send_player(name,random_messages.list_messages())
elseif t[1] == "removemessage" then
if not random_messages.check_params(
@ -146,3 +185,136 @@ local register_chatcommand_table = {
minetest.register_chatcommand("random_messages", register_chatcommand_table)
minetest.register_chatcommand("rmessages", register_chatcommand_table)
-- Place signs in the world with random messages on it
-- Most of the code was adapted from tsm_chests_exemple
if place_messages_signs then
-- Height limits to place the signs
local h_min = random_messages.options.signs.h_min or -200
local h_max = random_messages.options.signs.h_max or 200
local signs_per_chunk = random_messages.options.signs.signs_per_chunk or 1
-- Register cubic sign node if no yard sign
if minetest.get_modpath("default")
and ( not minetest.get_modpath("signs_lib"))
and ( not minetest.get_modpath("signs"))
then
minetest.register_node(modname..":sign", {
description = "Informative Sign",
tiles = {"default_wood.png^default_sign_wood.png"},
is_ground_content = true,
groups = {choppy = 2, flammable = 2, oddly_breakable_by_hand = 3},
drop = 'default:sign_wall_wood',
sounds = default.node_sound_wood_defaults(),
})
end
minetest.register_on_generated(function(minp, maxp, seed)
-- get the water level and convert it to a number
local water_level = minetest.setting_get("water_level")
if water_level == nil or type(water_level) ~= "number" then
water_level = 1
else
water_level = tonumber(water_level)
end
-- signs minimum and maximum spawn height
local height_min = water_level + h_min
local height_max = water_level + h_max
if(maxp.y < height_min or minp.y > height_max) then
return
end
local y_min = math.max(minp.y, height_min)
local y_max = math.min(maxp.y, height_max)
for i=1, signs_per_chunk do
local pos = {x=math.random(minp.x,maxp.x),z=math.random(minp.z,maxp.z), y=minp.y}
local env = minetest.env
-- Find ground level
local ground = nil
local top = y_max
if env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "air" and env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "default:water_source" and env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "default:lava_source" then
for y=y_max,y_min,-1 do
local p = {x=pos.x,y=y,z=pos.z}
if env:get_node(p).name == "air" or env:get_node(p).name == "default:water_source" or env:get_node(p) == "default:lava_source" then
top = y
break
end
end
end
for y=top,y_min,-1 do
local p = {x=pos.x,y=y,z=pos.z}
if env:get_node(p).name ~= "air" and env:get_node(p).name ~= "default:water_source" and env:get_node(p).name ~= "default:lava_source" then
ground = y
break
end
end
if(ground~=nil) then
local sign_pos = {x=pos.x,y=ground+1, z=pos.z}
local nn = minetest.get_node(sign_pos).name -- sign node name (before it becomes a sign)
if nn == "air" then
-- Replace plants and other buildable to nodes instead of placing on it
local under = minetest.get_node({x=pos.x, y=ground, z=pos.z}).name
local under_def = minetest.registered_nodes[under]
if under_def and under_def.buildable_to then
ground = ground - 1
sign_pos = {x=pos.x,y=ground+1, z=pos.z}
nn = minetest.get_node(sign_pos).name
end
-- Define message to display
local message_number = table.random(random_messages.messages)
local msg = random_messages.messages[message_number] or message_number
if msg then
-- Define the rest of the sign
local sign = {}
if minetest.get_modpath("signs_lib") or minetest.get_modpath("signs") then
sign.name = "signs:sign_yard"
else
sign.name = modname..":sign"
end
-- secondly: rotate the chest
-- find possible faces
local xp, xm, zp, zm
xp = minetest.get_node({x=pos.x+1,y=ground+1, z=pos.z})
xm = minetest.get_node({x=pos.x-1,y=ground+1, z=pos.z})
zp = minetest.get_node({x=pos.x,y=ground+1, z=pos.z+1})
zm = minetest.get_node({x=pos.x,y=ground+1, z=pos.z-1})
local facedirs = {}
if(xp.name=="air" or xp.name=="default:water_source") then
table.insert(facedirs, minetest.dir_to_facedir({x=-1,y=0,z=0}))
end
if(xm.name=="air" or xm.name=="default:water_source") then
table.insert(facedirs, minetest.dir_to_facedir({x=1,y=0,z=0}))
end
if(zp.name=="air" or zp.name=="default:water_source") then
table.insert(facedirs, minetest.dir_to_facedir({x=0,y=0,z=-1}))
end
if(zm.name=="air" or zm.name=="default:water_source") then
table.insert(facedirs, minetest.dir_to_facedir({x=0,y=0,z=1}))
end
-- choose a random face (if possible)
if(#facedirs == 0) then
minetest.set_node({x=pos.x,y=ground+1, z=pos.z+1},{name=nn})
sign.param2 = minetest.dir_to_facedir({x=0,y=0,z=1})
else
sign.param2 = facedirs[math.floor(math.random(#facedirs))]
end
-- Lastly: place the sign
minetest.set_node(sign_pos,sign)
local meta = minetest.get_meta(sign_pos)
meta:set_string("text",msg)
meta:set_string("infotext",msg)
end
end
end
end
end)
end

37
messages.fr.txt Executable file
View File

@ -0,0 +1,37 @@
[-Astuce-] Utilisez T pour envoyer des message ou taper des commandes.
[-Astuce-] Utilisez F9 pour afficher la mini-carte.
[-Astuce-] Utilisez F7 pour changer la vue du personnage.
[-Astuce-] Utilisez F2 pour activer désactiver le brouillard, R pour limiter/étendre le champ de vision.
[-Astuce-] Vous êtes pressé.e. ? Sprintez en maintenant la touche "e".
[-Astuce-] Si au moins la moitiés des joueurs dorment, la nuit peut être est passée.
[-Astuce-] Si vous mourrez vous apparaîtrez près du dernier lit dans lequel vous avez dormit.
[-Astuce-] Tondez un mouton sans danger grâce aux ciseaux à laine !
[-Astuce-] Donnez du blé a un mouton et il vous suivra si vous marchez lentement.
[-Astuce-] Donnez cinq épis de blé a un mouton pour l'apprivoiser.
[-Astuce-] Des graines de blé sauvage peuvent être trouvées dans les touffes d'herbe.
[-Astuce-] On trouve des graines de coton dans les hautes herbe de la jungle...
[-Astuce-] Il y a des chances de trouver des graines dans les touffes d'herbe.
[-Astuce-] Vos plantes ne poussent pas ? Travaillez le sol avec une houe et plantez les près de l'eau.
[-Astuce-] Maintenez la touche MAJ pour marcher sur le bord des blocs sans tomber !
[-Astuce-] Envie de changer d'apparence ? Construisez une armoire !
[-Astuce-] Consulter votre 'crafting guide' pour connaitres toutes les recettes !
[-Astuce-] Votre chariot minier est trop lent ? Tapez dessus pour le faire avancer !
[-Astuce-] Retrouvez la direction de vos ossements grace à la commande "/showbones".
[-Astuce-] Affichez vos succès grace aux Tableau de Trophés.
[-Astuce-] Les zombies, fantômes et oerrki n'apparaissent que dans les zones sombres.
[-Astuce-] Vous devriez pouvoir vaincre les zombies sans encombres si vous les tenez a distance.
[-Astuce-] Les portails élémentaux permettent de se déplacer d'un bout a l'autre de la carte rapidement.
[-Astuce-] La nourriture régénère votre barre de vie.
[-Astuce-] Consultez les dernières astuces avec la commande /rmessages
[-Astuce-] Consultez le guide du server à tout moment avec la commande /guide
[-Astuce-] Les ruines enfouies abritent parfois des trésors ... et des zombies
[-Astuce-] Le tournevis sert à tourner les blocs, c'est l'outil indispensable des architectes !
[-Astuce-] Avez-vous déjà rencontré un Nyan Cat ? C'est le bloc le plus rare du jeu
[-Astuce-] La potion de la taupe est incroyable ! Buvez-la et foncez vers un mur !!
[-Astuce-] Marre de la grisaille ? Craftez un pot de peinture et repeignez les grottes !
[-Astuce-] Les plants de haricots verts donnent parfois un haricot magique !
[-Astuce-] Les haricots magiques poussent parfois dans les touffes d'herbes !
[-Astuce-] Utilisez la loupe pour tout savoir sur un bloc !
[-Astuce-] Acheminez, triez, et transformez automatiquement vos matériaux grâce aux tubes pneumatiques !
[-Astuce-] Créez des machines entièrement automatisées grâce aux mesecons !
[-Astuce-] Craftez un sac pour transporter plus de choses !