ID:170147
 
I have a regular say verb that allows players to hear messages throughout the game. However, how would i code it so that if a mob is hit with a certain attack, such as "Sound Blast", the mob would become temporarily "deaf", and not be able to see the messages others say to the world for a short period of time? Also, how would i also add it so that after a short period of time, the mob begins to be able to see fragments of sentences others type, yet not the full thing?

--Reinhart
I would create a custom mob Hear() proc to catch "audio" messages sent to players. (I use Hear() in my own projects to make ignore lists easier to implement. You can also use NPCs' Hear() procs to parse conversations. DarkeNight even indicates distance and direction for all sounds. :) ) Your vocal commands will have to change to call Hear() for every mob in range.

This snippet may be more complex than you are looking for, but it models sound pretty realistically and minces messages that players can not hear at 100%. The perception comments in the communication verbs are for players with hear_mod = 1, the default value.
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")

To make players completely deaf, set hear_mod = 0. Partially deaf players have a hear mod between 0 and 1 (like hear_mod = 0.5). Your sound blast could initially set the victim's hear_mod to 0, then gradually restore it over time .