1
0
mirror of https://github.com/pandorabox-io/banners.git synced 2025-01-04 23:20:36 +01:00
banners/chatcommands.lua
Luke aka SwissalpS fe72fc27a3 add chatcommand banners_fix
fixes #7
provides a work-around for the engine problem with entities.
2024-11-29 11:59:11 +01:00

54 lines
1.7 KiB
Lua

-- Due to some engine troubles there are sometimes stray
-- banner entities and more rarely there are banner nodes without entities.
-- Calling this command fixes both situations.
core.register_chatcommand("banners_fix", {
description = "recreates the banner-visuals in your area",
func = function(name)
local player = core.get_player_by_name(name)
if not player then
return
end
local pos = player:get_pos()
local t1 = core.get_us_time()
local radius = 10
local entity_count = 0
local objects = core.get_objects_inside_radius(pos, radius)
for _, v in ipairs(objects) do
local e = v:get_luaentity()
if e and e.name == "banners:banner_ent" then
entity_count = entity_count + 1
v:remove()
end
end
local pos1 = vector.subtract(pos, radius)
local pos2 = vector.add(pos, radius)
local nodes = {
"banners:wooden_banner",
"banners:steel_banner",
}
if core.get_modpath("factions") then
table.insert_all(nodes, {
"banners:power_banner",
"banners:death_banner",
})
end
local pos_list = core.find_nodes_in_area(pos1, pos2, nodes)
for _, node_pos in ipairs(pos_list) do
core.add_entity(node_pos, "banners:banner_ent")
end
local t2 = core.get_us_time()
local diff = t2 - t1
local millis = diff / 1000
return true, "Removed " .. entity_count .. " banner entities and restored "
.. #pos_list .. " banners in " .. millis .. " ms"
end
})