catcommands/init.lua

363 lines
11 KiB
Lua
Raw Normal View History

2016-07-01 18:59:00 +01:00
minetest.register_privilege("secret", "Wouldn't you like to know?")
2016-07-03 19:50:27 +01:00
minetest.register_privilege("hidden_one", {description = "Can hide from players.", give_to_singleplayer=false})
2016-07-01 18:59:00 +01:00
2017-10-22 21:00:08 +01:00
local default_sneak_mode = "old" -- change this to "new" if you want new movement.
2016-07-04 19:26:28 +01:00
2016-12-12 14:42:45 +00:00
-- Admin Curses
2016-07-01 18:59:00 +01:00
2016-12-12 14:42:45 +00:00
-- prevents player from jumping
2017-09-09 17:53:12 +01:00
local function hobble(user, target)
2017-10-17 22:14:29 +01:00
local player = minetest.get_player_by_name(target)
player:set_attribute("hobbled", "true")
player:set_physics_override({jump = 0})
2016-07-01 18:59:00 +01:00
end
2016-07-03 18:05:46 +01:00
2016-07-01 18:59:00 +01:00
minetest.register_chatcommand("hobble", {
2017-10-17 22:14:29 +01:00
params = "<person>",
privs = {secret=true},
description = "Prevent player jumping.",
func = function(name, target)
local player = minetest.get_player_by_name(target)
if player == nil then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
hobble(name, target)
minetest.chat_send_player(target, "Cursed by an admin! No more jumping!")
minetest.chat_send_player(name, "Curse successful!")
end
2016-07-01 18:59:00 +01:00
})
2016-12-12 14:42:45 +00:00
-- reduces player movement speed
local default_slow = 0.3
local function slowmo(name, target, speed)
2017-10-17 22:14:29 +01:00
local player = minetest.get_player_by_name(target)
player:set_attribute("slowed", speed)
player:set_physics_override({speed = speed})
2016-07-01 18:59:00 +01:00
end
2016-07-03 18:05:46 +01:00
2016-07-01 18:59:00 +01:00
minetest.register_chatcommand("slowmo", {
params = "<person> <speed>",
privs = {secret = true},
2017-10-17 22:14:29 +01:00
description = "Reduce player movement speed.",
func = function(name, params)
local target, speed = params:match("^(%S+)%s*([%d.]*)$")
if target == nil or target == "" then
return false, "You must enter a player name, optionally followed by speed."
end
2017-10-17 22:14:29 +01:00
local player = minetest.get_player_by_name(target)
if player == nil then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
if speed == nil or speed == "" or
tonumber(speed) > 1.0 or tonumber(speed) < 0.1 then
speed = default_slow
end
slowmo(name, target, speed)
2017-10-17 22:14:29 +01:00
minetest.chat_send_player(target, "Cursed by an admin! You feel sloooooow!")
minetest.chat_send_player(name, "Curse successful! "..target.."'s speed set to "..speed)
2017-10-17 22:14:29 +01:00
end
2016-07-01 18:59:00 +01:00
})
2016-12-12 14:42:45 +00:00
-- prevent player from changing speed/direction and jumping
2017-09-09 17:53:12 +01:00
local function freeze(name, target)
2017-10-17 22:14:29 +01:00
local player = minetest.get_player_by_name(target)
player:set_attribute("frozen", "true")
player:set_physics_override({jump = 0, speed = 0})
end
minetest.register_chatcommand("freeze", {
2017-10-17 22:14:29 +01:00
params = "<person>",
privs = {secret=true},
description = "Prevent player movement.",
func = function(name, target)
local player = minetest.get_player_by_name(target)
if player == nil then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
freeze(name, target)
minetest.chat_send_player(target, "Cursed by an admin! You are now frozen!")
minetest.chat_send_player(name, "Curse successful!")
end
})
2017-03-24 19:58:15 +00:00
-- disables minimap for player
2017-09-09 17:53:12 +01:00
local function getlost(name,target)
2017-10-17 22:14:29 +01:00
local player = minetest.get_player_by_name(target)
player:set_attribute("lost", "true")
player:hud_set_flags({minimap = false})
2017-03-24 19:58:15 +00:00
end
minetest.register_chatcommand("getlost", {
2017-10-17 22:14:29 +01:00
params = "<person>",
privs = {secret=true},
description = "Prevent player from using the minimap.",
func = function(name, target)
local player = minetest.get_player_by_name(target)
if player == nil then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
getlost(name,target)
minetest.chat_send_player(target, "Cursed by an admin! You will get lost now!")
minetest.chat_send_player(name, "Curse successful!")
end
2017-03-24 19:58:15 +00:00
})
2017-10-24 01:24:57 +01:00
-- lower light levels for player
local function blind(name,target)
local player = minetest.get_player_by_name(target)
player:set_attribute("blind", "true")
player:override_day_night_ratio(0.05)
end
minetest.register_chatcommand("blind", {
params = "<person>",
privs = {secret=true},
description = "Place player in eternal night time.",
func = function(name, target)
local player = minetest.get_player_by_name(target)
if player == nil then
return false, "Player does not exist."
end
blind(name,target)
minetest.chat_send_player(target, "Cursed by an admin! Eternal night time!")
minetest.chat_send_player(name, "Curse successful!")
end
})
2017-03-24 19:58:15 +00:00
2016-12-12 14:42:45 +00:00
-- trigger curse effects when player joins
minetest.register_on_joinplayer(function(player)
2017-10-17 22:14:29 +01:00
local name = player:get_player_name()
if player:get_attribute("hobbled") == "true" then
hobble(name,name)
end
local slowed = player:get_attribute("slowed")
if slowed then
slowmo(name,name, tonumber(slowed))
2017-10-17 22:14:29 +01:00
end
if player:get_attribute("frozen") == "true" then
freeze(name,name)
end
if player:get_attribute("lost") == "true" then
getlost(name,name)
end
2017-10-24 01:24:57 +01:00
if player:get_attribute("blind") == "true" then
blind(name,name)
end
2017-10-22 21:00:08 +01:00
-- set sneak mode if unassigned
if player:get_attribute("sneak_mode") == nil then
player:set_attribute("sneak_mode", default_sneak_mode)
end
-- set movement physics based on sneak_mode
2017-10-22 14:33:17 +01:00
if player:get_attribute("sneak_mode") == "old" then
2017-10-22 21:00:08 +01:00
player:set_physics_override({new_move = false, sneak_glitch = true, sneak = true})
2017-10-22 14:33:17 +01:00
elseif player:get_attribute("sneak_mode") == "new" then
2017-10-22 21:00:08 +01:00
player:set_physics_override({new_move = true, sneak_glitch = false, sneak = true})
elseif player:get_attribute("sneak_mode") == "none" then
player:set_physics_override({sneak = false})
end
end)
2016-12-12 14:42:45 +00:00
-- reset player physics
2016-07-01 18:59:00 +01:00
minetest.register_chatcommand("setfree",{
2017-10-17 22:14:29 +01:00
params = "<person>",
privs = {secret=true},
description = "Reset player movement.",
func = function(name, target)
local player = minetest.get_player_by_name(target)
if player == nil then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
player:set_attribute("hobbled", "")
player:set_attribute("slowed", "")
player:set_attribute("frozen", "")
player:set_attribute("lost", "")
2017-10-24 01:24:57 +01:00
player:set_attribute("blind", "")
2017-10-17 22:14:29 +01:00
player:set_physics_override({jump = 1, speed = 1, sneak = true})
player:hud_set_flags({minimap = true})
2017-10-24 01:24:57 +01:00
player:override_day_night_ratio(nil)
2017-10-17 22:14:29 +01:00
minetest.chat_send_player(target, "The curse is lifted. You have been set free!")
minetest.chat_send_player(name, "The curse is lifted.")
2017-10-22 14:33:17 +01:00
end
2016-07-01 18:59:00 +01:00
})
2016-07-03 19:50:27 +01:00
2017-10-22 14:33:17 +01:00
-- set sneak mode
local function sneak_mode(player, mode)
player:set_attribute("sneak_mode", mode)
if mode == "old" then
player:set_physics_override({new_move = false, sneak_glitch = true, sneak = true})
elseif mode == "new" then
player:set_physics_override({new_move = true, sneak_glitch = false, sneak = true})
elseif mode == "none" then
player:set_physics_override({sneak = false})
end
end
minetest.register_chatcommand("set_sneak",{
params = "<player> <old | new | none>",
privs = {secret = true},
description = "Set sneak mode for player.",
func = function(name, params)
local target, mode = params:match("(%S+)%s+(.+)")
if not target and not reason then
return false, "Must include player name and sneak mode."
end
local player = minetest.get_player_by_name(target)
if not player then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-22 14:33:17 +01:00
end
if not mode or (mode ~= "old" and mode ~= "new" and mode ~= "none") then
return false, "Set a mode: old, new or none."
end
sneak_mode(player, mode)
end
})
2016-07-03 19:50:27 +01:00
2017-10-22 21:52:56 +01:00
-- check player status
minetest.register_chatcommand("curses",{
params = "<person>",
privs = {secret = true},
description = "Check player status.",
func = function(user_name, target_name)
local player = minetest.get_player_by_name(target_name)
if player == nil then
return false, "Player does not exist."
end
local result = "Status for player "..target_name..": "
2017-10-24 01:24:57 +01:00
local status_list = {"hobbled", "slowed", "frozen", "lost", "blind", "caged"}
2017-10-22 21:52:56 +01:00
for i, status in ipairs(status_list) do
if player:get_attribute(status_list[i]) == "true" then
result = result..status_list[i].." "
end
end
if player:get_attribute("slowed") ~= "" then
result = result.."slowed("..player:get_attribute("slowed")..")"
end
2017-10-22 21:52:56 +01:00
minetest.chat_send_player(user_name, result.." Sneak mode: "..player:get_attribute("sneak_mode"))
return
end
})
2016-12-12 14:42:45 +00:00
-- Cage Commands
2016-07-04 19:26:28 +01:00
2016-12-12 14:42:45 +00:00
-- put a player in the cage
2016-07-04 19:26:28 +01:00
minetest.register_chatcommand("cage", {
2017-10-17 22:14:29 +01:00
params = "<person>",
privs = {secret=true},
description = "Put a player in the cage.",
func = function(warden_name, target_name)
2017-10-22 14:33:17 +01:00
-- prevent self-caging
2017-10-17 22:14:29 +01:00
if warden_name == target_name then
2017-10-22 18:33:57 +01:00
return false, "You can't cage yourself."
2017-10-17 22:14:29 +01:00
end
-- get target player or return
local target = minetest.get_player_by_name(target_name)
if not target then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
-- return if already caged
if target:get_attribute("caged") == "true" then
2017-10-22 18:33:57 +01:00
return false, "This player is already caged."
2017-10-17 22:14:29 +01:00
end
-- get cage position from config or return
local cagepos = minetest.setting_get_pos("cage_coordinate")
if not cagepos then
2017-10-22 18:33:57 +01:00
return false, "No cage set..."
2017-10-17 22:14:29 +01:00
end
2017-10-23 02:33:14 +01:00
-- save then remove all privs other than shout
local target_privs = minetest.privs_to_string(minetest.get_player_privs(target_name))
target:set_attribute("caged_privs", target_privs)
minetest.chat_send_player(warden_name, target:get_attribute("caged_privs"))
2017-10-17 22:14:29 +01:00
minetest.set_player_privs(target_name,{shout = true})
target:set_attribute("caged", "true")
2017-10-22 14:33:17 +01:00
sneak_mode(target, "none")
2017-10-17 22:14:29 +01:00
target:setpos(cagepos)
end
2016-07-04 19:26:28 +01:00
})
2016-12-12 14:42:45 +00:00
-- free a player from the cage
2016-07-04 19:26:28 +01:00
minetest.register_chatcommand("uncage", {
2017-10-17 22:14:29 +01:00
params = "<person>",
privs = {secret=true},
description = "Free a player from the cage.",
func = function(warden_name, target_name)
-- get target player or return
local target = minetest.get_player_by_name(target_name)
if not target then
2017-10-22 18:33:57 +01:00
return false, "Player does not exist."
2017-10-17 22:14:29 +01:00
end
-- return if not caged
if target:get_attribute("caged") ~= "true" then
2017-10-22 18:33:57 +01:00
return false, "This player is not caged."
2017-10-17 22:14:29 +01:00
end
-- get release position from config or return
local releasepos = minetest.setting_get_pos("release_coordinate")
if not releasepos then
2017-10-22 18:33:57 +01:00
return false, "No release point set..."
2017-10-17 22:14:29 +01:00
end
2017-10-23 02:33:14 +01:00
-- restore privs and release
local original_privs = minetest.string_to_privs(target:get_attribute("caged_privs"))
minetest.set_player_privs(target_name, original_privs)
target:set_attribute("caged_privs", nil)
2017-10-22 21:00:08 +01:00
sneak_mode(target, default_sneak_mode)
2017-10-17 22:14:29 +01:00
target:set_attribute("caged", "")
target:setpos(releasepos)
end
2016-07-04 19:26:28 +01:00
})
2016-12-12 14:42:45 +00:00
-- Other Commands
2016-07-03 19:50:27 +01:00
2016-12-12 14:42:45 +00:00
-- hide player model and nametag (only works in 0.4.14 and above)
2016-07-03 19:50:27 +01:00
vanished_players = {}
minetest.register_chatcommand("vanish", {
2017-10-17 22:14:29 +01:00
params = "",
description = "Make user invisible",
privs = {hidden_one = true},
func = function(user)
local prop
local player = minetest.get_player_by_name(user)
vanished_players[user] = not vanished_players[user]
if vanished_players[user] then
prop = {visual_size = {x = 0, y = 0},
collisionbox = {0,0,0,0,0,0}}
player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}})
else
-- default player size.
prop = {visual_size = {x = 1, y = 1},
collisionbox = {-0.35, -1, -0.35, 0.35, 1, 0.35}}
player:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
end
player:set_properties(prop)
end
2016-07-03 19:50:27 +01:00
})
2016-12-12 14:42:45 +00:00
-- announcements
2016-07-25 00:40:37 +01:00
minetest.register_chatcommand("proclaim", {
2017-10-17 22:14:29 +01:00
params = "<text>",
description = "Sends text to all players",
privs = {server = true},
func = function (user, text)
if not text
or text == "" then
return
end
minetest.chat_send_all(text)
if minetest.get_modpath("irc") then
if irc.connected and irc.config.send_join_part then
irc:say(text)
end
end
end
2016-07-03 19:50:27 +01:00
})
2016-07-14 18:36:17 +01:00