Paste #4285: Dynamic Command Handler Example

Date: 2014/05/11 20:29:34 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


################################################################################
#
# Dynamic Command Handler Example
#
#
# An example of a command handler that accepts variable input. It doesn't
# matter what order the user puts in the arguments. It defaults the dryrun and
# verbose options to false.
#
# USAGE
#
# /cmdtest -a someValue -b anotherValue -c "Strings in quotes work too!" --dryrun --verbose
#
#
'DynamicCommandHandlerExample':
  type: world
  debug: false
  events:

    on cmdtest command:
    - if !<player.has_permission[denizen.cmdtest]> queue stop
    - define dryrun '<tern[<c.args.contains[--dryrun]>]:true || false>'
    - define verbose '<tern[<c.args.contains[--verbose]>]:true || false>'
    - if <c.args.find[-a].is[OR_MORE].than[0]> {
      - define a <c.args.get[<c.args.find[-a].add[1].as_int>]>
      - narrate "<&b>a<&co> <&a>%a%"
      }
    - if <c.args.find[-b].is[OR_MORE].than[0]> {
      - define b <c.args.get[<c.args.find[-b].add[1].as_int>]>
      - narrate "<&b>b<&co> <&a>%b%"
      }
    - if <c.args.find[-c].is[OR_MORE].than[0]> {
      - define c <c.args.get[<c.args.find[-c].add[1].as_int>]>
      - narrate "<&b>c<&co> <&a>%c%"
      }
    - narrate "<&b>dryrun<&co> <&a>%dryrun%"
    - narrate "<&b>verbose<&co> <&a>%verbose%"
    - determine FULFILLED
################################################################################