plots_of_id #3558

Open
opened 2023-01-18 10:38:48 +00:00 by AliasAlreadyTaken · 1 comment
2023-01-18 10:37:51: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod '??' in callback on_chat_message(): (load):61: attempt to index field 'format' (a nil value)
2023-01-18 10:37:51: ERROR[Main]: stack traceback:
2023-01-18 10:37:51: ERROR[Main]: 	(load):61: in function 'func'
2023-01-18 10:37:51: ERROR[Main]: 	...inetest_test/bin/../builtin/profiler/instrumentation.lua:107: in function 'func'
2023-01-18 10:37:51: ERROR[Main]: 	/home/mt/5.6.1/Minetest_test/bin/../builtin/game/chat.lua:79: in function 'func'
2023-01-18 10:37:51: ERROR[Main]: 	...inetest_test/bin/../builtin/profiler/instrumentation.lua:107: in function <...inetest_test/bin/../builtin/profiler/instrumentation.lua:100>
2023-01-18 10:37:51: ERROR[Main]: 	.../mt/5.6.1/Minetest_test/bin/../builtin/game/register.lua:431: in function <.../mt/5.6.1/Minetest_test/bin/../builtin/game/register.lua:417>
``` 2023-01-18 10:37:51: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod '??' in callback on_chat_message(): (load):61: attempt to index field 'format' (a nil value) 2023-01-18 10:37:51: ERROR[Main]: stack traceback: 2023-01-18 10:37:51: ERROR[Main]: (load):61: in function 'func' 2023-01-18 10:37:51: ERROR[Main]: ...inetest_test/bin/../builtin/profiler/instrumentation.lua:107: in function 'func' 2023-01-18 10:37:51: ERROR[Main]: /home/mt/5.6.1/Minetest_test/bin/../builtin/game/chat.lua:79: in function 'func' 2023-01-18 10:37:51: ERROR[Main]: ...inetest_test/bin/../builtin/profiler/instrumentation.lua:107: in function <...inetest_test/bin/../builtin/profiler/instrumentation.lua:100> 2023-01-18 10:37:51: ERROR[Main]: .../mt/5.6.1/Minetest_test/bin/../builtin/game/register.lua:431: in function <.../mt/5.6.1/Minetest_test/bin/../builtin/game/register.lua:417> ```
Author
Owner
function print_plots(name, param)
    --defense
    if not areas or not areas.areas then
        return false, "Missing dependency to areas"
    end
    if not name or not param then
        return false, "Missing param. See usage /help plots_of_id"
    end
    if not core.get_player_by_name(name) then
        return false, "No legit player"
    end
    if not tonumber(param) or not areas.areas[tonumber(param)] then
        return false, "Area does not exist"
    end
    if not areas.areas[tonumber(param)].yl_city then
        return false, "Area is not a city"
    end

    local city = areas.areas[tonumber(param)]
    local pos1 = city.pos1
    local pos2 = city.pos2
    local inner_areas_of_city = areas:getAreasIntersectingArea(pos1,pos2)
    
    -- Which of those inner areas are plots?
    local plot_areas_of_city = {}
    for area_id,area in pairs(inner_areas_of_city) do
        if area.yl_plot then
            plot_areas_of_city[area_id] = area
        end
    end

    -- Find the one and only subarea of every plotarea
    local count = 1
    local t_text = {}
    t_text[count] = {"#", "ID", "Name", "Owner", "Due"}

    for plotarea_id,_ in pairs(plot_areas_of_city) do
        local children_of_plot = areas:getChildren(plotarea_id)
        if #children_of_plot ~= 1 then
            core.log("warning","[MOD] yl_cities: Plot has more than one subarea! Area ID: "..plotarea_id)
        else
            --sub_areas_of_plots[children_of_plot[1]] = areas.areas[children_of_plot[1]]
            local childarea = areas.areas[children_of_plot[1]]
            count = count +1
            
            local pauth = core.get_auth_handler().get_auth(childarea.owner)
            local due = "???"
		    if pauth and pauth.last_login and pauth.last_login ~= -1 then
			    due = os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
		    end
            
            t_text[count] = {count-1, children_of_plot[1],childarea.name,childarea.owner,due}
        end
    end

    -- return the result
    local ret = ""
    if core.get_modpath("worldeditadditions") then
        if type(worldeditadditions.make_ascii_table) == "function" then
            ret = worldeditadditions.make_ascii_table(t_text)
        elseif type(worldeditadditions.format.make_ascii_table) == "function" then
            ret = worldeditadditions.format.make_ascii_table(t_text)
        else
            core.log("error","Something went wrong, no function available")
            ret = "Something went wrong, no function available"
        end
    else
        for k, v in ipairs(t_text) do
            ret = ret .. table.concat(t_text[k], " ") .. "\n"
        end
    end

    return true,ret

