Paste #108768: Expressive

Date: 2023/04/13 06:35:06 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


## Expressive Sleep needs to check for nearby beds and place the player's head in the correct location.

ExpressiveSleepCommand:
    debug: true
    type: command
    name: sleep
    description: Causes the player to go to sleep.
    usage: /sleep
    script:
    - if !<player.has_flag[ExpressiveSleeping]>:
        - narrate "No Flag"
        - narrate <player.name>
        - define PlayerYaw <player.location.yaw>
        - define CalculatedYaw <element[270].sub[<[PlayerYaw]>]>
        - define RotatedLocation <player.location.with_yaw[<[CalculatedYaw]>]>
        - create player <player.name> <[RotatedLocation]> save:SleepBodyDouble
        - define SleepBodyDouble <entry[SleepBodyDouble].created_npc>
        - narrate <[SleepBodyDouble]>
        - animate <[SleepBodyDouble]> animation:arm_swing
        - sleep npc:<[SleepBodyDouble]>

        - fakeequip <player> head:air chest:air legs:air boots:air for:<server.online_players>
        - invisible <player> state:true
        - flag <player> ExpressiveSleepOriginalLocation:<player.location>
        - teleport <player> <player.location.sub[<player.location.with_pitch[0].direction.vector.mul[1.6]>].with_y[<player.location.y.sub[0.8]>]>
        - animate <player> animation:sit
        - flag <player> ExpressiveSleeping
        - flag <player> SleepBodyDouble:<[SleepBodyDouble]>

        - wait 5t
        - teleport <[SleepBodyDouble]> <[SleepBodyDouble].location.rotate_yaw[50]>
        - wait 6t
        - teleport <[SleepBodyDouble]> <[SleepBodyDouble].location.rotate_yaw[-100]>
        - wait 5t
        - teleport <[SleepBodyDouble]> <[SleepBodyDouble].location.rotate_yaw[50]>

        - run ExpressiveSleepTask def:<[SleepBodyDouble]>|<[CalculatedYaw]>|<[PlayerYaw]>

        - clickable save:sleep_broadcast_request_clickable:
            - if !<player.has_flag[ExpressiveTimerB]>:
                - narrate "<&6><player.name><&f> is requesting that players go to sleep!" targets:<server.online_players>
                - flag <player> ExpressiveTimerB expire:60s
        - narrate "<&f>Click <&6><element[<&lb>Here<&rb>].on_click[<entry[sleep_broadcast_request_clickable].command>]><&f> to ask others to sleep!"

        - stop

    - if <player.has_flag[ExpressiveSleeping]>:
        - teleport <player> <player.flag[ExpressiveSleepOriginalLocation].with_yaw[<player.location.yaw>].with_pitch[<player.location.pitch>]>
        - animate <player> animation:stop_sitting
        - invisible <player> state:false
        - remove <player.flag[SleepBodyDouble]>
        - flag <player> SleepBodyDouble:!
        - flag <player> ExpressiveSleeping:!
        - flag <player> ExpressiveSleepOriginalLocation:!
        # - fakeequip <player> head:air chest:air legs:air boots:air duration:0.1s for:<server.online_players>

        # Compatability - Uncomment any commented lines and remove this block to remove compatibility for external mods.
        - if !<player.has_flag[hidden_armor_toggle]>:
            - fakeequip <player> head:air chest:air legs:air boots:air duration:0.1s for:<server.online_players>

ExpressiveCrawlCommand:
    debug: true
    type: command
    name: crawl
    description: Crawl on your stomach.
    usage: /crawl
    script:
    - if !<player.has_flag[ExpressiveCrawl]>:
        - narrate "No Flag"
        - stop
    - if <player.has_flag[ExpressiveCrawl]>:
        - narrate "Flag Found"
        - stop

ExpressiveSitCommand:
    debug: true
    type: command
    name: sit
    description: Sit down somewhere.
    usage: /sit
    script:
    - if !<player.has_flag[ExpressiveSitting]>:
        - narrate "No Flag"
        - stop
    - if <player.has_flag[ExpressiveSitting]>:
        - narrate "Flag Found"
        - stop

# ExpressiveResetCommand:
#     debug: true
#     type: command
#     name: er
#     description: Reset.
#     usage: /er
#     script:
#     - if <player.has_flag[ExpressiveSleeping]>:
#         - remove <player.flag[SleepBodyDouble]>
#         - flag <player> SleepBodyDouble:!
#         - flag <player> ExpressiveSleeping:!
#         - flag <player> ExpressiveSleepOriginalLocation:!

#     - if <player.has_flag[ExpressiveSitting]>:
#         - flag <player> ExpressiveSitting:!
#     - if <player.has_flag[ExpressiveCrawling]>:
#         - flag <player> ExpressiveCrawling:!


ExpressiveWorld:
    type: world
    events:
        on player starts sneaking:
            - if <player.has_flag[ExpressiveTimerA]> && <player.location.pitch.is_less_than_or_equal_to[-89]>:
                - execute as_player "sleep"
                - flag <player> ExpressiveTimerA:!
                - stop
            - if <player.has_flag[ExpressiveTimerA]> && <player.location.pitch.is_more_than_or_equal_to[89]>:
                - execute as_player "crawl"
                - flag <player> ExpressiveTimerA:!
                - stop
            - flag <player> ExpressiveTimerA expire:8t
        on player breaks block flagged:ExpressiveSleeping:
            - determine cancelled
        on player starts sneaking flagged:ExpressiveSleeping:
            - execute as_player "sleep"
            - determine cancelled
        on player right clicks *_stairs:
            - execute as_player "sit"
            - determine cancelled

ExpressiveSleepTask:
    type: task
    script:
    - define BodyDouble <[1]>
    - define SafeYaw <[2]>
    - define StartYaw <[3].add[360].mod[360]>

    - while <player.has_flag[ExpressiveSleeping]>:
        - wait 2t

        - define difference <[StartYaw].sub[<player.location.yaw.add[360].mod[360]>]>
        - if <[difference]> > 180:
            - define difference <[difference].sub[360]>
        - if <[difference]> < -180:
            - define difference <[difference].add[360]>

        - if <[SafeYaw].sub[<[difference]>]> >= <[SafeYaw].sub[50]> && <[SafeYaw].sub[<[difference]>]> <= <[SafeYaw].add[50]> && <[BodyDouble].location.exists>:
            - teleport <[BodyDouble]> <[BodyDouble].location.with_pitch[<player.location.pitch.add[30]>].with_yaw[<[SafeYaw].sub[<[difference]>]>]>
        # - else: 
        #     - teleport <[BodyDouble]> <[BodyDouble].location.with_pitch[<player.location.pitch.add[0]>]>

ExpressiveCrawlTask:
    type: task
    script:
    - while <player.has_flag[ExpressiveCrawling]>:
        - ratelimit <player> 2t
        - if <player.location.add[0,1,0].find_blocks.within[0.01].contains[air]>:
            - narrate X

# NPC Tests:
# Yaw 0 = Body Facing East (Positive X)
# Yaw 90 = Body Facing North (Negative Z)
# Yaw 180 = Body Facing West (Negative X)
# Yaw -90 = Body Facing South (Positive Z)

# Yaw 0 = Body Facing East (Positive X)
# Yaw -90 = Body Facing South (Positive Z)
# Yaw -180 = Body Facing West (Negative X)

# Body Points to Yaw -45 if Player yaw is 135 ( Correct )
# Body Points to yaw -60 if player yaw is 150 ( Incorrect, Rotated Counter Clockwise by 15 degrees instead of Clockwise)