From dd13f134fbce8ab7f1cc4a8fed6af8ce28f65359 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= <gabriel@gpcf.eu>
Date: Wed, 18 Jul 2018 19:29:21 +0200
Subject: Fix crash when protecting is not allowed

---
 init.lua | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'init.lua')

diff --git a/init.lua b/init.lua
index 78ba446..dec6498 100644
--- a/init.lua
+++ b/init.lua
@@ -337,6 +337,7 @@ local function protect_area(pos, dir, height, width, owner)
 		areas:save()
 		return id
 	end
+	minetest.chat_send_player(owner, errMsg)
 	return nil
 end
 
@@ -449,9 +450,12 @@ minetest.register_node("towercrane:base", {
 			if no_area_violation(owner, pos) then
 				if dir ~= nil then
 					if check_space(table.copy(pos), dir, height, width, owner) then
-						-- add protection area
-						meta:set_int("id", protect_area(table.copy(pos), table.copy(dir), height, width, owner))
+					    -- add protection area
+					    id = protect_area(table.copy(pos), table.copy(dir), height, width, owner)
+					    if id ~= nil then
+						meta:set_int("id", id)
 						construct_crane(table.copy(pos), table.copy(dir), height, width, owner)
+					    end
 					else
 						chat(owner, "area is protected or too less space to raise up the crane!")
 					end
-- 
cgit v1.2.3