PDA

View Full Version : Open door with key.



gregory
11-19-2015, 06:24 PM
Anyone got some code for opening a door with a key?

Jayson
11-19-2015, 11:01 PM
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

Oscagi
11-20-2015, 09:56 AM
Jayson and if u open the door for enter, when u use the key for exit u will close it.


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

Aristeus
11-20-2015, 02:19 PM
There are better ways to do it.

Something like this might work.



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.)


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

shadowart
11-20-2015, 08:11 PM
Actually, Self.UseItemWithGround doesn't work with keys. You have to use it via the container.

Daffik
11-26-2015, 03:31 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.

shadowart
11-26-2015, 11:15 PM
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.
Read Aristeus post.

Matildabot
01-01-2016, 07:12 PM
There are better ways to do it.

Something like this might work.



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.)


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



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 :D

Aristeus
01-01-2016, 08:13 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 :D

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.

Matildabot
01-01-2016, 09:12 PM
Okey thanks for the explanation! :)

sholh
01-10-2016, 03:55 PM
its doesnt work

artichunter123
03-06-2016, 04:38 PM
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.


Hello there! im having some trouble getting this script to work, what am I doing wrong? didnt really understand what to do just paste it into my "hunting script"?

Walker.Stop()
wait(800,1600)
if Map.GetTopUseItem(32190, 32432, 8).id == 1632 then --- checks the id of the locked door
useKeyOnDoor(2968, 32190, 32432, 8) --- opens if locked.
wait(400,600)
Walker.Start()
else
if not Map.IsTileWalkable(32190, 32432, 8) then Self.UseDoor(32190, 32432, 8) --- 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
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

Aristeus
03-06-2016, 05:52 PM
Hello there! im having some trouble getting this script to work, what am I doing wrong? didnt really understand what to do just paste it into my "hunting script"?

Walker.Stop()
wait(800,1600)
if Map.GetTopUseItem(32190, 32432, 8).id == 1632 then --- checks the id of the locked door
useKeyOnDoor(2968, 32190, 32432, 8) --- opens if locked.
wait(400,600)
Walker.Start()
else
if not Map.IsTileWalkable(32190, 32432, 8) then Self.UseDoor(32190, 32432, 8) --- 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
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

Impossible for me to say what you're doing wrong with so little information. You'll have to describe what's not working.

The function should be pasted in the same script but not in the same label. Just put it at the end of the script. Only the first part should trigger at a specific label.

artichunter123
03-06-2016, 08:03 PM
Impossible for me to say what you're doing wrong with so little information. You'll have to describe what's not working.

The function should be pasted in the same script but not in the same label. Just put it at the end of the script. Only the first part should trigger at a specific label.



I just get a error message when im trying to make a label in the script, (Error: '<eof>' expected near 'elseif') dont know what im doing wrong, could you help me out? haha

KeyId=2968
x=32190
y=32432
z=8


elseif (labelName == "OpenDoor") then
Walker.Stop()
wait(800,1600)
if Map.GetTopUseItem(32190, 32432, 8).id == LockedID then --- checks the id of the locked door
useKeyOnDoor(2968, 32190, 32432, 8) --- opens if locked.
wait(400,600)
Walker.Start()
else
if not Map.IsTileWalkable(32190, 32432, 8) then Self.UseDoor(32190, 32432, 8) --- 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

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

this is what I pasted in my hunting script..

Aristeus
03-06-2016, 09:10 PM
I just get a error message when im trying to make a label in the script, (Error: '<eof>' expected near 'elseif') dont know what im doing wrong, could you help me out? haha

KeyId=2968
x=32190
y=32432
z=8


elseif (labelName == "OpenDoor") then
Walker.Stop()
wait(800,1600)
if Map.GetTopUseItem(32190, 32432, 8).id == LockedID then --- checks the id of the locked door
useKeyOnDoor(2968, 32190, 32432, 8) --- opens if locked.
wait(400,600)
Walker.Start()
else
if not Map.IsTileWalkable(32190, 32432, 8) then Self.UseDoor(32190, 32432, 8) --- 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

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

this is what I pasted in my hunting script..

I'm still having trouble understanding what you're pasting where. You shouldn't even be getting that bug if you followed the instructions correctly. Can't really help you with it either since it might be in some other part of the script (eof = end of function).

I'd suggest you read some basic guides on scripting first. None of this is particularly hard if you have the basics under control.

Good guide to start with: http://forums.xenobot.net/showthread.php?14664-100-AFK-Script-Making

artichunter123
03-07-2016, 11:22 AM
I'm still having trouble understanding what you're pasting where. You shouldn't even be getting that bug if you followed the instructions correctly. Can't really help you with it either since it might be in some other part of the script (eof = end of function).

I'd suggest you read some basic guides on scripting first. None of this is particularly hard if you have the basics under control.

Good guide to start with: http://forums.xenobot.net/showthread.php?14664-100-AFK-Script-Making

Okey, thanks :)

krille09
03-08-2016, 04:14 AM
Okey, thanks :)

I think you are copying scripts into wrong place, I think your putting function inside the function and I think that won't work, unsure tho, but what you really are missing is an "end" somewhere...

Post your WHOLE lua here and I can try help you, or if you wish, in private...

artichunter123
03-08-2016, 08:23 PM
I think you are copying scripts into wrong place, I think your putting function inside the function and I think that won't work, unsure tho, but what you really are missing is an "end" somewhere...

Post your WHOLE lua here and I can try help you, or if you wish, in private...

Oh, thats very nice of you. I checked some other scripts and found out exactly what you said haha, I put the function in the wrong place. Got it working now :D