Instruments

Share scripts you wrote for Denizen-Bukkit here!
Post Reply
princil
New
New
Posts: 2
Joined: June 19th, 2020, 6:32 am

Instruments

Post by princil » June 19th, 2020, 8:22 am

Haste Link: v1.1


Showcase of the script on a private server.

Allows players to play their favorite tunes using custom instruments.
Allows admins to easily add in new instruments for their players to use.

You can create a new instruments with the [nbt=sound/<sound>] NBT Tag.
To play a custom sound from a Resource Pack, add [custom/true] to the item's NBT value, so the finished NBT Tag looks like [nbt=sound/<sound>|custom/true].

Sheet Music System By BasedUser

Old Versions:
v1.0


Code:
Spoiler!

Code: Select all

# Instruments       #
# Soumeh, BasedUser #

# Items #
banjo:
  type: item
  material: clock[nbt=sound/block.note_block.banjo|custom/true|texture/banjo]
  debug: false
  display name: <reset>Birch Banjo
  recipes:
    1:
      type: shaped
      input:
      - air|string|birch_planks
      - birch_planks|birch_planks|string
      - birch_planks|birch_planks|string
basedrum:
  type: item
  material: clock[nbt=sound/block_note_block_basedrum|texture/basedrum]
  debug: false
  display name: <reset>War Drum
  recipes:
    1:
      type: shaped
      input:
      - leather|leather|leather
      - leather|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|leather
      - oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks
bass:
  type: item
  material: clock[nbt=sound/block_note_block_bass|texture/bass]
  debug: false
  display name: <reset>Oak Bass
  recipes:
    1:
      type: shaped
      input:
      - air|string|oak_planks
      - oak_planks|oak_planks|string
      - oak_planks|oak_planks|string
bell:
  type: item
  material: clock[nbt=sound/block_note_block_bell|texture/bell]
  debug: false
  display name: <reset>Golden Bell
  recipes:
    1:
      type: shaped
      input:
      - air|gold_nugget|air
      - gold_ingot|gold_ingot|gold_ingot
      - gold_ingot|gold_nugget|gold_ingot
bit:
  type: item
  material: clock[nbt=sound/block.note_block.bit|custom/true|texture/bit]
  debug: false
  display name: <reset>Redstone Bitbox
  recipes:
    1:
      type: shaped
      input:
      - air|note_block|air
      - note_block|diamond_shard|note_block
      - air|note_block|air
chime:
  type: item
  material: clock[nbt=sound/block_note_block_chime|texture/chime]
  debug: false
  display name: <reset>Diorite Chime
  recipes:
    1:
      type: shaped
      input:
      - polished_diorite|polished_diorite|polished_diorite
      - polished_diorite|iron_ingot|polished_diorite
      - polished_diorite|iron_ingot|polished_diorite
cow_bell:
  type: item
  material: clock[nbt=sound/block.note_block.cow_bell|custom/true|texture/cow_bell]
  debug: false
  display name: <reset>Cow Bell
  recipes:
    1:
      type: shaped
      input:
      - air|iron_ingot|air
      - iron_ingot|stick|iron_ingot
      - iron_ingot|air|iron_ingot
didgeridoo:
  type: item
  material: clock[nbt=sound/block.note_block.didgeridoo|custom/true|texture/didgeridoo]
  debug: false
  display name: <reset>Acacia Didgeridoo
  recipes:
    1:
      type: shaped
      input:
      - air|air|acacia_planks
      - air|acacia_planks|acacia_planks
      - acacia_planks|acacia_planks|air
flute:
  type: item
  material: clock[nbt=sound/block_note_block_flute|texture/flute]
  debug: false
  display name: <reset>Dark Oak Flute
  recipes:
    1:
      type: shaped
      input:
      - air|air|dark_oak_planks
      - air|dark_oak_planks|air
      - birch_planks|air|air
