Files
Bubberstation/code/datums/components/sound_player.dm
SkyratBot 7f5e526bb1 [MIRROR] Refactors and fixes sound_player [MDB IGNORE] (#11198)
* Refactors and fixes sound_player (#64443)

idk if this is considered a refactor since its not creating a new component, so remove my refactor label if you believe so.

Overhauls how sound_player works, and makes it actually work.

* Refactors and fixes sound_player

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
2022-01-31 23:24:59 -05:00

40 lines
897 B
Plaintext

/**
* 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)