Minetest-WorldEditAdditions/worldeditadditions_commands/commands/extra/speed.lua
Starbeamrainbowlabs 2f98b86c5f
movetool, //speed: add optdepend on pova
pova is a physics_override manager mod, so it's important we have support for it to ensure we play nice with other mods
Ref https://content.minetest.net/packages/TenPlus1/pova/
2023-12-30 13:12:10 +00:00

87 lines
2.7 KiB
Lua

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
weac.player_set_physics_override(player,
"worldeditadditions_movetool", {
speed = speed,
climb_speed = speed
}
)
-- player:set_physics_override({
-- })
elseif mode == "relative" then
local overrides = weac.player_get_physics_override(
player, "worldeditadditions_movetool"
)
local src_speed = overrides.speed or 1
local src_climb_speed = overrides.climb_speed or 1
weac.player_set_physics_override(player,
"worldeditadditions_movetool", {
speed = src_speed + speed,
climb_speed = src_climb_speed + speed
}
)
-- player:set_physics_override({
-- })
else
return false, "Error: Unknown adjustment mode '"..tostring(mode).."'. This is a bug."
end
local overrides_after = weac.player_get_physics_override(
player, "worldeditadditions_movetool"
)
-- local overrides_after = player:get_physics_override()
local time_taken = weac.get_ms_time() - start_time
return true, "Movement speed is now x"..tostring(overrides_after.speed).."."
end
})