Page 1 of 1

Script Sample - Command Script and Procedure Script

Posted: February 15th, 2017, 5:43 pm
by Anthony
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: Select all

/showfacing (time in seconds)
Any feedback for improvements is welcome!

Code: Select all

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

Re: Script Sample - Command Script and Procedure Script

Posted: February 15th, 2017, 7:28 pm
by mcmonkey
Half of this is outdated by today's build :P

Re: Script Sample - Command Script and Procedure Script

Posted: February 15th, 2017, 8:32 pm
by Anthony
mcmonkey wrote:Half of this is outdated by today's build :P
updated

Re: Script Sample - Command Script and Procedure Script

Posted: February 15th, 2017, 8:36 pm
by mcmonkey
Every single 'stop' under 'getFacing' is irrelevant in theory.

Or should be.

Re: Script Sample - Command Script and Procedure Script

Posted: February 15th, 2017, 8:42 pm
by Anthony
mcmonkey wrote:Every single 'stop' under 'getFacing' is irrelevant in theory.

Or should be.
updated