2023-12-26 13:37:19 +00:00
|
|
|
local weac = worldeditadditions_core
|
|
|
|
local wea = worldeditadditions
|
|
|
|
local weacmd = worldeditadditions_commands
|
|
|
|
local Vector3 = weac.Vector3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ███████ ██████ ███████ ███████ ██████
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ███████ ██████ █████ █████ ██ ██
|
|
|
|
-- ██ ██ ██ ██ ██ ██
|
|
|
|
-- ███████ ██ ███████ ███████ ██████
|
|
|
|
worldeditadditions_core.register_command("speed", {
|
|
|
|
params = "[<value=1>]",
|
|
|
|
description =
|
|
|
|
"Changes your movement speed. A value of 1 = normal speed. Prepend + or - to add or subtract a given amount from the current value.",
|
|
|
|
privs = { worldedit = true },
|
|
|
|
require_pos = 0,
|
|
|
|
parse = function(params_text)
|
|
|
|
if not params_text or params_text == "" then
|
|
|
|
params_text = "1"
|
|
|
|
end
|
|
|
|
|
|
|
|
local speed
|
|
|
|
local mode = "absolute"
|
|
|
|
|
|
|
|
params_text = weac.trim(params_text)
|
|
|
|
|
|
|
|
if params_text:sub(1,1) == "+" or params_text:sub(1,1) == "-" then
|
|
|
|
mode = "relative"
|
|
|
|
end
|
|
|
|
|
|
|
|
speed = tonumber(params_text)
|
|
|
|
|
|
|
|
if not speed then return false, "Error: Invalid speed value. The speed value must be a number." end
|
|
|
|
|
|
|
|
print("DEBUG:speed/parse PARAMS_TEXT", params_text, "MODE", mode, "SPEED", speed)
|
|
|
|
|
|
|
|
return true, mode, speed
|
|
|
|
end,
|
|
|
|
nodes_needed = function(name)
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
func = function(name, mode, speed)
|
|
|
|
local start_time = weac.get_ms_time()
|
|
|
|
|
|
|
|
print("DEBUG:speed NAME", name, "MODE", mode, "SPEED", speed)
|
|
|
|
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
|
|
|
|
if mode == "absolute" then
|
2023-12-30 13:12:10 +00:00
|
|
|
weac.player_set_physics_override(player,
|
|
|
|
"worldeditadditions_movetool", {
|
|
|
|
speed = speed,
|
|
|
|
climb_speed = speed
|
|
|
|
}
|
|
|
|
)
|
|
|
|
-- player:set_physics_override({
|
|
|
|
-- })
|
2023-12-26 13:37:19 +00:00
|
|
|
elseif mode == "relative" then
|
2023-12-30 13:12:10 +00:00
|
|
|
local overrides = weac.player_get_physics_override(
|
|
|
|
player, "worldeditadditions_movetool"
|
|
|
|
)
|
2023-12-26 13:37:19 +00:00
|
|
|
local src_speed = overrides.speed or 1
|
|
|
|
local src_climb_speed = overrides.climb_speed or 1
|
2023-12-30 13:12:10 +00:00
|
|
|
weac.player_set_physics_override(player,
|
|
|
|
"worldeditadditions_movetool", {
|
|
|
|
speed = src_speed + speed,
|
|
|
|
climb_speed = src_climb_speed + speed
|
|
|
|
}
|
|
|
|
)
|
|
|
|
-- player:set_physics_override({
|
|
|
|
-- })
|
2023-12-26 13:37:19 +00:00
|
|
|
else
|
|
|
|
return false, "Error: Unknown adjustment mode '"..tostring(mode).."'. This is a bug."
|
|
|
|
end
|
|
|
|
|
2023-12-30 13:12:10 +00:00
|
|
|
local overrides_after = weac.player_get_physics_override(
|
|
|
|
player, "worldeditadditions_movetool"
|
|
|
|
)
|
|
|
|
-- local overrides_after = player:get_physics_override()
|
2023-12-26 13:37:19 +00:00
|
|
|
|
|
|
|
local time_taken = weac.get_ms_time() - start_time
|
|
|
|
|
|
|
|
return true, "Movement speed is now x"..tostring(overrides_after.speed).."."
|
|
|
|
end
|
|
|
|
})
|