1local instruments = {
2 [2070] = {effect = CONST_ME_SOUND_GREEN}, -- wooden flute
3 [2071] = {effect = CONST_ME_SOUND_GREEN}, -- lyre
4 [2072] = {effect = CONST_ME_SOUND_GREEN}, -- lute
5 [2073] = {effect = CONST_ME_SOUND_GREEN}, -- drum
6 [2074] = {effect = CONST_ME_SOUND_GREEN}, -- panpipes
7 [2075] = {effect = CONST_ME_SOUND_GREEN}, -- simple fanfare
8 [2076] = {effect = CONST_ME_SOUND_GREEN}, -- fanfare
9 [2077] = {effect = CONST_ME_SOUND_GREEN}, -- royal fanfare
10 [2078] = {effect = CONST_ME_SOUND_GREEN}, -- post horn
11 [2079] = {effect = CONST_ME_SOUND_GREEN}, -- war horn
12 [2080] = {effects = {failure = CONST_ME_SOUND_PURPLE, success = CONST_ME_SOUND_GREEN}, chance = 50}, -- piano
13 [2081] = {effects = {failure = CONST_ME_SOUND_PURPLE, success = CONST_ME_SOUND_GREEN}, chance = 50}, -- piano
14 [2082] = {effects = {failure = CONST_ME_SOUND_PURPLE, success = CONST_ME_SOUND_GREEN}, chance = 50}, -- piano
15 [2083] = {effects = {failure = CONST_ME_SOUND_PURPLE, success = CONST_ME_SOUND_GREEN}, chance = 50}, -- piano
16 [2084] = {effect = CONST_ME_SOUND_GREEN}, -- harp
17 [2085] = {effect = CONST_ME_SOUND_GREEN}, -- harp
18 [2332] = {effect = CONST_ME_SOUND_GREEN}, -- Waldo's post horn
19 [2367] = {effect = CONST_ME_SOUND_GREEN}, -- drum (immovable)
20 [2368] = {effect = CONST_ME_SOUND_GREEN}, -- simple fanfare (immovable)
21 [2369] = {effect = CONST_ME_SOUND_YELLOW, itemId = 2681, itemCount = 10, chance = 80, remove = true}, -- cornucopia (immovable)
22 [2370] = {effect = CONST_ME_SOUND_GREEN}, -- lute (immovable)
23 [2371] = {effect = CONST_ME_SOUND_BLUE}, -- the horn of sundering (actual effect is unknown; immovable)
24 [2372] = {effect = CONST_ME_SOUND_GREEN}, -- lyre (immovable)
25 [2373] = {effect = CONST_ME_SOUND_GREEN}, -- panpipes (immovable)
26 [3951] = {effect = CONST_ME_SOUND_BLUE}, -- bongo drum (actual effect is unknown)
27 [3952] = {effects = {failure = CONST_ME_POFF, success = CONST_ME_SOUND_GREEN}, chance = 20}, -- didgeridoo
28 [3953] = {effect = CONST_ME_SOUND_RED}, -- war drum
29 [3957] = {effect = CONST_ME_SOUND_YELLOW, itemId = 2681, itemCount = 10, chance = 80, remove = true}, -- cornucopia
30 [5786] = {effects = {failure = CONST_ME_SOUND_RED, success = CONST_ME_SOUND_YELLOW}, monster = "war wolf", chance = 60, remove = true}, -- wooden whistle
31 [6572] = {effect = CONST_ME_SOUND_GREEN, text = "TOOOOOOT", transformId = 13578, decayId = 6572}, -- party trumpet
32 [6573] = {effect = CONST_ME_SOUND_GREEN, text = "TOOOOOOT", transformId = 13578, decayId = 6573}, -- party trumpet
33 [13759] = {effect = CONST_ME_SOUND_BLUE}, -- small whistle (actual effect is unknown)
34 [23923] = {effect = CONST_ME_SOUND_WHITE} -- small crystal bell
35}
36
37function onUse(player, item, fromPosition, target, toPosition, isHotkey)
38 local instrument, chance = instruments[item:getId()]
39 if instrument.chance then
40 chance = instrument.chance >= math.random(1, 100)
41
42 if instrument.monster and chance then
43 local monster = Game.createMonster(instrument.monster, player:getPosition(), true)
44 if monster then
45 player:addSummon(monster)
46 end
47 elseif instrument.itemId and chance then
48 player:addItem(instrument.itemId, instrument.itemCount)
49 end
50 end
51
52 item:getPosition():sendMagicEffect(instrument.effect or instrument.effects and chance and instrument.effects.success or instrument.effects.failure)
53
54 if instrument.transformId then
55 player:say(instrument.text, TALKTYPE_MONSTER_SAY, false, nil, item:getPosition())
56 item:transform(instrument.transformId)
57 item:decay(instrument.decayId)
58 end
59
60 if not chance and instrument.remove then
61 item:remove()
62 end
63 player:addAchievementProgress("Rockstar", 10000)
64 return true
65end
66