XenoBot Forums - Powered by vBulletin

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Open door with key.

  1. #1
    gregory's Avatar
    Join Date
    Sep 2013
    Location
    Newcastle, England
    Posts
    145
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

    Open door with key.

    Anyone got some code for opening a door with a key?

  2. #2

    Join Date
    Apr 2013
    Posts
    2
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    Oscagi's Avatar
    Join Date
    Aug 2014
    Location
    Spain
    Posts
    237
    Mentioned
    27 Post(s)
    Tagged
    0 Thread(s)
    @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


    REMEMBER TO SAY THANKS.

  4. #4
    Senior Member Aristeus's Avatar
    Join Date
    Jun 2013
    Location
    Sweden
    Posts
    600
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Moderator shadowart's Avatar
    Join Date
    Dec 2014
    Location
    Sweden
    Posts
    1,985
    Mentioned
    225 Post(s)
    Tagged
    3 Thread(s)
    Actually, Self.UseItemWithGround doesn't work with keys. You have to use it via the container.

  6. #6

    Join Date
    Feb 2013
    Posts
    84
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shadowart View Post
    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.

  7. #7
    Moderator shadowart's Avatar
    Join Date
    Dec 2014
    Location
    Sweden
    Posts
    1,985
    Mentioned
    225 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Daffik View Post
    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.

  8. #8

    Join Date
    Jul 2013
    Posts
    48
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aristeus View Post
    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

    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

  9. #9
    Senior Member Aristeus's Avatar
    Join Date
    Jun 2013
    Location
    Sweden
    Posts
    600
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Matildabot View Post
    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.

  10. #10

    Join Date
    Jul 2013
    Posts
    48
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Okey thanks for the explanation!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •