Hide some messages received

38 views
Skip to first unread message

Zagor

unread,
Jan 15, 2021, 7:03:07 AM1/15/21
to Evennia
Hey all :-) 
I'm writing because I'm not able to figure out how to hidden some messages to players.

For example, let's assume the player is sleeping: player.db.sleeping = True

I don't want make him hear what's happening around, so I want hide some messages (for example if someone is saying things or picking up things etc.).

Meanwhile I want some messages to be displayed for example:  "You cannot do that, try to wake up yourself before!"

What's the best way to address this issue?
Thanks in advance for your help!

Zude Onim

unread,
Jan 15, 2021, 3:47:23 PM1/15/21
to eve...@googlegroups.com
Some ideas :

As part of your 'get' command, include :

for item in self.caller.location:
if item.db.is_character:
if item.db.is_awake:
item.msg("%s picks up the %s" % (self.caller, item_to_get))

You'd have to include that for all commands that send messages to the room.

On all the commands available to a sleeping character :

if self.caller.db.is_awake:
blah blah blah
else:
self.caller.msg("You cannot do that, try to wake up yourself before!")

Other people will have cooler streamlined super-python ways to do it,
but this would still work.
> --
> You received this message because you are subscribed to the Google Groups
> "Evennia" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to evennia+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/evennia/6caa2eff-2adc-4811-8f72-a9548bc37421n%40googlegroups.com.
>

Kovitikus

unread,
Jan 15, 2021, 4:57:25 PM1/15/21
to Evennia
I don't have an absolute fully realized solution for you, but consider using locks and at_msg_receive.

Zude's solution works as well. The difference is that his solution prevents a message from being sent and the logic is contained in the command.

My suggestion allows the message to be sent to the object, but then the object decides what to do with it and the logic lies on that object.

You could put the logic further up in your typeclass, in the base character typeclass, so that all character objects evaluate it. Just make sure you put a bit of logic at the start that exits the logic if there's no reason to execute it.
Message has been deleted

Griatch Art

unread,
Feb 11, 2021, 4:18:58 AM2/11/21
to Evennia
The evennia recommended way of doing this is to consider this a new 'state'. That is - you assign a new SleepCmdSet on the sleeping player with two commands - one is the 'wake' command that brings you out of the state and the other is a systemcommand (CMD_NOMATCH) that catches everything else and gives the "you can'd do that while sleeping" error. When they do wake up, just remove that cmdset and all your normal commands are back - no need for any flags or if statements in normal commands.

To mute input, it's easiest to override the `at_msg_receive` on the Character's typeclass as Kovitikus already mentioned. All you need in it is

    def at_msg_receive(self, msg, **kwargs):
        return self.db.is_awake

If this method returns False, the message never reaches the player, which is what you want.
.
Griatch
Reply all
Reply to author
Forward
0 new messages