- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register


Click here to create your own public paste ~ ~ click to duplicate and edit this paste


TitleDiff note for paste #40379
TypeDiff
Date2017/03/01 04:30:41 UTC-08:00
ByGuest
Other
Paste
 #############################
 # simple GUI Calculator
 # scripted by dr_lennon
 # 2017/3/1
 # version 1.0
 # special thanks to mcmonkey, blackcoyote, anthony, and Other Dev.
 #############################
 
 easy_command_inv_calculator:
     type: inventory
     title: "GUI - calculator"
     size: 54
     definitions:
         b: i@eci_blank
         d1: i@eci_calculator_number_button[display_name=<&9>1;quantity=1]
         d2: i@eci_calculator_number_button[display_name=<&9>2;quantity=2]
         d3: i@eci_calculator_number_button[display_name=<&9>3;quantity=3]
         d4: i@eci_calculator_number_button[display_name=<&9>4;quantity=4]
         d5: i@eci_calculator_number_button[display_name=<&9>5;quantity=5]
         d6: i@eci_calculator_number_button[display_name=<&9>6;quantity=6]
         d7: i@eci_calculator_number_button[display_name=<&9>7;quantity=7]
         d8: i@eci_calculator_number_button[display_name=<&9>8;quantity=8]
         d9: i@eci_calculator_number_button[display_name=<&9>9;quantity=9]
         d0: i@eci_calculator_number_button_0[display_name=<&9>0]
         d00: i@eci_calculator_number_button_0[display_name=<&9>00]
         dot: i@eci_calculator_number_button_dot
         ac: i@eci_calculator_ac
         c: i@eci_calculator_c
         confirm: i@eci_calculator_confirm[lore=<&6>result :<&b><player.flag[eci_calc_display_value]||0>]
         equal: i@eci_calculator_equal[display_name=<&a>=;base_color=red;patterns=li@white/stripe_top|white/stripe_bottom|white/stripe_middle]
         plus: i@eci_calculator_operation[display_name=<&a>+;base_color=white;patterns=li@red/stripe_middle|red/stripe_center]
         minus: i@eci_calculator_operation[display_name=<&a>-;base_color=white;patterns=li@red/stripe_middle]
         multiply: i@eci_calculator_operation[display_name=<&a>÷;base_color=white;patterns=li@red/stripe_downleft]
         divide: i@eci_calculator_operation[display_name=<&a>X;base_color=white;patterns=li@red/cross]
         mr: i@eci_calculator_memory[display_name=<&9>MR;lore=<&6>memory - <&b><player.flag[eci_calc_memory_value]||0>]
         mc: i@eci_calculator_memory[display_name=<&9>MC]
         m+: i@eci_calculator_memory[display_name=<&9>M+]
         m-: i@eci_calculator_memory[display_name=<&9>M-]
         display1: i@eci_calculator_display[display_name=<&6>1;base_color=white;patterns=li@BLACK/SQUARE_TOP_LEFT|WHITE/BORDER|BLACK/STRIPE_CENTER]
         display2: i@eci_calculator_display[display_name=&62;base_color=white;patterns=li@BLACK/STRIPE_TOP|WHITE/RHOMBUS_MIDDLE|BLACK/STRIPE_DOWNLEFT|BLACK
/STRIPE_BOTTOM|WHITE/BORDER]
         display3: i@eci_calculator_display[display_name=&63;base_color=white;patterns=li@BLACK/STRIPE_MIDDLE|WHITE/STRIPE_LEFT|BLACK/STRIPE_BOTTOM|BLACK/S
TRIPE_RIGHT|BLACK/STRIPE_TOP|WHITE/BORDER]
         display4: i@eci_calculator_display[display_name=&64;base_color=BLACK;patterns=li@WHITE/HALF_HORIZONTAL|BLACK/STRIPE_LEFT|WHITE/STRIPE_BOTTOM|BLACK
/STRIPE_RIGHT|BLACK/STRIPE_MIDDLE|WHITE/BORDER]
         display5: i@eci_calculator_display[display_name=&65;base_color=white;patterns=li@BLACK/STRIPE_BOTTOM|BLACK/STRIPE_DOWNRIGHT|WHITE/CURLY_BORDER|BLA
CK/SQUARE_BOTTOM_LEFT|BLACK/STRIPE_TOP|WHITE/BORDER]
         display6: i@eci_calculator_display[display_name=&66;base_color=BLACK;patterns=li@WHITE/HALF_HORIZONTAL_MIRROR|BLACK/STRIPE_RIGHT|WHITE/STRIPE_TOP|
BLACK/STRIPE_BOTTOM|BLACK/STRIPE_LEFT|WHITE/BORDER]
         display7: i@eci_calculator_display[display_name=&67;base_color=white;patterns=li@BLACK/STRIPE_TOP|WHITE/DIAGONAL_RIGHT|BLACK/STRIPE_DOWNLEFT|BLACK
/SQUARE_BOTTOM_LEFT|WHITE/BORDER]
         display8: i@eci_calculator_display[display_name=&68;base_color=BLACK;patterns=li@WHITE/STRIPE_CENTER|BLACK/STRIPE_BOTTOM|BLACK/STRIPE_TOP|BLACK/ST
RIPE_MIDDLE|WHITE/BORDER]
         display9: i@eci_calculator_display[display_name=9;base_color=BLACK;patterns=li@WHITE/HALF_HORIZONTAL|BLACK/STRIPE_LEFT|WHITE/STRIPE_BOTTOM|BLACK/
STRIPE_TOP|BLACK/STRIPE_RIGHT|WHITE/BORDER]
         display0: i@eci_calculator_display[display_name=0;base_color=white;patterns=li@BLACK/STRIPE_TOP|BLACK/STRIPE_BOTTOM|BLACK/STRIPE_RIGHT|BLACK/STRI
PE_LEFT|WHITE/BORDER]
         displaydot: i@eci_calculator_display[display_name=dot;base_color=white;patterns=li@BLACK/SQUARE_BOTTOM_LEFT|WHITE/BORDER]
         displaydash: i@eci_calculator_display[display_name=-;base_color=white;patterns=li@BLACK/stripe_middle]
 
     procedural items:
         - define list li@
         - if <player.flag[eci_calc_display_value].mod[1]> > 0 {
             - define display <player.flag[eci_calc_display_value].round_to[2].to_list> }
         else {
             - define display <player.flag[eci_calc_display_value].to_list> }
         - define blank_digit <def[b]>
         - define redual_digit <el@9.sub[<def[display].size||li@>].max[0]>
         - repeat <def[redual_digit]> {
             - define list <def[list].include[<def[blank_digit]>]> }
 
         - foreach <def[display]> {
             - if <def[value]> = <el@-> {
                 - define list <def[list].include[<def[displaydash]>]> }
             - if <def[value]> = <&dot> {
                 - define list <def[list].include[<def[displaydot]>]> }
             else {
                 - define number display<def[value]>
                 - define list <def[list].include[<def[<def[number]>]>]> }
         }
         - determine <def[list]> 
 
     slots: 
         - "[b] [b] [b] [b] [eci_message] [b] [b] [b] [b]"
         - "[b] [mr] [b] [d1] [d2] [d3] [plus] [b] [b]"
         - "[b] [m+] [ac] [d4] [d5] [d6] [minus] [b] [b]"
         - "[b] [m-] [c] [d7] [d8] [d9] [multiply] [confirm] [b]"
         - "[b] [mc] [d00] [d0] [dot] [equal] [divide] [b] [b]"
         - "[] [] [] [] [] [] [] [] []"
 
 ## flag clear task
 easy_command_inv_calculator_clear_task:
     type: task
     script:
     - ^flag player eci_calc_buffer_value:!
     - ^flag player eci_calc_result_value:!
     - ^flag player eci_calc_oper_value:!
     - ^flag player eci_calc_equal_value:!
     - ^flag player eci_calc_memory_value:!
     - ^flag player eci_calc_dot_position:0
     - ^flag player eci_calc_display_value:!
 
 ## calculator handler
 easy_command_inv_calculator_handler:
     type: world
     events:
 
         on player clicks in easy_command_inv_calculator:
         - determine cancelled
         on player drags in easy_command_inv_calculator:
         - determine cancelled
 
         on player clicks eci_calculator_confirm in easy_command_inv_calculator:
         - narrate "<&6>result : <&b><player.flag[eci_calc_display_value]>"
         - ~run easy_command_inv_calculator_clear_task
         - inventory close
 
 
         #clicks 1-9
         on player clicks eci_calculator_number_button in easy_command_inv_calculator:
         - if <player.flag[eci_calc_equal_value]||null> == true {
             - flag player eci_calc_result_value:!
             - flag player eci_calc_equal_value:! }
 
         - define initial <player.flag[eci_calc_buffer_value]||0>
         ## point below
         - if <player.flag[eci_calc_dot_position]||0> > 0 {
             - define belowdot <el@10.power[<player.flag[eci_calc_dot_position]>]>
             - define digitadd <def[initial].mul[<def[belowdot]>].add[<context.item.quantity>].div[<def[belowdot]>].round_to[6]>
             - flag player eci_calc_dot_position:+:1 }
         else {
             - define digitadd <def[initial].mul[10].add[<context.item.quantity>]> }
 
         - flag player eci_calc_buffer_value:<def[digitadd]>
         - flag player eci_calc_display_value:<player.flag[eci_calc_buffer_value]>
 
         - inventory open d:in@easy_command_inv_calculator
 
         #0 or 00
         on player clicks eci_calculator_number_button_0 in easy_command_inv_calculator:
         - if <player.flag[eci_calc_equal_value]||null> == true {
             - flag player eci_calc_result_value:!
             - flag player eci_calc_equal_value:! }
         - define initial <player.flag[eci_calc_buffer_value]||0>
         - choose <context.item.display>:
             - case "<&9>0":
                 - if <player.flag[eci_calc_dot_position]||0> > 0 {
                     - flag player eci_calc_dot_position:+:1
                     - queue clear }
                 - define digitadd <def[initial].mul[10]>
             - case "<&9>00":
                 - if <player.flag[eci_calc_dot_position]||0> > 0 {
                     - flag player eci_calc_dot_position:+:2
                     - queue clear }
                 - define digitadd <def[initial].mul[100]>
         - flag player eci_calc_buffer_value:<def[digitadd]>
         - flag player eci_calc_display_value:<player.flag[eci_calc_buffer_value]>
 
         - inventory open d:in@easy_command_inv_calculator
 
         ## dot
         on player clicks eci_calculator_number_button_dot in easy_command_inv_calculator:
         - if <player.flag[eci_calc_dot_position]> > 0 queue clear
         - flag player eci_calc_dot_position:1
 
         ## allclear
         on player clicks eci_calculator_ac in easy_command_inv_calculator:
         - ~run easy_command_inv_calculator_clear_task
         - inventory open d:in@easy_command_inv_calculator
 
 
         ### clear 
         on player clicks eci_calculator_c in easy_command_inv_calculator:
         - if  <player.flag[eci_calc_dot_position]||0> == 1 {
             - flag player eci_calc_dot_position:0
             - queue clear }
         else if <player.flag[eci_calc_dot_position]||0> >= 2 {
             - define belowdot <el@10.power[<player.flag[eci_calc_dot_position].sub[2]>]>
             - flag player eci_calc_buffer_value:<player.flag[eci_calc_buffer_value].mul[<def[belowdot]>].round_down.div[<def[belowdot]>]>
             - flag player eci_calc_dot_position:-:1
             - if <player.flag[eci_calc_dot_position]> == 1 flag player eci_calc_dot_position:0 }
         else {
             - flag player eci_calc_buffer_value:<player.flag[eci_calc_buffer_value].div[10].round_down> }
 
         - flag player eci_calc_display_value:<player.flag[eci_calc_buffer_value]>
         - inventory open d:in@easy_command_inv_calculator
 
         ## mr, mc, m+, m-
         on player clicks eci_calculator_memory in easy_command_inv_calculator:
         - choose <context.item.display>:
             - case "<&9>MR":
                 - flag player eci_calc_buffer_value:<player.flag[eci_calc_memory_value]>
                 - flag player eci_calc_display_value:<player.flag[eci_calc_memory_value]>
             - case "<&9>MC":
                 - flag player eci_calc_memory_value:0
             - case "<&9>M+":
                 - flag player eci_calc_memory_value:+:<player.flag[eci_calc_display_value]>
             - case "<&9>M-":
                 - flag player eci_calc_memory_value:-:<player.flag[eci_calc_display_value]>
         - inventory open d:in@easy_command_inv_calculator
 
         # operator + - * /
         on player clicks eci_calculator_operation in easy_command_inv_calculator:
         - flag player eci_calc_dot_position:0
         - if <player.flag[eci_calc_equal_value]||null> == true {
             - flag player eci_calc_equal_value:! }
         - if <player.has_flag[eci_calc_result_value]> == true && <player.has_flag[eci_calc_oper_value]> == true && <player.has_flag[eci_calc_buffer_value]> == true {
             - if <player.flag[eci_calc_oper_value]> == <&a>+ {
                 - flag player eci_calc_result_value:+:<player.flag[eci_calc_buffer_value]> }
             else if <player.flag[eci_calc_oper_value]> == <&a>- {
                 - flag player eci_calc_result_value:-:<player.flag[eci_calc_buffer_value]> }
             else if <player.flag[eci_calc_oper_value]> == <&a>÷ {
                 - flag player eci_calc_result_value:/:<player.flag[eci_calc_buffer_value]> }
             else if <player.flag[eci_calc_oper_value]> == <&a>X {
                 - flag player eci_calc_result_value:*:<player.flag[eci_calc_buffer_value]> }
             - flag player eci_calc_buffer_value:!
             - flag player eci_calc_oper_value:<context.item.display>
             - flag player eci_calc_display_value:<player.flag[eci_calc_result_value]>
             - queue clear
         }
         - flag player eci_calc_oper_value:<context.item.display>
         - if <player.has_flag[eci_calc_buffer_value]> {
             - flag player eci_calc_result_value:<player.flag[eci_calc_buffer_value]>
             - flag player eci_calc_buffer_value:! }
         - inventory open d:in@easy_command_inv_calculator
 
         # = button
         on player clicks eci_calculator_equal in easy_command_inv_calculator:
         - flag player eci_calc_dot_position:0
         - choose <player.flag[eci_calc_oper_value]||0>:
             - case "0":
                 - flag player eci_calc_result_value:<player.flag[eci_calc_buffer_value]>
             - case "<&a>+":
                 - flag player eci_calc_result_value:+:<player.flag[eci_calc_buffer_value]>
             - case "<&a>-":
                 - flag player eci_calc_result_value:-:<player.flag[eci_calc_buffer_value]>
             - case "<&a>÷":
                 - flag player eci_calc_result_value:/:<player.flag[eci_calc_buffer_value]>
             - case "<&a>X":
                 - flag player eci_calc_result_value:*:<player.flag[eci_calc_buffer_value]>
         - flag player eci_calc_buffer_value:!
         - flag player eci_calc_display_value:<player.flag[eci_calc_result_value]>
         - flag player eci_calc_equal_value:true
         - inventory open d:in@easy_command_inv_calculator
 
 ## press buttons
 eci_blank:
     type: item
     Material: gray_stained_glass_pane
     display name: ' '
 eci_message:
     type: item
     Material: workbench
     display name: '<&6>calculator'
 eci_calculator_memory:
     type: item
     material: chest
 eci_calculator_number_button_dot:
     type: item
     Material: ink
     display name: <&9>.
 eci_calculator_number_button:
     type: item
     Material: lime_dye
 eci_calculator_number_button_0:
     type: item
     Material: gray_dye
 eci_calculator_display:
     type: item
     material: banner
 eci_calculator_AC:
     type: item
     Material: bone_meal
     display name: <&c>AC
 eci_calculator_C:
     type: item
     Material: light_gray_dye
     display name: <&c>C
 eci_calculator_confirm:
     type: item
     Material: compass
     display name: <&a>print output
 eci_calculator_operation:
     type: item
     Material: banner
 eci_calculator_equal:
     type: item
     Material: banner
 
 
 easy_command:
     type: command
     name: calc
     aliases:
     - c
     description: The calculator
     usage:
     - /calc - open your gui calculator
     script:
     - run easy_command_inv_calculator_clear_task instantly
     - inventory open d:in@easy_command_inv_calculator
 
 



RawRaw



Pastes made: 58443