Spawner: Fix issue when "npcs" table is not present in restore_plotmarkers.

This commit is contained in:
Hector Franqui 2017-09-01 18:27:17 -04:00
parent fe5a155177
commit 8e5d6d03f4

View File

@ -228,9 +228,9 @@ function npc.spawner.determine_npc_occupation(building_type, workplace_nodes, np
for j = 1, #workplace_nodes do for j = 1, #workplace_nodes do
-- Get building types from occupation -- Get building types from occupation
local local_building_types = local local_building_types =
npc.occupations.registered_occupations[occupation_names[i]].building_type or {} npc.occupations.registered_occupations[occupation_names[i]].building_type or {}
local surrounding_building_types = local surrounding_building_types =
npc.occupations.registered_occupations[occupation_names[i]].surrounding_building_types or {} npc.occupations.registered_occupations[occupation_names[i]].surrounding_building_types or {}
minetest.log("Occupation btype: "..dump(local_building_types)) minetest.log("Occupation btype: "..dump(local_building_types))
minetest.log("Surrounding btypes: "..dump(surrounding_building_types)) minetest.log("Surrounding btypes: "..dump(surrounding_building_types))
-- Check the workplace_node is of any of those building_types -- Check the workplace_node is of any of those building_types
@ -514,12 +514,12 @@ function npc.spawner.assign_places(self, entrance, node_data, pos)
npc_name = self.npc_name, npc_name = self.npc_name,
occupation = self.occupation_name, occupation = self.occupation_name,
multiple_npcs = multiple_npcs =
npc.occupations.registered_occupations[self.occupation_name].allow_multiple_npcs_at_workplace npc.occupations.registered_occupations[self.occupation_name].allow_multiple_npcs_at_workplace
} }
meta:set_string("work_data", minetest.serialize(work_data)) meta:set_string("work_data", minetest.serialize(work_data))
-- --
-- meta = minetest.get_meta(node_data.workplace_type[i].node_pos) -- meta = minetest.get_meta(node_data.workplace_type[i].node_pos)
-- minetest.log("Work data: "..dump(minetest.deserialize(meta:get_string("work_data")))) -- minetest.log("Work data: "..dump(minetest.deserialize(meta:get_string("work_data"))))
end end
end end
end end
@ -900,11 +900,13 @@ minetest.register_chatcommand("restore_plotmarkers", {
local infotext = meta:get_string("infotext") local infotext = meta:get_string("infotext")
local npcs = minetest.deserialize(meta:get_string("npcs")) local npcs = minetest.deserialize(meta:get_string("npcs"))
-- Restore workplaces to original status -- Restore workplaces to original status
for i = 1, #npcs do if npcs then
if npcs[i].workplace then for i = 1, #npcs do
-- Remove work data if npcs[i].workplace then
local workplace_meta = minetest.get_meta(npcs[i].workplace) -- Remove work data
workplace_meta:set_string("work_data", nil) local workplace_meta = minetest.get_meta(npcs[i].workplace)
workplace_meta:set_string("work_data", nil)
end
end end
end end
-- Set metadata -- Set metadata