Update slowmo command to accept alternative speeds

This commit is contained in:
Ezhh 2018-07-01 22:42:59 +01:00
parent 8a778746f8
commit f94d441b6d

View File

@ -28,24 +28,38 @@ minetest.register_chatcommand("hobble", {
}) })
-- reduces player movement speed -- reduces player movement speed
local function slowmo(name, target) local default_slow = 0.3
local function slowmo(name, target, speed)
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
player:set_attribute("slowed", "true") player:set_attribute("slowed", speed)
player:set_physics_override({speed = 0.3}) player:set_physics_override({speed = speed})
end end
minetest.register_chatcommand("slowmo", { minetest.register_chatcommand("slowmo", {
params = "<person>", params = "<person> <speed>",
privs = {secret=true}, privs = {secret = true},
description = "Reduce player movement speed.", description = "Reduce player movement speed.",
func = function(name, target)
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
local player = minetest.get_player_by_name(target) local player = minetest.get_player_by_name(target)
if player == nil then if player == nil then
return false, "Player does not exist." return false, "Player does not exist."
end end
slowmo(name,target)
if speed == nil or speed == "" or
tonumber(speed) > 1.0 or tonumber(speed) < 0.1 then
speed = default_slow
end
slowmo(name, target, speed)
minetest.chat_send_player(target, "Cursed by an admin! You feel sloooooow!") minetest.chat_send_player(target, "Cursed by an admin! You feel sloooooow!")
minetest.chat_send_player(name, "Curse successful!") minetest.chat_send_player(name, "Curse successful! "..target.."'s speed set to "..speed)
end end
}) })
@ -122,8 +136,9 @@ minetest.register_on_joinplayer(function(player)
if player:get_attribute("hobbled") == "true" then if player:get_attribute("hobbled") == "true" then
hobble(name,name) hobble(name,name)
end end
if player:get_attribute("slowed") == "true" then local slowed = player:get_attribute("slowed")
slowmo(name,name) if slowed then
slowmo(name,name, tonumber(slowed))
end end
if player:get_attribute("frozen") == "true" then if player:get_attribute("frozen") == "true" then
freeze(name,name) freeze(name,name)
@ -221,6 +236,9 @@ minetest.register_chatcommand("curses",{
result = result..status_list[i].." " result = result..status_list[i].." "
end end
end end
if player:get_attribute("slowed") ~= "" then
result = result.."slowed("..player:get_attribute("slowed")..")"
end
minetest.chat_send_player(user_name, result.." Sneak mode: "..player:get_attribute("sneak_mode")) minetest.chat_send_player(user_name, result.." Sneak mode: "..player:get_attribute("sneak_mode"))
return return
end end