SphereCommunity
Open Doors Function - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Open Doors Function (/Thread-Open-Doors-Function)



Open Doors Function - dicataldisky - 11-30-2019 06:03 PM

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



RE: Open Doors Function - Coruja - 12-01-2019 09:34 AM

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


RE: Open Doors Function - dicataldisky - 12-01-2019 01:36 PM

(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!