diff --git a/code/datums/components/sound_player.dm b/code/datums/components/sound_player.dm new file mode 100644 index 00000000000..08d25b548b5 --- /dev/null +++ b/code/datums/components/sound_player.dm @@ -0,0 +1,39 @@ +/** + * Sound Player component + * + * Component that will play a sound upon recieving some signal + */ +/datum/component/sound_player + ///Volume of the sound when played + var/volume + ///The list of sounds played, picked randomly. + var/list/sounds + ///Uses left before the sound player deletes itself. If set to a negative number that will mean infinite uses. + var/uses + +/datum/component/sound_player/Initialize( + volume = 30, + sounds = list('sound/items/bikehorn.ogg'), + uses = -1, + signal_list = list(COMSIG_ATOM_ATTACK_HAND), +) + src.volume = volume + src.sounds = sounds + src.uses = uses + + RegisterSignal(parent, signal_list, .proc/play_sound) + +/** + * Attempt to play the sound on parent + * + * If out of uses, will qdel itself. + */ +/datum/component/sound_player/proc/play_sound() + SIGNAL_HANDLER + + playsound(parent, pick(sounds), volume, TRUE) + if(uses <= -1) + return + uses-- + if(!uses) + qdel(src) diff --git a/code/datums/components/soundplayer.dm b/code/datums/components/soundplayer.dm deleted file mode 100644 index d3e729d4749..00000000000 --- a/code/datums/components/soundplayer.dm +++ /dev/null @@ -1,42 +0,0 @@ -/*This is the sound_player component. It can be attached to any datum and register any signal to play the sound(s) you want, when you want. Used for the honk virus as an example - Usage : - target.AddComponent(/datum/component/sound_player, args) - Arguments : - custom_volume : Used to define a custom volume. Default : 30 - custom_sounds : Used to define a list of custom sounds that will be picked at random when play_sound() is triggered. Default : list('sound/items/bikehorn.ogg') - amount : Used to define an amount of time the component will work before deleting itself. Default : -1 - signal_or_sig_list : Used to register the signal(s) you want to play the sound when they are sent. Default : None -*/ -/datum/component/sound_player - var/volume = 30 - var/list/sounds = list('sound/items/bikehorn.ogg') - var/amount_left = -1 - -/datum/component/sound_player/Initialize(custom_volume, custom_sounds, amount, signal_or_sig_list) - if(!isnull(custom_volume)) - volume = custom_volume - - if(!isnull(custom_sounds)) - sounds = custom_sounds - - if(!isnull(amount)) - amount_left = amount - - RegisterSignal(parent, signal_or_sig_list, .proc/play_sound) //Registers all the signals in signal_or_sig_list. - - - -/*play_sound() os the proc that actually plays the sound. - If amount_left is equal to -1, the component is infinite and will never delete itself. -*/ -/datum/component/sound_player/proc/play_sound() - SIGNAL_HANDLER - playsound(parent, pick_weight(sounds), volume, TRUE) - switch(amount_left) - if(-1) - return - if(1) //Last use. - qdel(src) - return - else - amount_left -- diff --git a/code/game/objects/items/devices/PDA/PDA.dm b/code/game/objects/items/devices/PDA/PDA.dm index cdae86efbf0..e7cdad24d61 100644 --- a/code/game/objects/items/devices/PDA/PDA.dm +++ b/code/game/objects/items/devices/PDA/PDA.dm @@ -1083,8 +1083,8 @@ GLOBAL_LIST_EMPTY(PDAs) sig_list += list(COMSIG_AIRLOCK_OPEN, COMSIG_AIRLOCK_CLOSE) else sig_list += list(COMSIG_ATOM_ATTACK_HAND) - target.AddComponent(/datum/component/sound_player, amount = (rand(15,20)), signal_or_sig_list = sig_list) - installed_cartridge.charges -- + target.AddComponent(/datum/component/sound_player, uses = rand(15,20), signal_list = sig_list) + installed_cartridge.charges-- return TRUE diff --git a/tgstation.dme b/tgstation.dme index 1ef4420b337..cd923104232 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -792,7 +792,7 @@ #include "code\datums\components\sizzle.dm" #include "code\datums\components\slippery.dm" #include "code\datums\components\soulstoned.dm" -#include "code\datums\components\soundplayer.dm" +#include "code\datums\components\sound_player.dm" #include "code\datums\components\spawner.dm" #include "code\datums\components\spill.dm" #include "code\datums\components\spinny.dm"