Paste #11880: Double Jumper

Date: 2014/12/06 18:37:21 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# ---------------------------------------------------------------------------- #
#                                                                              |
#                                                                              |
#                           D o u b l e   J u m p e r                          |
#                                                                              |
#                       Let your players do double jumps                       |
#                                                                              |
#                                                                              |
#   Author: |Anthony|                                                          |
#   Version: 0.1                                                               |
#   dScript Version: 0.9.6-b1545                                               |
#                                                                              |
# ---------------------------------------------------------------------------- #
#                                                                              |
#                                                                              |
# ABOUT:                                                                       |
#                                                                              |
#       Players will be able to do double jumps. You can set a flag to let     |
#     some folks actually fly.                                                 |
#     - flag <player> fly_enabled                                              |
#                                                                              |
#                                                                              |
# ---------------------------------------------------------------------------- #

DoubleJump:
  type: world
  debug: false
  speed: 0
  events:
    on player joins:
    - wait 1t
    - adjust <player> can_fly:true

    on player changes gamemode:
    - wait 1t
    - adjust <player> can_fly:true

    on player walks:
#    - narrate "player <player.location.y>"
#    - narrate "context old <c.old_location.y>"
#    - narrate "context new <c.new_location.y>"
    - if <c.new_location.y.is[LESS].than[<c.old_location.y>]||false> {
      - if <c.new_location.sub[0,0.1,0].material.is[!=].to[m@air]||false> {
        - queue clear
        }
      - if <player.has_flag[falling]||false> {
        - queue clear
        }
      - if <player.has_flag[jumping]||false> {
        - event "player jump|player stops jumping" context:state|stop|to_location|<c.old_location>|from_location|<player.flag[jumping]>
        - flag <player> jumping:!
        }
      - flag <player> falling:<c.old_location>
      - event "player fall|player starts falling" context:state|start|from_location|<c.old_location>
      - while <player.location.standing_on.material.is[==].to[m@air]||false> {
        - if <player.is_online.not> {
          - while stop
          }
        - wait 1t
        }
      - event "player fall|player stops falling" context:state|stop|to_location|<player.location>|from_location|<c.old_location>
      - narrate "Fall Distance <c.old_location.y.sub[<player.location.simple.as_location.y>]||0> blocks"
      - narrate "Fall Distance <c.old_location.y> - <player.location.y>"
      - wait 1t
      - flag <player> falling:!
      - queue clear
      }

    - if <c.new_location.y.is[MORE].than[<c.old_location.y>]||false> {
      - narrate "UP"
      - if <c.new_location.sub[0,0.1,0].material.is[!=].to[m@air]||false> {
        - queue clear
        }
      - if <player.has_flag[jumping]||false> {
        - queue clear
        }
      - flag <player> jumping:<c.old_location>
      - narrate "Jump Event"
      - event "player jump|player starts jumping" context:state|start|from_location|<c.old_location>
#      - define old_location '<player.location.y>'
#      - wait 1t
#      - while <player.location.y.is[MORE].than[<def[old_location]>]||false> {
#        - wait 1t
#        - define old_location <player.location.y>
#        }
##      - define old_location <player.location.y>
#      - narrate "JumpA <def[old_location].sub[<player.flag[jumping]>]||0> blocks"
#      - flag <player> jumping:!
      - queue clear
      }

#    - if <c.new_location.y.is[==].to[<c.old_location.y>]||false> {
#      - if <player.has_flag[falling].not||false> {
#        - queue clear
#        }
#      - narrate "FallB <player.flag[falling].sub[<c.old_location.y>]||0> blocks"
#      - flag <player> falling:!
#      - queue clear
#      }


    on player starts jumping:
      - narrate "Jumping from <c.from_location.y>"

    on player starts falling:
      - narrate "Falling from <c.from_location.y>"

    on player stops jumping:
      - narrate "Jump Height <c.to_location.y.sub[<c.from_location.y>]||0> Blocks"

    on player stops falling:
      - narrate "Fall Distance <c.from_location.y.sub[<c.to_location.y>]||0> Blocks"

    on player jumps:
    - if <player.has_flag[launched]||false> {
      - queue clear
      }
    - while <player.location.standing_on.material.name.is[==].to[air]||false> {
      - if <player.is_online.not> {
        - while stop
        }
      - wait 1t
      }
    - define fall '<c.location.y.sub[<player.location.y>]>'
    - adjust <player> can_fly:false
    - adjust <player> 'fall_distance:%fall%'
#    - narrate "fall distance %fall%"
    - adjust <player> can_fly:true

    on player starts flying:
    - if <player.has_flag[fly_enabled]||false>
      || <player.gamemode.id.is[==].to[1]> {
      - queue clear
      }
    - wait 5t
    - adjust <player> can_fly:false
    - define maxY '<player.location.y>'
    - while <player.location.standing_on.material.name.is[==].to[air]||false> {
      - if <player.is_online.not> {
        - while stop
        }
      - wait 1t
      }
    - adjust <player> fall_distance:<def[maxY].sub[<player.location.y>].mul[0.75]||0>
    - adjust <player> can_fly:true