rumble/init.lua

131 lines
3.7 KiB
Lua

-- rumble - Client side mod for Minetest
-- Scripted by: Li0n
-- configureable settings:
local rumble_strength_max_standard = 0.5
local rumble_duration_max_standard = 5
-- To do list:
-- sadist mode
-- tnt griefer mode
-- chat mode: trigger from specific words written by either yourself (humiliation) or others (degradation)
local rumble_strength_max = rumble_strength_max_standard
local rumble_duration_max = rumble_duration_max_standard
local log
local log_mode
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
local no_log_no_chat = function(text)
end
-- step 1 (start)
minetest.register_on_mods_loaded(function()
minetest.display_chat_message("rumble mod loaded. May the rumble be with you!")
log = log_and_chat
log_mode = "log and chat"
end)
-- step 2 (take damage)
minetest.register_on_damage_taken(function(hp)
local rumble_strength = math.min( hp/20, rumble_strength_max )
local rumble_duration = math.min( hp, rumble_duration_max )
log("[rumble] ".."queue "..rumble_strength.." "..rumble_duration)
end)
-- step 3 (die)
minetest.register_on_death(function()
log("[rumble] instant 0 0")
end)
-- step 4 (disconnect)
minetest.register_on_shutdown(function()
log("[rumble] instant 0 0")
end)
-- step 5 (commands)
-- command 1
minetest.register_chatcommand("strength", {
description = "set max rumble strength (from 0 to 1)",
func = function(text)
if (string.match((text), "^%d+%.?%d*$")) then
rumble_strength_max = text
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
end,
})
-- command 2
minetest.register_chatcommand("duration", {
description = "set max rumble duration (in seconds)",
func = function(text)
if (string.match((text), "^%d+%.?%d*$")) then
rumble_duration_max = text
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,
})
-- command 3
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)
end,
})
-- command 4
minetest.register_chatcommand("chat_off", {
description = "disables rumble logs being written into chat",
func = function()
log = log_only
log_mode = "log only"
minetest.display_chat_message("rumble chat turned off")
end,
})
-- command 5
minetest.register_chatcommand("chat_on", {
description = "enables rumble logs being written into chat",
func = function()
log = log_and_chat
log_mode = "log and chat"
minetest.display_chat_message("rumble chat turned on")
end,
})
-- command 6
minetest.register_chatcommand("stop", {
description = "pauses logging",
func = function()
log = no_log_no_chat
log_mode = "no log no chat"
minetest.display_chat_message("rumble logging paused")
end,
})
-- command 7
minetest.register_chatcommand("resume", {
description = "resumes the rumble program",
func = function()
log = log_only
log_mode = "log only"
minetest.display_chat_message("rumble logging resumed")
end,
})