Files
Bubberstation/code/datums/components/soundplayer.dm
SkyratBot 9228782297 [MIRROR] Added the ability to upload honk viruses to doors, machines and computers. Added new sound_player component. (#278)
* Added the ability to upload honk viruses to doors, machines and computers. Added new sound_player component. (#52593)

* Added the ability to upload honk viruses to airlocks.

* Removed shoes requirements. Added charge gain sound.

* Revert "Removed shoes requirements. Added charge gain sound."

This reverts commit 641fe91a1c936c2de0cdd8104304d7f25bc831a8.

* Added ping on charge gain.

* Refactored to use components and signals.

* Now works on all machines / computers.

* implements suggested changes

Co-authored-by: Rohesie <rohesie@gmail.com>

* Moved signals around.

* WIP

* Finally added sound_playing component.

* Rohesie provides good code

Co-authored-by: Rohesie <rohesie@gmail.com>

* More Rohesie goodies

Co-authored-by: Rohesie <rohesie@gmail.com>

* Everything is fucked oh god

* Clean sweep

* Update code/game/objects/items/devices/PDA/PDA.dm

Co-authored-by: Rohesie <rohesie@gmail.com>

* Update code/game/objects/items/devices/PDA/PDA.dm

Co-authored-by: Rohesie <rohesie@gmail.com>

Co-authored-by: Rohesie <rohesie@gmail.com>

* Added the ability to upload honk viruses to doors, machines and computers. Added new sound_player component.

Co-authored-by: KathyRyals <65850818+KathyRyals@users.noreply.github.com>
Co-authored-by: Rohesie <rohesie@gmail.com>
2020-08-11 00:39:56 +01:00

42 lines
1.5 KiB
Plaintext

/*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()
playsound(parent, pickweight(sounds), volume, TRUE)
switch(amount_left)
if(-1)
return
if(1) //Last use.
qdel(src)
return
else
amount_left --