Description: A small script to repair player's items with a small money cost.
For now, each point of durability costs 1 coin and each level of enchantment costs 100 coins. Adjust the number to customize the cost of repair.
Vault is required.
Thanks to mcmonkey4eva for the 'adjust' command. It is the core to the whole repair script.
# 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: 1# 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:
- random 3
- chat "<dark_gray>You have something to repair? Hold it and show it to me."
- chat "<dark_gray>It is cheaper to repair if your enchanted equipment is damaged more heavily."
- chat "<dark_gray>Maybe I could request some rare materials from you in 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.
- if <<player.item_in_hand>.repairable> == true {
- chat "<dark_gray>Hmmm, let me see that...."
- run CalcCost instantly
- wait 1s
- chat "<dark_gray>It will take <gold><flag.p:repaircost> <dark_gray>coins to repair that."
- narrate "Type <gold>Yes<white> or <gold>No<white>"
- zap repair
}
else {
- chat "<dark_gray>I cannot repair that."}
repair:
chat trigger:
'Yes':
trigger: '/Yes/, repair it.'
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>
- adjust <player.item_in_hand> durability:0 save:newitem
- take iteminhand
- give <entry[newitem].result>
- chat "<dark_gray>Here you go, come back if your equipment needs to be repaired again."
- narrate "You now have <gold><player.money> coins."
- zap default
}
else {
- chat "<dark_gray>Hey, you do not have enough money! Off you go, rascal!"
- zap default
}
'No':
trigger: '/No/, I do not want to repair it.'
script:
- chat "<dark_gray>Come back if you have more equipment to repair."
- 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>