guitar:
  type: item
  material: clock[nbt=sound/block_note_block_guitar|texture/guitar]
  debug: false
  display name: <reset>Jungle Guitar
  recipes:
    1:
      type: shaped
      input:
      - air|string|jungle_planks
      - jungle_planks|jungle_planks|string
      - jungle_planks|jungle_planks|string
harp:
  type: item
  material: clock[nbt=sound/block_note_block_harp|texture/harp]
  debug: false
  display name: <reset>Basalt Harp
  recipes:
    1:
      type: shaped
      input:
      - polished_granite|polished_granite|polished_granite
      - polished_granite|string|polished_granite
      - polished_granite|polished_granite|polished_granite
hat:
  type: item
  material: clock[nbt=sound/block_note_block_hat|texture/hat]
  debug: false
  display name: <reset>Sticks
  recipes:
    1:
      type: shapeless
      input: stick|stick
iron_xylophone:
  type: item
  material: clock[nbt=sound/block.note_block.iron_xylophone|custom/true|texture/iron_xylophone]
  debug: false
  display name: <reset>Iron Xylophone
  recipes:
    1:
      type: shaped
      input:
      - polished_granite|air|iron_ingot
      - iron_ingot|iron_ingot|air
      - air|iron_ingot|polished_granite
pling:
  type: item
  material: clock[nbt=sound/block_note_block_pling|texture/pling]
  debug: false
  display name: <reset>Obsidian Pling
  recipes:
    1:
      type: shaped
      input:
      - obsidian|obsidian|obsidian
      - obsidian|harp|obsidian
      - obsidian|obsidian|obsidian
xylophone:
  type: item
  material: clock[nbt=sound/block_note_block_xylophone|texture/xylophone]
  debug: false
  display name: <reset>Bone Xylophone
  recipes:
    1:
      type: shaped
      input:
      - polished_stone|air|bone
      - bone|bone|air
      - air|bone|polished_stone
slap_bass:
  type: item
  material: clock[nbt=sound/block.note_block.slap_bass|custom/true|texture/slap_bass]
  debug: false
  display name: <reset>Birch Bass
  recipes:
    1:
      type: shaped
      input:
      - air|string|birch_planks
      - birch_planks|birch_log|string
      - birch_planks|birch_planks|string
snare:
  type: item
  material: clock[nbt=sound/block_note_block_snare|texture/snare]
  debug: false
  display name: <reset>Short Drums
  recipes:
    1:
      type: shaped
      input:
      - leather|leather
      - oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks|oak_planks/birch_planks/spruce_planks/jungle_planks/acacia_planks/dark_oak_planks
cymbal_hi-hat:
  type: item
  material: clock[nbt=sound/block.note_block.cymbal_hi-hat|custom/true|texture/cymbal_hi-hat]
  debug: false
  display name: <reset>Iron Plate
  recipes:
    1:
      type: shaped
      input:
      - air|iron_ingot|air
      - iron_ingot|air|iron_ingot
      - air|iron_ingot|air
cymbal_splash:
  type: item
  material: clock[nbt=sound/block.note_block.cymbal_splash|custom/true|texture/cymbal_splash]
  debug: false
  display name: <reset>Golden Plate
  recipes:
    1:
      type: shaped
      input:
      - air|gold_ingot|air
      - gold_ingot|air|gold_ingot
      - air|gold_ingot|air
