Paste #9272: black

Date: 2014/09/04 06:45:37 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# NPC Blacksmith
# Citizens 2 (build #992)
# Denizen 0.9.3 (build #1352)
#
# @author Hyruii
#
# FOR EASY SETUP
# 1) Select the NPC and type /npc assign --set "blacksmith"

# Assignment script for blacksmith.
"blacksmith":
    type: assignment

    default constants:
        # Costs to repair one point of durability
        repairdurability: 10
        # Costs to repair each level of enchant
        repairenchant: 100

    interact scripts:
    # Priority starts from 10
    - 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:5

        on enter proximity:
        - chat "Hey <player.name>! Se hai qualcosa da riparare vieni qui e mostramelo."

        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.
                - if <<player.item_in_hand>.repairable> == true {
                    - chat "Mmm, fammelo vedere...."
                    - run CalcCost instantly
                    - wait 1s
                    - chat "Ti costerà <gold><flag.p:repaircost> <green> soldi per ripararlo."
                    - narrate "Scegli una della seguenti risposte digitando il numero corrispondente"
                    - narrate "1) Sì, riparamelo! (paga <flag.p:repaircost>)"
                    - narrate "2) No, grazie!"
                    - zap repair
                  }
                  else {
                      - chat "Non sono in grado di ripararlo."
                  }

        repair:
            chat trigger:
                'Yes':
                    trigger: '/1/ Sì, riparamelo!'
                    script:
                        # Once player agree to repair, check for sufficient money and increase durability (number of times used) to zero.
                        - if <player.money> OR_MORE <flag.p:repaircost> {
                            - playsound <player.location> sound:anvil_use
                            - take money qty:<flag.p:repaircost>
                            - define item <player.item_in_hand>
                            - take iteminhand
                            - adjust <player.item_in_hand> durability:0 save:newitem
                            - give <entry[newitem].result>
                            - chat "Ecco a te, torna di nuovo se hai bisogno di riparare!"
                            - narrate "Ora hai <gold><player.money.as_money> soldi."
                            - zap default
                          }
                          else {
                            - chat "Hey, non hai soldi sufficienti! Torna quando li avrai, barbone!"
                            - zap default
                          }

                'No':
                    trigger: '/2/ Non voglio ripararlo.'
                    script:
                        - chat "Torna da me quando dovrai ripararlo."
                        - 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>