Skip to content

Commit

Permalink
Ensure a field exists before checking it, fix for bug #422
Browse files Browse the repository at this point in the history
  • Loading branch information
brightrim committed Oct 7, 2024
1 parent d1f94a0 commit 9bd0556
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions item/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ local function getDoor(user)
for x = -Radius ,Radius do
for y = -Radius, Radius do
local targetPos = position(user.pos.x + x, user.pos.y + y, user.pos.z)
if (world:isItemOnField(targetPos)) then

local fieldExists = world:getField(targetPos)

if fieldExists and world:isItemOnField(targetPos) then
targetItem = world:getItemOnField(targetPos)
if targetItem ~= nil and (doors.CheckClosedDoor(targetItem.id) or doors.CheckOpenDoor(targetItem.id)) then
return targetItem
Expand All @@ -129,8 +132,12 @@ local function getStair(user)
local Radius = 1
for x = -Radius ,Radius do
for y = -Radius, Radius do

local targetPos = position(user.pos.x + x, user.pos.y + y, user.pos.z)
if (world:isItemOnField(targetPos)) then

local fieldExists = world:getField(targetPos)

if fieldExists and world:isItemOnField(targetPos) then
targetItem = world:getItemOnField(targetPos)

if targetItem ~= nil and targetItem.id == 4339 and not common.IsNilOrEmpty(targetItem:getData("lockId")) then
Expand Down

0 comments on commit 9bd0556

Please sign in to comment.