Script Sample - Command Script and Procedure Script

Anthony

Active member
Aug 5, 2016
35
0
6
Here's an example D2 script using a command script and a procedure script. This script displays the cardinal direction you are facing in the action bar for the duration specified in the command input.

Usage:
Code:
/showfacing (time in seconds)

Any feedback for improvements is welcome!

Code:
showFacing_command:
  type: command
  debug: minimal
  name: showfacing
  description: Tells you which way you are facing.
  script:
    - if <context.source> != 'player':
      - echo "This is a player command only!"
      - stop
    - define duration <context.arguments.get[1]||10>
    - if <[duration].is_number.not>:
      - define duration 10
    - define duration <def[duration].to_number.multiply[1000]>
    - flag <player> showFacing:<system.current_time_milliseconds.add_integer[<def[duration]>]>
    - while <player.flag[showFacing].is_greater_than[<system.current_time_milliseconds>]>:
      - actionbar <player> "<procedure[script:getFacing|yaw:<player.rotation.y>].facing>"
      - wait 0.1s
    - unflag <player> showFacing

getFacing:
# Usage: <procedure[script:getFacing|yaw:100].facing>
  type: procedure
  debug: false
  script:
    - define yaw <number[<context.yaw>]>
    # This bit fixes the ridiculous return values of entity.rotation
    - if <def[yaw]> < -180:
      - define yaw <def[yaw].add[360]>
    - else if <def[yaw]> > 180:
      - define yaw <def[yaw].subtract[360]>

    - if <def[yaw]> >= 157.5:
      - determine facing north
    - else if <def[yaw]> >= 112.5:
      - determine facing north_west
    - else if <def[yaw]> >= 67.5:
      - determine facing west
    - else if <def[yaw]> >= 22.5:
      - determine facing south_west
    - else if <def[yaw]> >= -22.5:
      - determine facing south
    - else if <def[yaw]> >= -67.5:
      - determine facing south_east
    - else if <def[yaw]> >= -112.5:
      - determine facing east
    - else if <def[yaw]> >= -157.5:
      - determine facing north_east
    - else:
      - determine facing north
 

Anthony

Active member
Aug 5, 2016
35
0
6
mcmonkey said:
Every single 'stop' under 'getFacing' is irrelevant in theory.

Or should be.
updated