Date: 2016/03/24 08:00:47 UTC-07:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"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>