Paste #31912: Edit of P#3092 - Blacksmith

Date: 2016/03/24 08:00:47 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


"blacksmith": 
    type: assignment 

    default constants: 
        repairdurability: 10 
        repairenchant: 1000 

    interact scripts: 
    - 10 SmithCheck 

    actions: 
        on assignment: 
        # Enable/disable triggers with NPC via chatting, clicking and entering proximity. 
        - trigger name:chat toggle:true 
        - trigger name:click toggle:true 
        - trigger name:proximity toggle:true radius:3 

        on enter proximity: 
        - random 3 
        - chat "You have something to repair? Let me see..." 
        - chat "That's a nice <player.item_in_hand>... I'll bet I could make it better." 
        - chat "Maybe I could request some rare materials from you in the future, eh?" 

        on exit proximity: 
        - zap 's@SmithCheck' step:default 

"SmithCheck": 
    type: interact 
    steps: 
        default: 
            click trigger: 
                script: 
                # Checks if item in player's hand is repairable. If so, run a task called CalcCost. 
                - chat "Hmmm, let's see..." 
                - wait 1s 
                - if <player.item_in_hand.repairable> == true { 
                    - run CalcCost instantly 
                    - if <flag.p:repaircost> > 0 { 
                        - chat "Yeah, I can fix that. It'll cost <gold><flag.p:repaircost> <white>coins to repair, though." 
                        - narrate "<gold>Yes <white>\/ <gold>No" 
                        - zap repair 
                      } 
                  } 
                  else { 
                      - chat "Sorry, but I can't repair that." 
                  } 

        repair: 
            chat trigger: 
                'Yes': 
                    trigger: '/Yes/, repair it.' 
                    script: 
                        # Once player agrees to repair, check for sufficient money and increase durability (number of times used) to zero. 
                        - if <player.money> OR_MORE <flag.p:repaircost> { 
                            - adjust <player.item_in_hand> durability:0 save:newitem 
                            - take iteminhand 
                            - playsound <player.location> sound:anvil_use 
                            - take money qty:<flag.p:repaircost> 
                            - give <entry[newitem].result> 
                            - chat "<dark_gray>Here you go! Come back if you need anymore repairs." 
                            - zap default 
                          } 
                          else { 
                            - chat "<dark_gray>Hey, you don't have enough money and I have mouths to feed! Come back when you can afford it..." 
                            - zap default 
                          } 

                'No': 
                    trigger: '/No/, I don''t want to repair it.' 
                    script: 
                        - chat "<dark_gray>Well... alright. Come back if you change your mind." 
                        - zap default 

"CalcCost": 
    type: task 
    script: 
        # Check for enchantments and the state of durability used. 
        - if <<player.item_in_hand>.enchantments> != null { 
            - flag player enchantlvl:0 
            - foreach <<player.item_in_hand>.enchantments.levels> { 
                - flag player enchantlvl:++:%value% 
              } 
          } 
          else { 
              - flag player enchantlvl:0 
          } 
        - flag player duralvl:<<player.item_in_hand>.durability> 

        # Calculates repair cost based on enchant level & durability. 
        - flag player enchantcost:<flag.p:enchantlvl> 
        - flag player enchantcost:**:<cons:repairenchant> 

        - flag player duracost:<flag.p:duralvl> 
        - flag player duracost:**:<cons:repairdurability> 

        - flag player repaircost:<flag.p:enchantcost> 
        - flag player repaircost:++:<flag.p:duracost>