# Handlers #
note_block_handler:
  type: world
  debug: false
  events:
    on noteblock plays note:
    - choose <context.location.below.material.name>:
      - case hay_bale:
        - determine passively cancelled
        - define sound:block.note_block.banjo
        - define custom:true
        - goto play
      - case emerald_block:
        - determine passively cancelled
        - define sound:block.note_block.bit
        - define custom:true
        - goto play
      - case iron_block:
        - determine passively cancelled
        - define sound:block.note_block.iron_xylophone
        - define custom:true
        - goto play
      - case soul_sand:
        - determine passively cancelled
        - define sound:block.note_block.cow_bell
        - define custom:true
        - goto play
      - case pumpkin carved_pumpkin:
        - determine passively cancelled
        - define sound:block.note_block.didgeridoo
        - define custom:true
        - goto play
      - case oak_log birch_log spruce_log jungle_log acacia_log dark_oak_log:
        - determine passively cancelled
        - define sound:block.note_block.slap_bass
        - define custom:true
        - goto play
      - default:
        - stop
    - mark play
    - if <[custom]> == [custom]:
      - playsound <context.location> sound:<[sound]> pitch:<context.pitch> volume:3 sound_category:records
    - else:
      - playsound <context.location> sound:<[sound]> pitch:<context.pitch> volume:3 custom sound_category:records
    - playeffect effect:NOTE at:<context.location.add[0.5,1.1,0.5]> offset:<context.pitch>,0,0 quantity:0 data:1
instrument_handler:
  type: world
  debug: false
  events:
    after player right clicks entity with item:
	- flag player pitches_r d:2t
    - inject instrument_task
    after player left clicks with item:
	- flag player pitches_l d:2t
    - inject instrument_task
    after player right clicks with item:
	- flag player pitches_r d:2t
    - inject instrument_task
	after player damages entity:
	- flag player pitches_l d:2t
	- inject instrument_task
instrument_task:
  type: task
  debug: false
  script:
    - if !<player.item_in_hand.has_nbt[sound]>:
	  - stop
    - if !<player.open_inventory.as_element.contains_text[player]>:
      - stop
	- if <player.has_flag[instrument_cooldown]>:
	  - stop
	- flag player instrument_cooldown d:1t
	- if <player.has_flag[pitches_l]>:
	  - define pitch:<element[1.05946].power[<player.location.pitch.sub[90].mul[-1].mul[<element[12].div[180]>].round>].div[2]>
	- else if <player.has_flag[pitches_r]>:
	  - define pitch:<element[1.05946].power[<player.location.pitch.sub[90].mul[-1].mul[<element[12].div[180]>].round.add[12]>].div[2]>
    - determine passively cancelled
    - if <player.item_in_hand.has_nbt[custom]>:
      - playsound <player.location> sound:<player.item_in_hand.nbt[sound]> pitch:<[pitch]> custom sound_category:records
    - else:
      - playsound <player.location> sound:<player.item_in_hand.nbt[sound]> pitch:<[pitch]> sound_category:records
    - playeffect effect:NOTE at:<player.location.add[0,2,0].add[<util.random.decimal[-0.5].to[0.5]>,<util.random.decimal[0].to[0.5]>,<util.random.decimal[-0.5].to[0.5]>]> offset:<[pitch]>,0,0 quantity:0 data:1
sheet_music_handler:
  type: world
  debug: false
  events:
    after player left clicks with stick:
    - if !<player.has_flag[playingSheetMusic]> && <player.item_in_offhand.is_book>:
      - flag player playingSheetMusic:<queue>
      - flag player playedSheetMusic:<player.item_in_offhand.book_pages.unseparated.strip_color.split[;]>
      - foreach <player.flag[playedSheetMusic].get[1]> as:note:
        - if <player.item_in_offhand.is_book>:
          - if <[note].split[,].size> == 4:
            - define pause <[note].split[,].get[1]>
            - define pitch <[note].split[,].get[2]>
            - define sound <[note].split[,].get[3]>
            - define volume <[note].split[,].get[4]>
            - if <player.inventory.slot[<[sound]>].has_nbt[custom]>:
              - playsound <player.location> sound:<player.inventory.slot[<[sound]>].nbt[sound]> custom volume:<[volume]> pitch:<element[1.05946].power[<[pitch]>].div[2]> sound_category:records
            - else:
              - playsound <player.location> sound:<player.inventory.slot[<[sound]>].nbt[sound]> volume:<[volume]> pitch:<element[1.05946].power[<[pitch]>].div[2]> sound_category:records
            - playeffect effect:NOTE at:<player.location.add[0,2,0].add[<util.random.decimal[-0.5].to[0.5]>,<util.random.decimal[0].to[0.5]>,<util.random.decimal[-0.5].to[0.5]>]> offset:<element[1.05946].power[<[pitch]>].div[2]> quantity:0 data:1
            - wait <[pause]>t
        - else:
          - flag player playingSheetMusic:!
          - flag player playedSheetMusic:!
          - determine cancelled
    - else:
      - queue <player.flag[playingSheetMusic]> clear
    - flag player playingSheetMusic:!
    - flag player playedSheetMusic:!
