Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open Doors Function
Author Message
dicataldisky
Apprentice
*

Posts: 9
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Nov 2019
Reputation: 0



Post: #1
Open Doors Function
I am using the code below to open and close the doors, but I am having difficulty closing the doors when the char is inside the building ..

To be able to close the door it is necessary to be on top of the same tile, but the behavior must be that if it is 3 2 tiles from the door it must be closed!

when i have active .gm the port works the way i need ...

can anybody help me?

I recorded a video demonstrating my problem.





Code:
[FUNCTION open_door]
LOCAL.CURRENT_DOOR 0

FORITEMS 0
    IF (<TYPE> == t_door_locked) || (<TYPE> == t_door)
        IF (<EVAL ABS(<Z> - <SRC.P.Z>)> < 8)
            LOCAL.CURRENT_DOOR <UID>
            IF (<SRC.CTAG0.LAST_DOOR> != <UID>)
                DCLICK
                SRC.CTAG.LAST_DOOR <UID>
                RETURN
            ENDIF
        ENDIF
    ENDIF
ENDFOR

FORITEMS 1
    IF (<TYPE> == t_door_locked) || (<TYPE> == t_door)
        IF (<EVAL ABS(<Z> - <SRC.P.Z>)> < 8)
            LOCAL.CURRENT_DOOR <UID>
            IF (<SRC.CTAG0.LAST_DOOR> != <UID>)
                DCLICK
                SRC.CTAG.LAST_DOOR <UID>
                RETURN
            ENDIF
        ENDIF
    ENDIF
ENDFOR

FORITEMS 2
    IF (<TYPE> == t_door_locked) || (<TYPE> == t_door)
        IF (<EVAL ABS(<Z> - <SRC.P.Z>)> < 8)
            LOCAL.CURRENT_DOOR <UID>
            IF (<SRC.CTAG0.LAST_DOOR> != <UID>)
                DCLICK
                SRC.CTAG.LAST_DOOR <UID>
                RETURN
            ENDIF
        ENDIF
    ENDIF
ENDFOR

IF (<LOCAL.CURRENT_DOOR>)
    REF1 <LOCAL.CURRENT_DOOR>

    IF (<EVAL ABS(<REF1.Z> - <SRC.P.Z>)> < 8)
        REF1.DCLICK
    ENDIF
ENDIF
11-30-2019 06:03 PM
Find all posts by this user Like Post Quote this message in a reply
Coruja
Sphere Developer
*****

Posts: 987
Likes Given: 5
Likes Received: 226 in 187 posts
Joined: Jul 2012
Reputation: 7

Dimension Shard

Post: #2
RE: Open Doors Function
I don't know why you're calling 3x the same FORITEMS loop, but DCLICK function is the same thing as make the char dclick the item, so the item must be in range/LOS otherwise the DCLICK will fail, and that's why the 2nd door doesn't open/close when its out of LOS or distance is > 2 tiles. To fix this you must replace DCLICK with USEITEM, which is the same thing but USEITEM will ignore dist/LOS checks

Or you can manually link the door on each other (just use ".xlink" command or set LINK=012345) instead use this script, this will make sphere internal code automatically open the linked door
12-01-2019 09:34 AM
Find all posts by this user Like Post Quote this message in a reply
dicataldisky
Apprentice
*

Posts: 9
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Nov 2019
Reputation: 0



Post: #3
RE: Open Doors Function
(12-01-2019 09:34 AM)Coruja Wrote:  I don't know why you're calling 3x the same FORITEMS loop, but DCLICK function is the same thing as make the char dclick the item, so the item must be in range/LOS otherwise the DCLICK will fail, and that's why the 2nd door doesn't open/close when its out of LOS or distance is > 2 tiles. To fix this you must replace DCLICK with USEITEM, which is the same thing but USEITEM will ignore dist/LOS checks

Or you can manually link the door on each other (just use ".xlink" command or set LINK=012345) instead use this script, this will make sphere internal code automatically open the linked door

Right, worked, thanks!
12-01-2019 01:36 PM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)