added multiple article support

This commit is contained in:
Brandon 2013-06-29 22:47:26 -05:00
parent 361230f968
commit a08622d01e

View File

@ -3,20 +3,28 @@ local news = {}
news.path = minetest.get_worldpath()
function news.formspec(player)
local newsfile = io.open(news.path.."/news.txt","r")
function news.formspec(player,article)
if ( article == "" or article == nil ) then
article = "news.txt"
else
article = "news_"..article..".txt"
end
local newsfile = io.open(news.path.."/"..article,"r")
local formspec = "size[12,10]"
if newsfile ~= nil then
local newscontent = newsfile:read("*a")
formspec = formspec.."textarea[.25,"..tostring(y)..";12,10;news;;"..newscontent.."]"
else
minetest.log('error',"News file does not exist")
formspec = formspec.."textarea[.25,.25;12,10;news;;"..newscontent.."]"
else
formspec = formspec.."label[.25,.25;Article does not exist]"
end
formspec = formspec.."button_exit[.25,9;2,1;exit;Close"
newsfile:close()
if ( newsfile ~= nil ) then
newsfile:close()
end
return formspec
end
@ -28,11 +36,11 @@ end
minetest.register_chatcommand("news",{
params = "",
params = "<article>",
description="Shows the server news",
func = function (name,params)
local player = minetest.get_player_by_name(name)
minetest.show_formspec(name,"news",news.formspec(player))
minetest.show_formspec(name,"news",news.formspec(player,params))
end,
})