From 353f0f1ac9862bf78b623a8d127dfc157c162832 Mon Sep 17 00:00:00 2001 From: ezhh Date: Thu, 14 Jul 2016 18:36:17 +0100 Subject: [PATCH] Improved cage command --- init.lua | 134 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 41 deletions(-) diff --git a/init.lua b/init.lua index d226e46..48b9e25 100644 --- a/init.lua +++ b/init.lua @@ -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("slowed", {description = "Slow moving.", 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}) + --Admin Curses --prevents player from jumping. @@ -33,7 +35,7 @@ minetest.register_chatcommand("hobble", { end }) ---reduces player movement speed +--reduces player movement speed. local function slowmo(name, param) local player = minetest.get_player_by_name(param) local privs = minetest.get_player_privs(param) @@ -83,7 +85,7 @@ minetest.register_chatcommand("noglitch", { end }) ---prevents player from changing speed/direction and jumping. +--prevent player from changing speed/direction and jumping. local function freeze(name, param) local player = minetest.get_player_by_name(param) local privs=minetest.get_player_privs(param) @@ -108,7 +110,7 @@ minetest.register_chatcommand("freeze", { end }) ---trigger curse effects when player joins +--trigger curse effects when player joins. minetest.register_on_joinplayer(function(player) local name = player:get_player_name() if minetest.get_player_privs(name).hobbled then @@ -125,8 +127,6 @@ minetest.register_on_joinplayer(function(player) end end) - - --reset player physics. minetest.register_chatcommand("setfree",{ params = "", @@ -154,60 +154,109 @@ minetest.register_chatcommand("setfree",{ --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", { params = "", privs = {secret=true}, description = "Put a player in the cage.", - func = function(name, param) - local player = minetest.get_player_by_name(param) - if player == nil then - minetest.chat_send_player(name,"Player does not exist") + func = function(warden_name, target_name) + --get target player or return. + local target = minetest.get_player_by_name(target_name) + if not target then + minetest.chat_send_player(warden_name,"Player does not exist") return end - local privs = minetest.get_player_privs(param) - privs.interact=nil - privs.spawn=nil - privs.home=nil - privs.fly=nil - privs.fast=nil - minetest.set_player_privs(param,privs) - noglitch(name, param) + --get target player's privs or return. + local privs = minetest.get_player_privs(target_name) + if privs.caged == true then + minetest.chat_send_player(warden_name,"This player is already caged") + return + end + --get cage position from config or return. local cagepos = minetest.setting_get_pos("cage_coordinate") if not cagepos then - minetest.chat_send_player(name, "No cage set...") - return false + minetest.chat_send_player(warden_name, "No cage set...") + return 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 }) ---free a player from the cage +--free a player from the cage. minetest.register_chatcommand("uncage", { params = "", privs = {secret=true}, description = "Free a player from the cage.", - func = function(name, param) - local player = minetest.get_player_by_name(param) - if player == nil then - minetest.chat_send_player(name,"Player does not exist") + func = function(warden_name, target_name) + --get target player or return. + local target = minetest.get_player_by_name(target_name) + if not target then + minetest.chat_send_player(warden_name,"Player does not exist") return end - local privs = minetest.get_player_privs(param) - privs.interact=true - privs.spawn=true - privs.home=true - privs.fly=true - privs.fast=true - privs.unglitched=nil - minetest.set_player_privs(param,privs) - player:set_physics_override({sneak = true}) + --get target player's privs or return. + local privs = minetest.get_player_privs(target_name) + if privs.caged ~= true then + minetest.chat_send_player(warden_name,"This player is not caged") + return + end + --get spawn point position from config or return. local spawnpos = minetest.setting_get_pos("static_spawnpoint") if not spawnpos then - minetest.chat_send_player(name, "No spawn point set...") - return false + minetest.chat_send_player(warden_name, "No spawn point set...") + return 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 }) @@ -215,7 +264,7 @@ minetest.register_chatcommand("uncage", { --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 = {} minetest.register_chatcommand("vanish", { @@ -231,7 +280,7 @@ minetest.register_chatcommand("vanish", { collisionbox = {0,0,0,0,0,0}} player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}}) else - -- default player size + -- 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}}) @@ -240,7 +289,7 @@ minetest.register_chatcommand("vanish", { end }) ---announcements (only works in 0.4.14 and above) +--announcements. minetest.register_chatcommand("say", { params = "", description = "Sends text to all players", @@ -253,3 +302,6 @@ minetest.register_chatcommand("say", { minetest.chat_send_all(param) end }) + + +