2022-02-11 01:26:20 +01:00
|
|
|
-- rumble - Client side mod for Minetest
|
|
|
|
-- Scripted by: Li0n
|
|
|
|
|
2022-02-25 23:15:47 +01:00
|
|
|
-- configureable settings:
|
|
|
|
local rumble_strength_max_standard = 0.5
|
|
|
|
local rumble_duration_max_standard = 5
|
2022-02-25 00:22:40 +01:00
|
|
|
|
|
|
|
-- To do list:
|
|
|
|
-- sadist mode
|
|
|
|
-- tnt griefer mode
|
2022-02-26 18:47:57 +01:00
|
|
|
-- log player name only once, after player is initialized.
|
2022-02-27 16:25:30 +01:00
|
|
|
-- editable table of words to trigger notification rumble
|
|
|
|
-- command to choose a word/name that triggers notification rumble
|
|
|
|
-- notification mode: trigger rumble from specific words written by either yourself or others
|
|
|
|
-- condense on/off commands into single commands. eg .chatlog on and .chatlog off instead of .chatlog_on and .chatlog_off
|
2022-02-27 16:48:43 +01:00
|
|
|
-- make a GUI for all the settings
|
|
|
|
-- make a section in the code where all default settings can be changed
|
2022-02-27 16:25:30 +01:00
|
|
|
|
2022-02-11 01:26:20 +01:00
|
|
|
|
2022-02-25 23:46:39 +01:00
|
|
|
local rumble_strength_max = rumble_strength_max_standard
|
|
|
|
local rumble_duration_max = rumble_duration_max_standard
|
2022-02-26 16:26:30 +01:00
|
|
|
local log
|
|
|
|
local log_mode
|
2022-02-26 18:47:57 +01:00
|
|
|
local local_player_name
|
2022-02-27 16:25:30 +01:00
|
|
|
local notification_mode
|
|
|
|
local chat_trigger
|
2022-02-25 23:15:47 +01:00
|
|
|
|
|
|
|
local log_only = function(text)
|
|
|
|
minetest.log("action", text)
|
|
|
|
end
|
|
|
|
|
|
|
|
local log_and_chat = function(text)
|
|
|
|
minetest.log("action", text)
|
|
|
|
minetest.display_chat_message(text)
|
|
|
|
end
|
2022-02-25 20:58:58 +01:00
|
|
|
|
2022-02-25 23:30:34 +01:00
|
|
|
local no_log_no_chat = function(text)
|
|
|
|
end
|
|
|
|
|
2022-02-25 20:58:58 +01:00
|
|
|
-- step 1 (start)
|
|
|
|
minetest.register_on_mods_loaded(function()
|
|
|
|
minetest.display_chat_message("rumble mod loaded. May the rumble be with you!")
|
2022-02-26 16:26:30 +01:00
|
|
|
log = log_and_chat
|
|
|
|
log_mode = "log and chat"
|
2022-02-11 01:26:20 +01:00
|
|
|
end)
|
|
|
|
|
2022-02-19 19:41:17 +01:00
|
|
|
-- step 2 (take damage)
|
2022-02-11 01:26:20 +01:00
|
|
|
minetest.register_on_damage_taken(function(hp)
|
2022-02-25 00:36:09 +01:00
|
|
|
local rumble_strength = math.min( hp/20, rumble_strength_max )
|
|
|
|
local rumble_duration = math.min( hp, rumble_duration_max )
|
2022-02-25 23:15:47 +01:00
|
|
|
log("[rumble] ".."queue "..rumble_strength.." "..rumble_duration)
|
2022-02-11 01:26:20 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- step 3 (die)
|
|
|
|
minetest.register_on_death(function()
|
2022-02-25 23:15:47 +01:00
|
|
|
log("[rumble] instant 0 0")
|
2022-02-25 00:55:51 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- step 4 (disconnect)
|
|
|
|
minetest.register_on_shutdown(function()
|
2022-02-25 23:15:47 +01:00
|
|
|
log("[rumble] instant 0 0")
|
2022-02-25 00:55:51 +01:00
|
|
|
end)
|
2022-02-25 20:58:58 +01:00
|
|
|
|
2022-02-26 18:09:59 +01:00
|
|
|
-- step 5 (chat mode)
|
|
|
|
minetest.register_on_receiving_chat_message(function(message)
|
2022-02-27 16:25:30 +01:00
|
|
|
if notification_mode == true and (string.match((message), "^.*<.*>.*$")) and minetest.localplayer ~= nil then
|
2022-02-26 18:47:57 +01:00
|
|
|
local_player_name = minetest.localplayer:get_name(self)
|
|
|
|
if not (string.match((message), "^.*"..local_player_name..".*$")) then
|
2022-02-27 16:25:30 +01:00
|
|
|
if chat_trigger == nil then
|
|
|
|
log("[rumble] queue 0.2 5")
|
|
|
|
else
|
|
|
|
if (string.match((message), "^.*"..chat_trigger..".*$")) then
|
|
|
|
log("[rumble] queue 0.2 5")
|
|
|
|
end
|
|
|
|
end
|
2022-02-26 18:47:57 +01:00
|
|
|
end
|
2022-02-26 18:09:59 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-04-20 20:58:59 +02:00
|
|
|
-- step 6 (item use test and node place tests)
|
2022-02-26 18:09:59 +01:00
|
|
|
|
2022-04-20 20:58:59 +02:00
|
|
|
--minetest.register_on_item_use(function(itemstack, pointed_thing)
|
|
|
|
-- log("itemstack: "..tostring(itemstack))
|
|
|
|
-- log("pointed thing: "..dump(pointed_thing))
|
|
|
|
--end)
|
|
|
|
|
|
|
|
|
|
|
|
-- step 7 (commands)
|
2022-02-25 23:51:15 +01:00
|
|
|
|
|
|
|
-- command 1
|
2022-02-27 16:25:30 +01:00
|
|
|
minetest.register_chatcommand("settings", {
|
|
|
|
description = "shows current values of settings",
|
|
|
|
func = function()
|
|
|
|
minetest.display_chat_message("max rumble strength: "..rumble_strength_max)
|
|
|
|
minetest.display_chat_message("max rumble duration: "..rumble_duration_max)
|
|
|
|
minetest.display_chat_message("current chat and log mode: "..log_mode)
|
|
|
|
minetest.display_chat_message("local player name: "..tostring(local_player_name))
|
|
|
|
if notification_mode == true then
|
|
|
|
minetest.display_chat_message("notification mode: on")
|
|
|
|
elseif notification_mode == false then
|
|
|
|
minetest.display_chat_message("notification mode: off")
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.display_chat_message("chat trigger: "..tostring(chat_trigger))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- command 2
|
2022-02-25 20:58:58 +01:00
|
|
|
minetest.register_chatcommand("strength", {
|
2022-02-25 22:30:48 +01:00
|
|
|
description = "set max rumble strength (from 0 to 1)",
|
2022-02-25 20:58:58 +01:00
|
|
|
func = function(text)
|
2022-02-26 17:46:52 +01:00
|
|
|
if (string.match((text), "^%d+%.?%d*$")) then
|
2022-02-25 22:30:48 +01:00
|
|
|
rumble_strength_max = text
|
2022-02-25 21:55:03 +01:00
|
|
|
minetest.display_chat_message("max rumble strength set to "..rumble_strength_max)
|
|
|
|
else
|
|
|
|
minetest.display_chat_message(minetest.colorize("#FF0", "error: value after .strength should be a positive number"))
|
|
|
|
end
|
2022-02-25 20:58:58 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-02-27 16:25:30 +01:00
|
|
|
-- command 3
|
2022-02-25 20:58:58 +01:00
|
|
|
minetest.register_chatcommand("duration", {
|
|
|
|
description = "set max rumble duration (in seconds)",
|
|
|
|
func = function(text)
|
2022-02-26 17:46:52 +01:00
|
|
|
if (string.match((text), "^%d+%.?%d*$")) then
|
2022-02-25 22:30:48 +01:00
|
|
|
rumble_duration_max = text
|
2022-02-25 21:55:03 +01:00
|
|
|
minetest.display_chat_message("max rumble duration set to "..rumble_duration_max)
|
|
|
|
else
|
|
|
|
minetest.display_chat_message(minetest.colorize("#FF0", "error: value after .duration should be a positive number"))
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-02-25 23:51:15 +01:00
|
|
|
-- command 4
|
2022-02-26 18:47:57 +01:00
|
|
|
minetest.register_chatcommand("chatlog_off", {
|
2022-02-25 23:15:47 +01:00
|
|
|
description = "disables rumble logs being written into chat",
|
|
|
|
func = function()
|
2022-02-26 00:05:45 +01:00
|
|
|
log = log_only
|
|
|
|
log_mode = "log only"
|
|
|
|
minetest.display_chat_message("rumble chat turned off")
|
2022-02-25 23:15:47 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-02-25 23:51:15 +01:00
|
|
|
-- command 5
|
2022-02-26 18:47:57 +01:00
|
|
|
minetest.register_chatcommand("chatlog_on", {
|
2022-02-25 23:15:47 +01:00
|
|
|
description = "enables rumble logs being written into chat",
|
|
|
|
func = function()
|
2022-02-26 00:05:45 +01:00
|
|
|
log = log_and_chat
|
|
|
|
log_mode = "log and chat"
|
|
|
|
minetest.display_chat_message("rumble chat turned on")
|
2022-02-25 23:15:47 +01:00
|
|
|
end,
|
|
|
|
})
|
2022-02-25 23:30:34 +01:00
|
|
|
|
2022-02-25 23:51:15 +01:00
|
|
|
-- command 6
|
2022-02-25 23:30:34 +01:00
|
|
|
minetest.register_chatcommand("stop", {
|
2022-02-25 23:52:36 +01:00
|
|
|
description = "pauses logging",
|
2022-02-25 23:30:34 +01:00
|
|
|
func = function()
|
|
|
|
log = no_log_no_chat
|
2022-02-26 00:05:45 +01:00
|
|
|
log_mode = "no log no chat"
|
|
|
|
minetest.display_chat_message("rumble logging paused")
|
2022-02-25 23:30:34 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-02-25 23:51:15 +01:00
|
|
|
-- command 7
|
2022-02-25 23:30:34 +01:00
|
|
|
minetest.register_chatcommand("resume", {
|
|
|
|
description = "resumes the rumble program",
|
|
|
|
func = function()
|
|
|
|
log = log_only
|
2022-02-26 00:05:45 +01:00
|
|
|
log_mode = "log only"
|
|
|
|
minetest.display_chat_message("rumble logging resumed")
|
2022-02-25 23:30:34 +01:00
|
|
|
end,
|
|
|
|
})
|
2022-02-26 18:47:57 +01:00
|
|
|
|
|
|
|
-- command 8
|
2022-02-27 16:25:30 +01:00
|
|
|
minetest.register_chatcommand("notifications_on", {
|
|
|
|
description = "turns on notification mode: triggers rumble for every received message",
|
2022-02-27 16:48:43 +01:00
|
|
|
func = function()
|
2022-02-27 16:25:30 +01:00
|
|
|
notification_mode = true
|
|
|
|
minetest.display_chat_message("notification mode: on")
|
2022-02-26 18:47:57 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- command 9
|
2022-02-27 16:25:30 +01:00
|
|
|
minetest.register_chatcommand("notifications_off", {
|
|
|
|
description = "turns off notification mode: does not trigger rumble for received messages",
|
2022-02-27 16:48:43 +01:00
|
|
|
func = function()
|
2022-02-27 16:25:30 +01:00
|
|
|
notification_mode = false
|
|
|
|
minetest.display_chat_message("notification mode: off")
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- command 10
|
|
|
|
minetest.register_chatcommand("chat_trigger", {
|
|
|
|
description = "if set, will only trigger notification rumbles for a specific word or name typed after the command",
|
2022-04-20 20:58:59 +02:00
|
|
|
func = function(text)
|
2022-02-27 16:25:30 +01:00
|
|
|
chat_trigger = text
|
2022-04-20 20:58:59 +02:00
|
|
|
minetest.display_chat_message("notification trigger: "..tostring(chat_trigger))
|
2022-02-26 18:47:57 +01:00
|
|
|
end,
|
|
|
|
})
|