Paste #10589: Json Idea for Denizen

Date: 2014/10/19 19:38:21 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#A set of test chat utilities for having chat click-able links that interact with npcs

Red or Blue_:
    type: world
    events:
        on choice_selector_ command:
        - foreach <context.args> {
            - announce "Argument <def[loop_index]><&co> <def[value]>"
            }
        - determine fulfilled


Test Chat Links_:
    #
    # This is an example of using denizen to construct a chat link that executes a 
    # command that denizen then reads the arguments for...
    # Im thinking useful for...
    #   spells
    #   chat inputs
    #   world teleportations
    #   command lists
    #
    # custom built commands?
    # smite player selection
    #   arguments command target
    #   - foreach <server.list_online_players>
    type: task
    script:
    - execute as_server "tellraw <player.name> {text<&co>'hi there',color<&co>'blue'}"
    - execute as_server "tellraw <player.name> {text<&co>'Here your Text',color<&co>'Here your color',extra<&co>[{text<&co>'Here your Second Text',color<&co>'Here your Second Color',hoverEvent<&co>{action<&co>'show_text',value<&co>'Here your Hover Text'},clickEvent<&co>{action<&co>'run_command',value<&co>'/choice_selector_ red_pill swallow_it_quickly'}}]}"


#
#todo: introduce a new tag type, that parses code like it was used with a run command...
#It takes a list of denizen commands, parses them and from the determine gets the result of the tag, a mix of a procedure and a injection command
# syntax: "Hey player, your level<&co> <project:<script.yaml_keys[]>>"
New Tag Called Projection Usage:
    type: task
    determine_level:
    - if <def[player]> <proj:<script.yaml_keys[some_other_script_branch]>||>
    -
    - determine <noob>
    script:
    - narrate "Hey man your level<&co> <projection:<script.yaml_keys[determine_level]>>"

##################################################################################################################
# The main needs of a json format script, Each node here provides the options needed for minecrafts 
# tellraw, title, signs, books clickable links feature for 1.8.x
##################################################################################################################

json example format:
    #This type is optional as denizen tries to load every .yml file into memory
    #I think if 
    type: json
    definitions: json_text1|players_choice|players_quest
    script:
    #Json minecraft datatypes
    #value: "text"
    #list:
    #- item1
    #- item2
    #- item3
    #compound:
    #   sub-element: "sub-value"
    #   sub-compound:
    #       sub-sub-compound: value
    #
    #Default Minecraft Json Tags
    text:
    - text
    selector:
    - selector
    insertion:
    - text
    translate:
    - language
    color:
    - color
    bold:
    - bool
    italic:
    - bool
    underlined:
    - bool
    strikethrough:
    - bool
    obfuscated:
    - bool

    # according the the minecraft forum post listed above it appears that click event / with / extra mappings, 
    # they can recieve a [list] of objects...
    # im not sure how to have that handled other than give the option to return a list in the format of [<proj:%whatever_you_return%>]
    clickEvent:
        action:
        - [action]
        value:
        - "[value/url]"
    hoverEvent:
        action: action
        value: [value/json/nbt]
    score:
        name: p@player.name
        objective: [server_objective]

    #with and extra are lists... even list of lists
    #sub list notation in yaml.... not a familiar thing in denizen....
    #The empty list notation is needed for this otherwise yaml thinks that its an error and not a list of lists
    #too bad you guys didnt use this way to note a list of lists in denizen instead of using '|'
    #This will most likely conflict with the - determine command. Thats why the proposed tag is suggested for purposes <json:json_script>
    #I might be able to produce our own <proc:json_script> tag that uses existing procedures to construct a set of json compatible data.

    with:
    -
        - [more json info]
        - [2 more json info]
        - [3 more json info]
    extra:
    -
        -
        -

#########################################################
#Personal Examples
#########################################################
Player Choice Command:
    type: world
    events:
        on current_player_quest_selection command:
        - run "Start Quest Branch" def:<context.args.get[first]>


JSON Npc Subchoice Selector:
    type: json
    definitions: choice
    text:
    - determine <def[choice]>
    color:
    - determine gold
    clickEvent:
        action:
        - determine run_command
        value:
        - determine "current_player_quest_selection <def[choice]>"


JSON Npc Choice Selector:
    type: json
    definitions: json_text1|Choice_list|players_quest
    text:
    - determine <def[json_text1]||default_text>
    translate:
    - determine Pirate
    color:
    - determine red
    hoverEvent:
        action: 
        - determine show_text
        value: 
        - define text "<red>~[bheart]~ <gold>Please select your answer. <red>~[bheart]~"
        - determine <proc[iconize].context[<def[text]>]>
    extra:
    - define choice_list li@
    - foreach <def[choice_list].as_list> {
        - define extra_json "<json:JSON Npc Subchoice Selector>"
        - define choice_list <def[choice_list].extend[<def[extra_json]>]>
        }
    - determine <def[choice_list]>


Json Task Example:
    #
    # This is an example of using denizen to construct a chat link that executes a 
    # command that denizen then reads the arguments for...
    # Im thinking useful for...
    #   spells
    #   chat inputs
    #   world teleportations
    #   command lists
    #
    # custom built commands?
    # smite player selection
    #   arguments command target
    #   - foreach <server.list_online_players>
    type: task
    script:
    - define choice_text_1 "Your response to <npc.name>'s offer..."
    - define choice_list "li@Take the surrender|Fight to the end|Endure economic sanctions|Spend 20 years in prison"
    - execute as_server "title <player.name> <json:JSON Npc Choice Selector.context[]>"


################################################
# Now for examples from:
# http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/351959-1-8-raw-json-text-examples-for-tellraw-title-books
#
################################################

mcf raw json book example:
    type: json





Give Magic Spells Book:
    type: book
    title: Your spell book
    author: <player.name>
    text:
    - The spells you know<&co>
    - define first_line "Your spells are<&co>"
    - give 


tstbk:
    type: task
    script:
    - adjust <player.item_in_hand> book:you save:book
    - give <entry[book].result>