ID:195085
 
// Title: Player Deafening
// Credit To: Shadowdarke
// (http://developer.byond.com/forum/index.cgi?action=message_read&id=336595&forum=8&view=1)
// Contributed by: Audeuro

/* This is a cool little snippet that you can use to deafen
or mute players. A demo is included (also written by
Shadowdarke) to show how to use it.
*/


mob
var
hear_mod = 1 /* multiplier for sound volume.
0 makes the player completely deaf
0 < value < 1 => partially deaf
value > 1 => enhanced hearing */


proc
Hear(mob/who, message, volume = 10000, extra)
message = html_encode(message)
// add any additional handling for message length and spam

if(!who || !message) return // no one talking or nothing to say

// volume diminishes by the square of the distance

var/d = get_dist(src, who) // or custom distance proc
if(d) volume /= d*d

volume *= hear_mod

if(volume < 1) return // can't hear anything
if(volume < 100) // mince the message
var/new_message = ""
var/heard_some = 0
for(var/loop = 1 to length(message))
if(prob(volume))
new_message += copytext(message,loop, loop+1)
heard_some = 1
else
new_message += " " // a single space
if(!heard_some) // entire message was obscured
return
message = new_message
else if(volume > 10000)
// indicate that it sounds loud with <B> tags
message = "<b>[message]</b>"

src << "<b>[who.name][extra]:</b> [message]"

verb
say(T as text)
/* 100% perception volume at range = 10
50% at range = 14, 1% at 100*/


for(var/mob/M in hearers(usr, world.view*2))
M.Hear(src, T)

shout(T as text)
/* 100% perception at range = 31,
50% at 44, 25% at 63, 1% at 316
bold text up to range = 10 */


for(var/mob/M in world)
M.Hear(src, T, 100000, " shouts")

whisper(T as text)
// 100% at range 1, 25% at range 2... 1% at range 10
for(var/mob/M in hearers())
M.Hear(src, T, 100, " whispers")