ID:963585
 
(See the best response by Kaiochao.)
Hi guys,

In my game, i'm trying to give users an option to turn off system messages. I thought the best way to do that would be to set a var, e.g: systemmsg as 0 for off and 1 for on (on being default).

How can I make it so text only outputs to people who have that var on?

Something like-
systemmsg_players << "text"


instead of

world << "text"


Thanks
When you output to a list, the message is sent to all mobs in it. If you simply add listeners (mobs or clients) to the systemmsg_players list they will hear it while others not in the list will not.
Could you give me a small example code? Thanks
proc/SendMsg(msg as text)
var/list/listeners
for(var/mob/M in world)
if(M.systemmsg_players) listeners+=M
if(M in listeners) M<<"[msg]"
In response to Medz03
Best response
It's exactly how you had it.
DM Reference:
Format:
A << B
Cause the value B to be output to any players connected to mobs specified in A.

B may be an image, sound, or text. A may be a mob, the whole world, or any list containing mobs.
Every time you output to "range()" or "view()", you're obviously sending the message to a list containing mobs. When you output to "world", it's implicitly sending the message to world.contents (which is like checking "item in src").

And, of course, you can make your own lists.
var listeners[0]
proc/broadcast(message)
listeners << message

mob
verb/start_listening()
if(!(src in listeners))
src << "You start listening."
listeners += src
src << "You're already listening."

verb/stop_listening()
if(src in listeners)
src << "You stop listening."
listeners -= src
else src << "You're not listening."
In response to Shaoni
Only it'd be much easier to simply keep track of the list and only pick from that instead of referancing every mob in the world at the time to output a message.
var/list/Listening=new()
mob/verb/Listen()
if(!Listening.Find(src)) Listening.Add(src)
else Listening.Remove(src)
mob/verb/Say(t as text)
Listening<<t
Except you're not referencing every mob in the world when you do "Listening << t" just the mobs inside of the Listening list.

There's no need for the for() loop in your code :)
In response to Nadrew
Why thank you.