Improved cage command

This commit is contained in:
ezhh 2016-07-14 18:36:17 +01:00
parent 960bb4cf94
commit 353f0f1ac9

134
init.lua
View File

@ -3,9 +3,11 @@ minetest.register_privilege("frozen", {description = "Unable to move.", give_to_
minetest.register_privilege("hobbled", {description = "Unable to jump.", give_to_singleplayer=false}) minetest.register_privilege("hobbled", {description = "Unable to jump.", give_to_singleplayer=false})
minetest.register_privilege("slowed", {description = "Slow moving.", give_to_singleplayer=false}) minetest.register_privilege("slowed", {description = "Slow moving.", give_to_singleplayer=false})
minetest.register_privilege("unglitched", {description = "Not very glitchy...", give_to_singleplayer=false}) minetest.register_privilege("unglitched", {description = "Not very glitchy...", give_to_singleplayer=false})
minetest.register_privilege("caged", {description = "Not going anywhere...", give_to_singleplayer=false})
minetest.register_privilege("hidden_one", {description = "Can hide from players.", give_to_singleplayer=false}) minetest.register_privilege("hidden_one", {description = "Can hide from players.", give_to_singleplayer=false})
--Admin Curses --Admin Curses
--prevents player from jumping. --prevents player from jumping.
@ -33,7 +35,7 @@ minetest.register_chatcommand("hobble", {
end end
}) })
--reduces player movement speed --reduces player movement speed.
local function slowmo(name, param) local function slowmo(name, param)
local player = minetest.get_player_by_name(param) local player = minetest.get_player_by_name(param)
local privs = minetest.get_player_privs(param) local privs = minetest.get_player_privs(param)
@ -83,7 +85,7 @@ minetest.register_chatcommand("noglitch", {
end end
}) })
--prevents player from changing speed/direction and jumping. --prevent player from changing speed/direction and jumping.
local function freeze(name, param) local function freeze(name, param)
local player = minetest.get_player_by_name(param) local player = minetest.get_player_by_name(param)
local privs=minetest.get_player_privs(param) local privs=minetest.get_player_privs(param)
@ -108,7 +110,7 @@ minetest.register_chatcommand("freeze", {
end end
}) })
--trigger curse effects when player joins --trigger curse effects when player joins.
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
if minetest.get_player_privs(name).hobbled then if minetest.get_player_privs(name).hobbled then
@ -125,8 +127,6 @@ minetest.register_on_joinplayer(function(player)
end end
end) end)
--reset player physics. --reset player physics.
minetest.register_chatcommand("setfree",{ minetest.register_chatcommand("setfree",{
params = "<person>", params = "<person>",
@ -154,60 +154,109 @@ minetest.register_chatcommand("setfree",{
--Cage Commands --Cage Commands
--put a player in the cage local priv_table = {}
--save table to file.
local function table_save()
local data = priv_table
local f, err = io.open(minetest.get_worldpath() .. "/curse_priv_table.txt", "w")
if err then
return err
end
f:write(minetest.serialize(data))
f:close()
end
--read saved file.
local function table_read()
local f, err = io.open(minetest.get_worldpath() .. "/curse_priv_table.txt", "r")
local data = minetest.deserialize(f:read("*a"))
f:close()
return data
end
minetest.after(3.0, function()
local f, err = io.open(minetest.get_worldpath() .. "/curse_priv_table.txt", "r")
if err then
table_save()
else
priv_table = table_read()
end
end)
minetest.register_on_shutdown(function()
table_save()
end)
--put a player in the cage.
minetest.register_chatcommand("cage", { minetest.register_chatcommand("cage", {
params = "<person>", params = "<person>",
privs = {secret=true}, privs = {secret=true},
description = "Put a player in the cage.", description = "Put a player in the cage.",
func = function(name, param) func = function(warden_name, target_name)
local player = minetest.get_player_by_name(param) --get target player or return.
if player == nil then local target = minetest.get_player_by_name(target_name)
minetest.chat_send_player(name,"Player does not exist") if not target then
minetest.chat_send_player(warden_name,"Player does not exist")
return return
end end
local privs = minetest.get_player_privs(param) --get target player's privs or return.
privs.interact=nil local privs = minetest.get_player_privs(target_name)
privs.spawn=nil if privs.caged == true then
privs.home=nil minetest.chat_send_player(warden_name,"This player is already caged")
privs.fly=nil return
privs.fast=nil end
minetest.set_player_privs(param,privs) --get cage position from config or return.
noglitch(name, param)
local cagepos = minetest.setting_get_pos("cage_coordinate") local cagepos = minetest.setting_get_pos("cage_coordinate")
if not cagepos then if not cagepos then
minetest.chat_send_player(name, "No cage set...") minetest.chat_send_player(warden_name, "No cage set...")
return false return
end end
player:setpos(cagepos) --add current target privs to table and save to file.
priv_table[target_name] = privs
table_save()
--remove all privs but shout and add caged and unglitched.
minetest.set_player_privs(target_name,{shout = true, caged = true})
noglitch(warden_name, target_name)
--move target to cage location.
target:setpos(cagepos)
end end
}) })
--free a player from the cage --free a player from the cage.
minetest.register_chatcommand("uncage", { minetest.register_chatcommand("uncage", {
params = "<person>", params = "<person>",
privs = {secret=true}, privs = {secret=true},
description = "Free a player from the cage.", description = "Free a player from the cage.",
func = function(name, param) func = function(warden_name, target_name)
local player = minetest.get_player_by_name(param) --get target player or return.
if player == nil then local target = minetest.get_player_by_name(target_name)
minetest.chat_send_player(name,"Player does not exist") if not target then
minetest.chat_send_player(warden_name,"Player does not exist")
return return
end end
local privs = minetest.get_player_privs(param) --get target player's privs or return.
privs.interact=true local privs = minetest.get_player_privs(target_name)
privs.spawn=true if privs.caged ~= true then
privs.home=true minetest.chat_send_player(warden_name,"This player is not caged")
privs.fly=true return
privs.fast=true end
privs.unglitched=nil --get spawn point position from config or return.
minetest.set_player_privs(param,privs)
player:set_physics_override({sneak = true})
local spawnpos = minetest.setting_get_pos("static_spawnpoint") local spawnpos = minetest.setting_get_pos("static_spawnpoint")
if not spawnpos then if not spawnpos then
minetest.chat_send_player(name, "No spawn point set...") minetest.chat_send_player(warden_name, "No spawn point set...")
return false return
end end
player:setpos(spawnpos) --get target's original privs from table and restore them.
local original_privs = priv_table[target_name]
minetest.set_player_privs(target_name,original_privs)
--remove entry for target from table and save to file.
priv_table[target_name] = nil
table_save()
--restore sneak and move target to spawn.
target:set_physics_override({sneak = true})
target:setpos(spawnpos)
end end
}) })
@ -215,7 +264,7 @@ minetest.register_chatcommand("uncage", {
--Other Commands --Other Commands
--hide player model and nametag (only works in 0.4.14 and above) --hide player model and nametag (only works in 0.4.14 and above).
vanished_players = {} vanished_players = {}
minetest.register_chatcommand("vanish", { minetest.register_chatcommand("vanish", {
@ -231,7 +280,7 @@ minetest.register_chatcommand("vanish", {
collisionbox = {0,0,0,0,0,0}} collisionbox = {0,0,0,0,0,0}}
player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}}) player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}})
else else
-- default player size -- default player size.
prop = {visual_size = {x = 1, y = 1}, prop = {visual_size = {x = 1, y = 1},
collisionbox = {-0.35, -1, -0.35, 0.35, 1, 0.35}} collisionbox = {-0.35, -1, -0.35, 0.35, 1, 0.35}}
player:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}}) player:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
@ -240,7 +289,7 @@ minetest.register_chatcommand("vanish", {
end end
}) })
--announcements (only works in 0.4.14 and above) --announcements.
minetest.register_chatcommand("say", { minetest.register_chatcommand("say", {
params = "<text>", params = "<text>",
description = "Sends text to all players", description = "Sends text to all players",
@ -253,3 +302,6 @@ minetest.register_chatcommand("say", {
minetest.chat_send_all(param) minetest.chat_send_all(param)
end end
}) })