Tidy code
This commit is contained in:
parent
b69fda9c98
commit
3f67d39c54
17
init.lua
17
init.lua
@ -1,25 +1,20 @@
|
|||||||
|
|
||||||
-- register bypass priv
|
-- register bypass priv
|
||||||
minetest.register_privilege("news_bypass", {
|
minetest.register_privilege("news_bypass", {
|
||||||
description = "Skip the news.", give_to_singleplayer=false})
|
description = "Skip the news.", give_to_singleplayer = false})
|
||||||
|
|
||||||
-- create formspec from text file
|
-- create formspec from text file
|
||||||
local function get_formspec()
|
local function get_formspec()
|
||||||
|
|
||||||
local news_file = io.open(minetest.get_worldpath().."/news.txt", "r")
|
local news_file = io.open(minetest.get_worldpath().."/news.txt", "r")
|
||||||
|
local news_fs = 'size[12,8.5]'..
|
||||||
local news_fs = 'size[12,8.5]'
|
"button_exit[-0.05,8.05;2,1;exit;Close]"
|
||||||
if news_file then
|
if news_file then
|
||||||
local news = news_file:read("*a")
|
local news = news_file:read("*a")
|
||||||
|
news_file:close()
|
||||||
news_fs = news_fs.."textarea[0.25,0.25;12,9;news;;"..news.."]"
|
news_fs = news_fs.."textarea[0.25,0.25;12,9;news;;"..news.."]"
|
||||||
else
|
else
|
||||||
news_fs = news_fs.."textarea[0.25,0.25;12,9;news;;No current news.]"
|
news_fs = news_fs.."textarea[0.25,0.25;12,9;news;;No current news.]"
|
||||||
end
|
end
|
||||||
news_fs = news_fs.."button_exit[-0.05,8.05;2,1;exit;Close]"
|
|
||||||
|
|
||||||
if news_file then
|
|
||||||
news_file:close()
|
|
||||||
end
|
|
||||||
return news_fs
|
return news_fs
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,8 +31,8 @@ end)
|
|||||||
-- command to display server news at any time
|
-- command to display server news at any time
|
||||||
minetest.register_chatcommand("news", {
|
minetest.register_chatcommand("news", {
|
||||||
description = "Shows server news to the player",
|
description = "Shows server news to the player",
|
||||||
func = function (name, params)
|
func = function (name)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
minetest.show_formspec(name, "news", get_formspec())
|
minetest.show_formspec(name, "news", get_formspec())
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user