# By - BasedUser
sheet_music_handler:
  type: world
  debug: false
  events:
    after player left clicks with stick:
    - if !<player.has_flag[playingSheetMusic]> && <player.item_in_offhand.is_book>:
      - flag player playingSheetMusic:<queue>
      - flag player playedSheetMusic:<player.item_in_offhand.book_pages.unseparated.strip_color.split[;]>
      - foreach <player.flag[playedSheetMusic].get[1]> as:note:
        - if <player.item_in_offhand.is_book>:
          - if <[note].split[,].size> == 4:
            - define pause <[note].split[,].get[1]>
            - define pitch <[note].split[,].get[2]>
            - define sound <[note].split[,].get[3]>
            - define volume <[note].split[,].get[4]>
            - if <player.inventory.slot[<[sound]>].has_nbt[custom]>:
              - playsound <player.location> sound:<player.inventory.slot[<[sound]>].nbt[sound]> custom volume:<[volume]> pitch:<element[1.05946].power[<[pitch]>].div[2]> sound_category:records
            - else:
              - playsound <player.location> sound:<player.inventory.slot[<[sound]>].nbt[sound]> volume:<[volume]> pitch:<element[1.05946].power[<[pitch]>].div[2]> sound_category:records
            - playeffect effect:NOTE at:<player.location.add[0,2,0].add[<util.random.decimal[-0.5].to[0.5]>,<util.random.decimal[0].to[0.5]>,<util.random.decimal[-0.5].to[0.5]>]> offset:<element[1.05946].power[<[pitch]>].div[2]> quantity:0 data:1
            - wait <[pause]>t
        - else:
          - flag player playingSheetMusic:!
          - flag player playedSheetMusic:!
          - determine cancelled
    - else:
      - queue <player.flag[playingSheetMusic]> clear
    - flag player playingSheetMusic:!
    - flag player playedSheetMusic:!
Last edited by princil on July 12th, 2020, 1:19 pm, edited 3 times in total.

User avatar
mcmonkey
Site Admin
Site Admin
Posts: 295
Joined: August 5th, 2016, 7:27 pm
Location: Los Angeles, California, USA
Contact:

Re: Instruments

Post by mcmonkey » June 19th, 2020, 3:29 pm

- material: gold_ingot[nbt=sound/block_note_block_bell] Don't do that. Use the mechanisms: key.
- Be aware that "yaml data" is deprecated in current dev builds, and is just "data" now. Similarly "yaml_key" is now "data_key".
- - if !<player.open_inventory.as_element.contains_text[player]>: that's an awful hack, why... why?! I'm pretty sure you're intending to check the inventory_type?
- - define pitch:< put a space not a colon.
- with item this is redundant and does nothing. Might as well add - if true at that rate.
- Why are you using playeffect with a random location and a zero offset? Instead of, y'know... setting the offset to 0.5?
Denizen lead developer. On Discord as mcmonkey#6666.

princil
New
New
Posts: 2
Joined: June 19th, 2020, 6:32 am

Re: Instruments

Post by princil » June 19th, 2020, 4:12 pm

I will update the script tomorrow to fix all of these mistakes, i joined the discord server to discuss the last one about using playeffect, but this happened.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest