Script Sample - Command Script and Procedure Script

Get help with Denizen2Sponge here.
Post Reply
Anthony
Regular
Regular
Posts: 35
Joined: August 5th, 2016, 9:01 pm

Script Sample - Command Script and Procedure Script

Post by Anthony » February 15th, 2017, 5:43 pm

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
Last edited by Anthony on February 15th, 2017, 8:41 pm, edited 2 times in total.
We are the music makers, and we are the dreamers of dreams...

User avatar
mcmonkey
Site Admin
Site Admin
Posts: 204
Joined: August 5th, 2016, 7:27 pm
Location: Los Angeles, California, USA
Contact:

Re: Script Sample - Command Script and Procedure Script

Post by mcmonkey » February 15th, 2017, 7:28 pm

Half of this is outdated by today's build :P
Denizen lead developer.
http://mcmonkey.org

Anthony
Regular
Regular
Posts: 35
Joined: August 5th, 2016, 9:01 pm

Re: Script Sample - Command Script and Procedure Script

Post by Anthony » February 15th, 2017, 8:32 pm

mcmonkey wrote:Half of this is outdated by today's build :P
updated
We are the music makers, and we are the dreamers of dreams...

User avatar
mcmonkey
Site Admin
Site Admin
Posts: 204
Joined: August 5th, 2016, 7:27 pm
Location: Los Angeles, California, USA
Contact:

Re: Script Sample - Command Script and Procedure Script

Post by mcmonkey » February 15th, 2017, 8:36 pm

Every single 'stop' under 'getFacing' is irrelevant in theory.

Or should be.
Denizen lead developer.
http://mcmonkey.org

Anthony
Regular
Regular
Posts: 35
Joined: August 5th, 2016, 9:01 pm

Re: Script Sample - Command Script and Procedure Script

Post by Anthony » February 15th, 2017, 8:42 pm

mcmonkey wrote:Every single 'stop' under 'getFacing' is irrelevant in theory.

Or should be.
updated
We are the music makers, and we are the dreamers of dreams...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest