There are better ways to do it.
Something like this might work.
lua code:
LockedID = ID of the locked door.
KeyID = ID of the key.
Walker.Stop()
wait(800,1600)
if Map.GetTopUseItem(X, Y, Z).id == LockedID then --- checks the id of the locked door
useKeyOnDoor(KeyID, X, Y, Z) --- opens if locked.
wait(400,600)
Walker.Start()
else
if not Map.IsTileWalkable(X, Y, Z) then Self.UseDoor(X, Y, Z) --- opens door if unlocked
Walker.Start()
end
Walker.Start() ---- If door is neither locked or closed it'll just go to the next node and walk through it
end
This is the function for "useKeyOnDoor" (paste it in the same script.)
lua code:
function useKeyOnDoor(keyID, x, y, z) --- from forgee's library
local Cont = Container.New(0) -- check in main backpack (index is 0)
if Cont:CountItemsOfID(keyID) > 0 then
for s = 0, Cont:ItemCount() do --find specific itemid spot
local item = Cont:GetItemData(s)
if item.id == keyID then
Cont:UseItemWithGround(s, x, y, z)
end
end
end
end