Switch curses from privs to player attributes

This commit is contained in:
ezhh 2017-10-16 12:42:57 +01:00
parent 3f3701f2e0
commit 4dbe4fa590

View File

@ -1,28 +1,14 @@
minetest.register_privilege("secret", "Wouldn't you like to know?") minetest.register_privilege("secret", "Wouldn't you like to know?")
minetest.register_privilege("frozen", {description = "Unable to move.", 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("unglitched", {description = "Not very glitchy...", give_to_singleplayer=false})
minetest.register_privilege("lost", {description = "Not allowed to use minimap.", give_to_singleplayer=false})
minetest.register_privilege("caged", {description = "Not going anywhere...", 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
local function hobble(user, target) local function hobble(user, target)
-- return if player is admin
local admin_name = minetest.setting_get ("name")
if target == admin_name then
return
end
-- apply curse
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
local privs = minetest.get_player_privs(target) player:set_attribute("hobbled", "true")
privs.hobbled = true
minetest.set_player_privs(target,privs)
player:set_physics_override({jump = 0}) player:set_physics_override({jump = 0})
end end
@ -44,16 +30,8 @@ minetest.register_chatcommand("hobble", {
-- reduces player movement speed -- reduces player movement speed
local function slowmo(name, target) local function slowmo(name, target)
-- return if player is admin
local admin_name = minetest.setting_get ("name")
if target == admin_name then
return
end
-- apply curse
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
local privs = minetest.get_player_privs(target) player:set_attribute("slowed", "true")
privs.slowed = true
minetest.set_player_privs(target, privs)
player:set_physics_override({speed = 0.3}) player:set_physics_override({speed = 0.3})
end end
@ -75,16 +53,8 @@ minetest.register_chatcommand("slowmo", {
-- disable sneak glitch for the player -- disable sneak glitch for the player
local function noglitch(name, target) local function noglitch(name, target)
-- return if player is admin
local admin_name = minetest.setting_get ("name")
if target == admin_name then
return
end
-- apply curse
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
local privs = minetest.get_player_privs(target) player:set_attribute("unglitched", "true")
privs.unglitched = true
minetest.set_player_privs(target, privs)
player:set_physics_override({sneak = false}) player:set_physics_override({sneak = false})
end end
@ -106,16 +76,8 @@ minetest.register_chatcommand("noglitch", {
-- prevent player from changing speed/direction and jumping -- prevent player from changing speed/direction and jumping
local function freeze(name, target) local function freeze(name, target)
-- return if player is admin
local admin_name = minetest.setting_get ("name")
if target == admin_name then
return
end
-- apply curse
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
local privs = minetest.get_player_privs(target) player:set_attribute("frozen", "true")
privs.frozen = true
minetest.set_player_privs(target, privs)
player:set_physics_override({jump = 0, speed = 0}) player:set_physics_override({jump = 0, speed = 0})
end end
@ -137,16 +99,8 @@ minetest.register_chatcommand("freeze", {
-- disables minimap for player -- disables minimap for player
local function getlost(name,target) local function getlost(name,target)
-- return if player is admin
local admin_name = minetest.setting_get ("name")
if target == admin_name then
return
end
-- apply curse
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
local privs = minetest.get_player_privs(target) player:set_attribute("lost", "true")
privs.lost = true
minetest.set_player_privs(target, privs)
player:hud_set_flags({minimap = false}) player:hud_set_flags({minimap = false})
end end
@ -170,19 +124,19 @@ minetest.register_chatcommand("getlost", {
-- 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 player:get_attribute("hobbled") == "true" then
hobble(name,name) hobble(name,name)
end end
if minetest.get_player_privs(name).slowed then if player:get_attribute("slowed") == "true" then
slowmo(name,name) slowmo(name,name)
end end
if minetest.get_player_privs(name).unglitched then if player:get_attribute("unglitched") == "true" then
noglitch(name,name) noglitch(name,name)
end end
if minetest.get_player_privs(name).frozen then if player:get_attribute("frozen") == "true" then
freeze(name,name) freeze(name,name)
end end
if minetest.get_player_privs(name).lost then if player:get_attribute("lost") == "true" then
getlost(name,name) getlost(name,name)
end end
end) end)
@ -198,13 +152,11 @@ minetest.register_chatcommand("setfree",{
minetest.chat_send_player(name,"Player does not exist") minetest.chat_send_player(name,"Player does not exist")
return return
end end
local privs = minetest.get_player_privs(target) player:set_attribute("hobbled", "")
privs.frozen = nil player:set_attribute("slowed", "")
privs.hobbled = nil player:set_attribute("unglitched", "")
privs.slowed = nil player:set_attribute("frozen", "")
privs.unglitched = nil player:set_attribute("lost", "")
privs.lost = nil
minetest.set_player_privs(target, privs)
player:set_physics_override({jump = 1, speed = 1, sneak = true}) player:set_physics_override({jump = 1, speed = 1, sneak = true})
player:hud_set_flags({minimap = true}) player:hud_set_flags({minimap = true})
minetest.chat_send_player(target, "The curse is lifted. You have been set free!") minetest.chat_send_player(target, "The curse is lifted. You have been set free!")