Anyone got some code for opening a door with a key?
Anyone got some code for opening a door with a key?
xxx is map tiles of the door itself
keyid is id number of the key
step (direction) is which ever way your going through, i.e if ur going north through the door 2 spets north, when ur coming back, 2 spets south, ect...
elseif (labelName == "door-check-in") then
if Map.IsTileWalkable(XXXXX, XXXXX, X) then
Self.Step(Direction)
wait(1500)
Self.Step(Direction)
wait(1500)
else
Self.UseItemWithGround(keyid, XXXXX, XXXXX, X)
wait(1500)
Self.Step(Direction)
wait(1500)
Self.Step(Direction)
wait(1500)
end
elseif (labelName == "door-check-out") then
if Map.IsTileWalkable(XXXXX, XXXXX, X) then
Self.Step(Direction)
wait(1500)
Self.Step(Direction)
wait(1500)
else
Self.UseItemWithGround(keyid, XXXXX, XXXXX, X)
wait(1500)
Self.Step(Direction)
wait(1500)
Self.Step(Direction)
wait(1500)
end
@Jayson and if u open the door for enter, when u use the key for exit u will close it.
lua code:
elseif (labelName == "DoorEnter") then
Self.OpenDoor(X,Y,Z) -- X,Y,Z Door Position.
wait(500,800)
Self.Step("Direction")
wait(500,800)
Self.Step("Direction")
wait(500,800)
if Self.Position().x == X then -- 2 steps from closed door
-- BTW if u go south/north or East/west change X for Y)
return
else Self.UseItemWithGround(ITEMID,X,Y,Z) -- X,Y,Z Door Position.
wait(500,800)
Self.Step("Direction")
wait(500,800)
Self.Step("Direction")
wait(500,800)
if Self.Position().x == X then -- 2 steps from closed door
-- BTW if u go south/north or East/west change X for Y)
return
else gotoLabel("BeforeDoorEnter")
end
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
Last edited by Aristeus; 12-23-2015 at 01:58 PM.
Actually, Self.UseItemWithGround doesn't work with keys. You have to use it via the container.
sorry i dont get it, how do you use the key via the container? with a locked door?
Also this seem rather overly complex, surly it would just be easier just to add the key's to useitemwithground? function along with everything else.
i cant find the old function list anyway, there used to be one on this forum with all the self. /container. /walker. /move. and more...
where has this gone as this would be very helpfull.
Last edited by Daffik; 11-26-2015 at 04:11 PM.
Hi!
I kinda new to do own scripts with xenobot and just wonder how i use this lines, Do i paste both of your scripts in the same Lua file namned useKeyOnDoor?
And then change the locked ID for the door i will open, and the ID of the key?
Is it just to run the Lua after that and use a Lable called useKeyOnDoor?
I can not get it to work so if anyone can explain it to me i would be very happy![]()
You also need to put in the coordinates for the door (x, y, z) in the appropriate places but don't touch anything in the function "useKeyOnDoor"
Also, you don't need to have this in a separate script just put it in the same script you're using to hunt.
Paste the second section at the end of the file and the first under the lablename that you've chosen to open the door with.
Okey thanks for the explanation!![]()