2016-02-05 21:55:45 +00:00
--[[
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.
2018-04-06 15:18:32 +00:00
function table . count ( t ) -- luacheck: ignore
2016-02-05 21:55:45 +00:00
local i = 0
for k in pairs ( t ) do i = i + 1 end
return i
end
2018-04-06 15:18:32 +00:00
function table . random ( t ) -- luacheck: ignore
2016-02-05 21:55:45 +00:00
local rk = math.random ( 1 , table.count ( t ) )
local i = 1
for k , v in pairs ( t ) do
if ( i == rk ) then return v , k end
i = i + 1
end
end
function random_messages . initialize ( ) --Set the interval in minetest.conf.
2019-03-17 01:37:20 +00:00
minetest.settings : set ( " random_messages_interval " , 60 )
2018-12-30 23:08:25 +00:00
minetest.settings : write ( ) ;
2018-02-18 14:03:28 +00:00
return 60
2016-02-05 21:55:45 +00:00
end
2018-02-18 14:03:28 +00:00
function random_messages . set_interval ( ) --Read the interval from minetest.conf and set it if it doesn't exist
2019-03-17 01:37:20 +00:00
MESSAGE_INTERVAL = tonumber ( minetest.settings : get ( " random_messages_interval " ) )
or random_messages.initialize ( )
2016-02-05 21:55:45 +00:00
end
function random_messages . check_params ( name , func , params )
2019-03-17 01:37:20 +00:00
local stat , msg = func ( params )
2016-02-05 21:55:45 +00:00
if not stat then
minetest.chat_send_player ( name , msg )
return false
end
return true
end
function random_messages . read_messages ( )
2016-02-15 01:27:20 +00:00
random_messages.messages = {
" To talk to only your team, start your messages with /t. For example, /t Hello team! " ,
2018-11-18 13:15:32 +00:00
" Use medkits to gradually restore your health. " ,
2019-03-06 13:09:22 +00:00
" Moving or fighting while using medkits will interrupt the healing process. " ,
2020-10-16 21:51:07 +00:00
" Knights have a slight damage bonus (up to 1.5 hp) when attacking with swords. " ,
2021-06-10 17:53:47 +00:00
" Gain more score by killing enemies, healing teammates as a medic, or by capturing the flag. " ,
2017-10-12 23:31:39 +00:00
" You gain more score the better the opponent you defeat. " ,
2018-01-26 16:45:35 +00:00
" Find weapons in chests or mine and use furnaces to make stronger swords. " ,
2020-05-10 17:34:59 +00:00
" Players are immune to attack for 5 seconds after they respawn. " ,
2021-06-23 14:06:50 +00:00
" Access the pro section of the chest by achieving a 10k+ score and either killing 3 people for every 2 deaths and capturing the flag 10 times or killing as many people as you die, capturing the flag on every 3rd attempt and at least 30 times. " ,
2018-01-03 02:50:20 +00:00
" Use team doors (steel) to stop the enemy walking into your base. " ,
2021-01-18 04:19:38 +00:00
" Craft 6 cobbles and 1 steel ingot together to make reinforced cobble. " ,
2018-01-03 02:50:20 +00:00
" Sprint by pressing the fast key (E) when you have stamina. " ,
2021-02-25 17:29:53 +00:00
" Like CTF? Give feedback using /report, and consider joining the Discord " ,
2019-11-15 12:21:23 +00:00
" Want to submit your own map? Visit ctf.rubenwardy.com to get involved. " ,
2018-04-06 11:58:12 +00:00
" Using limited resources for building structures that don't strengthen your base's defences is discouraged. " ,
2020-12-22 16:21:22 +00:00
" To report misbehaving players to moderators, please use /report <name> <action> " ,
2018-04-06 11:58:12 +00:00
" Swearing, trolling and being rude will not be tolerated and strict action will be taken. " ,
2018-08-03 11:38:34 +00:00
" Trapping team mates on purpose is strictly against the rules and you will be kicked immediately. " ,
2018-04-06 11:58:12 +00:00
" Help your team claim victory by storing extra weapons in the team chest, and never taking more than you need. " ,
2018-08-03 11:38:34 +00:00
" Excessive spawn-killing is a direct violation of the rules - appropriate punishments will be given. " ,
2019-01-26 07:39:30 +00:00
" Use /r to check your score and rank, and /rankings to see the league tables. " ,
2019-11-27 06:00:39 +00:00
" Use /r <number> or /rn <number> to check the rankings of the player in the given rank. " ,
2019-03-06 13:09:22 +00:00
" Use bandages on team-mates to heal them by 3-4 HP if their health is below 15 HP. " ,
2019-03-17 01:37:20 +00:00
" Use /m to add a team marker at pointed location, that's visible only to team-mates. " ,
2021-03-17 15:34:32 +00:00
" Use /mr to remove your marker. " ,
" Use /summary or /s to check scores of the current match and the previous match. " ,
2019-03-22 04:31:57 +00:00
" Use /maps to view the maps catalog. It also contains license info and attribution details. " ,
" Change your class in your base by right clicking the home flag or typing /class. " ,
2020-03-13 23:26:53 +00:00
" Medics cause troops within 10 metres to regenerate health faster. " ,
2020-03-26 22:04:26 +00:00
" Hitting your enemy does more damage than not hitting them. " ,
2020-10-16 16:41:01 +00:00
" Press right mouse button or double-tap the screen to activate scope while wielding a sniper rifle. " ,
2021-03-17 15:34:32 +00:00
" Medics can dig pillars by right clicking the base of one with their paxel. " ,
2021-06-10 17:53:47 +00:00
" Use `/help all` to see all available commands. " ,
2016-02-15 01:27:20 +00:00
}
2016-02-05 21:55:45 +00:00
end
function random_messages . display_message ( message_number )
2016-02-14 19:28:45 +00:00
local msg = random_messages.messages [ message_number ] or message_number
if msg then
2022-02-12 13:46:08 +00:00
for i , player in ipairs ( minetest.get_connected_players ( ) ) do
local name = player : get_player_name ( )
minetest.chat_send_player ( name , minetest.colorize ( " #808080 " , msg ) )
end
2016-02-05 21:55:45 +00:00
end
end
function random_messages . show_message ( )
random_messages.display_message ( table.random ( random_messages.messages ) )
end
function random_messages . list_messages ( )
local str = " "
for k , v in pairs ( random_messages.messages ) do
str = str .. k .. " | " .. v .. " \n "
end
return str
end
function random_messages . remove_message ( k )
table.remove ( random_messages.messages , k )
random_messages.save_messages ( )
end
function random_messages . add_message ( t )
table.insert ( random_messages.messages , table.concat ( t , " " , 2 ) )
random_messages.save_messages ( )
end
function random_messages . save_messages ( )
2017-10-12 14:40:02 +00:00
local output = io.open ( minetest.get_worldpath ( ) .. " /random_messages " , " w " )
for k , v in pairs ( random_messages.messages ) do
output : write ( v .. " \n " )
end
io.close ( output )
2016-02-05 21:55:45 +00:00
end
--When server starts:
random_messages.set_interval ( )
random_messages.read_messages ( )
2018-01-02 20:13:30 +00:00
local function step ( dtime )
random_messages.show_message ( )
minetest.after ( MESSAGE_INTERVAL , step )
end
minetest.after ( MESSAGE_INTERVAL , step )
2016-02-05 21:55:45 +00:00
local register_chatcommand_table = {
params = " viewmessages | removemessage <number> | addmessage <number> " ,
privs = { server = true } ,
description = " View and/or alter the server's random messages " ,
func = function ( name , param )
local t = string.split ( param , " " )
if t [ 1 ] == " viewmessages " then
minetest.chat_send_player ( name , random_messages.list_messages ( ) )
elseif t [ 1 ] == " removemessage " then
if not random_messages.check_params (
name ,
function ( params )
if not tonumber ( params [ 2 ] ) or
random_messages.messages [ tonumber ( params [ 2 ] ) ] == nil then
return false , " ERROR: No such message. "
end
return true
end ,
t ) then return end
random_messages.remove_message ( t [ 2 ] )
elseif t [ 1 ] == " addmessage " then
if not t [ 2 ] then
minetest.chat_send_player ( name , " ERROR: No message. " )
else
random_messages.add_message ( t )
end
else
minetest.chat_send_player ( name , " ERROR: Invalid command. " )
end
end
}
minetest.register_chatcommand ( " random_messages " , register_chatcommand_table )
minetest.register_chatcommand ( " rmessages " , register_chatcommand_table )