Aaron Suen d0e6dcc410 Add "stasis" option and command.
This freezes many things that normally happen automatically
in the world, including most ABMs and AISMs, and a few other
custom step logic items like the player "hot potato" logic.

This can be used for "creative mode" purposes to setup a complex
build without it running itself away from you, and for texture
pack authors, to have time to see things that are normally
transient or difficult to observe because of the effects they have
on nearby things or players.
2020-01-10 06:26:07 -05:00

44 lines
1.2 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore, pairs
= minetest, nodecore, pairs
-- LUALOCALS > ---------------------------------------------------------
local function hotpotatoes(player)
local inv = player:get_inventory()
local hurt = 0
local throw = {}
for i = 1, inv:get_size("main") do
local s = inv:get_stack("main", i)
local n = not s:is_empty() and s:get_name()
n = n and minetest.registered_items[n]
n = n and n.damage_per_second
if n and n > 0 then
hurt = hurt + n
inv:set_stack("main", i, "")
throw[#throw + 1] = s
end
end
if #throw > 0 then
local pname = player:get_player_name()
local pos = player:get_pos()
pos.y = pos.y + 1.2
local dir = player:get_look_dir()
dir.x = dir.x * 5
dir.y = dir.y * 5 + 3
dir.z = dir.z * 5
for _, v in pairs(throw) do
local obj = minetest.add_item(pos, v)
obj:set_velocity(dir)
obj:get_luaentity().dropped_by = pname
end
end
if hurt > 0 then player:set_hp(player:get_hp() - hurt) end
end
minetest.register_globalstep(function()
if nodecore.stasis then return end
for _, v in pairs(minetest.get_connected_players()) do
hotpotatoes(v)
end
end)