end

local chatcommand_cmd = "plots_of_id"
local chatcommand_definition = {
    params = "<city area id>", -- Short parameter description
    description = "Plot status of area id", -- Full description
    privs = {staff = true}, -- Require the "privs" privilege to run
    func = function(name, param)
        return print_plots(name, param)
    end
    -- Called when command is run. Returns boolean success and text output.
    -- Special case: The help message is shown to the player if `func`
    -- returns false without a text output.
}

minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
``` function print_plots(name, param) --defense if not areas or not areas.areas then return false, "Missing dependency to areas" end if not name or not param then return false, "Missing param. See usage /help plots_of_id" end if not core.get_player_by_name(name) then return false, "No legit player" end if not tonumber(param) or not areas.areas[tonumber(param)] then return false, "Area does not exist" end if not areas.areas[tonumber(param)].yl_city then return false, "Area is not a city" end local city = areas.areas[tonumber(param)] local pos1 = city.pos1 local pos2 = city.pos2 local inner_areas_of_city = areas:getAreasIntersectingArea(pos1,pos2) -- Which of those inner areas are plots? local plot_areas_of_city = {} for area_id,area in pairs(inner_areas_of_city) do if area.yl_plot then plot_areas_of_city[area_id] = area end end -- Find the one and only subarea of every plotarea local count = 1 local t_text = {} t_text[count] = {"#", "ID", "Name", "Owner", "Due"} for plotarea_id,_ in pairs(plot_areas_of_city) do local children_of_plot = areas:getChildren(plotarea_id) if #children_of_plot ~= 1 then core.log("warning","[MOD] yl_cities: Plot has more than one subarea! Area ID: "..plotarea_id) else --sub_areas_of_plots[children_of_plot[1]] = areas.areas[children_of_plot[1]] local childarea = areas.areas[children_of_plot[1]] count = count +1 local pauth = core.get_auth_handler().get_auth(childarea.owner) local due = "???" if pauth and pauth.last_login and pauth.last_login ~= -1 then due = os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login) end t_text[count] = {count-1, children_of_plot[1],childarea.name,childarea.owner,due} end end -- return the result local ret = "" if core.get_modpath("worldeditadditions") then if type(worldeditadditions.make_ascii_table) == "function" then ret = worldeditadditions.make_ascii_table(t_text) elseif type(worldeditadditions.format.make_ascii_table) == "function" then ret = worldeditadditions.format.make_ascii_table(t_text) else core.log("error","Something went wrong, no function available") ret = "Something went wrong, no function available" end else for k, v in ipairs(t_text) do ret = ret .. table.concat(t_text[k], " ") .. "\n" end end return true,ret end local chatcommand_cmd = "plots_of_id" local chatcommand_definition = { params = "<city area id>", -- Short parameter description description = "Plot status of area id", -- Full description privs = {staff = true}, -- Require the "privs" privilege to run func = function(name, param) return print_plots(name, param) end -- Called when command is run. Returns boolean success and text output. -- Special case: The help message is shown to the player if `func` -- returns false without a text output. } minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) ```
AliasAlreadyTaken added the
1. kind/bug
label 2023-01-18 10:42:10 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: your-land/bugtracker#3558
No description provided.