<li><p><aclass="reference external"href="Howto/Coding-FAQ.html#adding-color-to-default-evennia-channels">Adding color to default Evennia Channels</a></p></li>
<li><p><aclass="reference external"href="Howto/Coding-FAQ.html#selectively-turn-off-commands-in-a-room">Selectively turn off commands in a room</a></p></li>
<li><p><aclass="reference external"href="Howto/Coding-FAQ.html#select-command-based-on-a-condition">Select Command based on a condition</a></p></li>
<li><p>[Automatically updating code when reloading](./Coding-FAQ#automatically-updating-code-when-
<p><strong>Q:</strong> How does one <em>remove</em> (not replace) e.g. the default <codeclass="docutils literal notranslate"><spanclass="pre">get</span></code><aclass="reference internal"href="../Components/Commands.html"><spanclass="doc">Command</span></a> from the
Character <aclass="reference internal"href="../Components/Command-Sets.html"><spanclass="doc">Command Set</span></a>?</p>
<p><strong>A:</strong> Go to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/commands/default_cmdsets.py</span></code>. Find the <codeclass="docutils literal notranslate"><spanclass="pre">CharacterCmdSet</span></code> class. It has one
method named <codeclass="docutils literal notranslate"><spanclass="pre">at_cmdset_creation</span></code>. At the end of that method, add the following line:
<codeclass="docutils literal notranslate"><spanclass="pre">self.remove(default_cmds.CmdGet())</span></code>. See the <aclass="reference internal"href="Starting/Part1/Adding-Commands.html"><spanclass="doc">Adding Commands Tutorial</span></a>
<h2>Preventing character from moving based on a condition<aclass="headerlink"href="#preventing-character-from-moving-based-on-a-condition"title="Permalink to this headline">¶</a></h2>
<p><strong>Q:</strong> How does one keep a character from using any exit, if they meet a certain condition? (I.E. in
combat, immobilized, etc.)</p>
<p><strong>A:</strong> The <codeclass="docutils literal notranslate"><spanclass="pre">at_before_move</span></code> hook is called by Evennia just before performing any move. If it returns
<codeclass="docutils literal notranslate"><spanclass="pre">False</span></code>, the move is aborted. Let’s say we want to check for an <aclass="reference internal"href="../Components/Attributes.html"><spanclass="doc">Attribute</span></a><codeclass="docutils literal notranslate"><spanclass="pre">cantmove</span></code>.
<spanclass="s2">"Called just before trying to move"</span>
<spanclass="k">if</span><spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">db</span><spanclass="o">.</span><spanclass="n">cantmove</span><spanclass="p">:</span><spanclass="c1"># replace with condition you want to test</span>
<spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="s2">"Something is preventing you from moving!"</span><spanclass="p">)</span>
<h2>Reference initiating object in an EvMenu command.<aclass="headerlink"href="#reference-initiating-object-in-an-evmenu-command"title="Permalink to this headline">¶</a></h2>
<p><strong>A:</strong> When an <aclass="reference internal"href="../Components/EvMenu.html"><spanclass="doc">EvMenu</span></a> is started, the menu object is stored as <codeclass="docutils literal notranslate"><spanclass="pre">caller.ndb._menutree</span></code>.
<p>Inside the menu you can now access the object through <codeclass="docutils literal notranslate"><spanclass="pre">caller.ndb._menutree.stored_obj</span></code>.</p>
<h2>Adding color to default Evennia Channels<aclass="headerlink"href="#adding-color-to-default-evennia-channels"title="Permalink to this headline">¶</a></h2>
<p><strong>Q:</strong> How do I add colors to the names of Evennia channels?</p>
<p><strong>A:</strong> The Channel typeclass’<codeclass="docutils literal notranslate"><spanclass="pre">channel_prefix</span></code> method decides what is shown at the beginning of a
<p>Additional hint: To make colors easier to change from one place you could instead put the
<codeclass="docutils literal notranslate"><spanclass="pre">CHANNEL_COLORS</span></code> dict in your settings file and import it as <codeclass="docutils literal notranslate"><spanclass="pre">from</span><spanclass="pre">django.conf.settings</span><spanclass="pre">import</span><spanclass="pre">CHANNEL_COLORS</span></code>.</p>
<h2>Selectively turn off commands in a room<aclass="headerlink"href="#selectively-turn-off-commands-in-a-room"title="Permalink to this headline">¶</a></h2>
<p><strong>A:</strong> This is done using a custom cmdset on a room <aclass="reference internal"href="../Components/Locks.html"><spanclass="doc">locked with the ‘call’ lock type</span></a>. Only
<spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">caller</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="s2">"You cannot do that in this room."</span><spanclass="p">)</span>
<p>After <codeclass="docutils literal notranslate"><spanclass="pre">@reload</span></code>, make some <codeclass="docutils literal notranslate"><spanclass="pre">BlockingRooms</span></code> (or switch a room to it with <codeclass="docutils literal notranslate"><spanclass="pre">@typeclass</span></code>). Entering one
will now replace the given commands for anyone that does not have the <codeclass="docutils literal notranslate"><spanclass="pre">Builders</span></code> or higher
permission. Note that the ‘call’ lock is special in that even the superuser will be affected by it
(otherwise superusers would always see other player’s cmdsets and a game would be unplayable for
but to <aclass="reference internal"href="../Components/Locks.html"><spanclass="doc">lock</span></a> it with the “cmd” type lock. Only if the “cmd” lock type is passed will the
<p>Add this to the <aclass="reference internal"href="Starting/Part1/Adding-Commands.html"><spanclass="doc">default cmdset as usual</span></a>. The <codeclass="docutils literal notranslate"><spanclass="pre">is_full_moon</span></code><aclass="reference external"href="Howto/Locks#lock-functions">lock
<p>After a <codeclass="docutils literal notranslate"><spanclass="pre">@reload</span></code>, the <codeclass="docutils literal notranslate"><spanclass="pre">werewolf</span></code> command will be available only at the right time, that is when the
<codeclass="docutils literal notranslate"><spanclass="pre">is_full_moon</span></code> lock function returns True.</p>
<h2>Automatically updating code when reloading<aclass="headerlink"href="#automatically-updating-code-when-reloading"title="Permalink to this headline">¶</a></h2>
<p><strong>Q:</strong> I have a development server running Evennia. Can I have the server update its code-base when
I reload?</p>
<p><strong>A:</strong> Having a development server that pulls updated code whenever you reload it can be really
useful if you have limited shell access to your server, or want to have it done automatically. If
you have your project in a configured Git environment, it’s a matter of automatically calling <codeclass="docutils literal notranslate"><spanclass="pre">git</span><spanclass="pre">pull</span></code> when you reload. And that’s pretty straightforward:</p>
<p>That’s all. We call <codeclass="docutils literal notranslate"><spanclass="pre">subprocess</span></code> to execute a shell command (that code works on Windows and Linux,
assuming the current directory is your game directory, which is probably the case when you run
Evennia). <codeclass="docutils literal notranslate"><spanclass="pre">call</span></code> waits for the process to complete, because otherwise, Evennia would reload on
partially-modified code, which would be problematic.</p>
<p>Now, when you enter <codeclass="docutils literal notranslate"><spanclass="pre">@reload</span></code> on your development server, the game repository is updated from the
configured remote repository (Github, for instance). Your development cycle could resemble
<li><p>When the time comes, login to the development server and run <codeclass="docutils literal notranslate"><spanclass="pre">@reload</span></code>.</p></li>
<p><strong>Q:</strong> How can I change the default exit messages to something like “XXX leaves east” or “XXX
arrives from the west”?</p>
<p><strong>A:</strong> the default exit messages are stored in two hooks, namely <codeclass="docutils literal notranslate"><spanclass="pre">announce_move_from</span></code> and
<codeclass="docutils literal notranslate"><spanclass="pre">announce_move_to</span></code>, on the <codeclass="docutils literal notranslate"><spanclass="pre">Character</span></code> typeclass (if what you want to change is the message other
characters will see when a character exits).</p>
<p>These two hooks provide some useful features to easily update the message to be displayed. They
take both the default message and mapping as argument. You can easily call the parent hook with
<p>It is advisable to look in the <aclass="reference external"href="https://github.com/evennia/evennia/tree/master/evennia/objects/objects.py">code of both
hooks</a>, and read the
hooks’ documentation. The explanations on how to quickly update the message are shown below:</p>
<spanclass="sd"> You can override this method and call its parent with a</span>
<spanclass="sd"> message to simply change the default message. In the string,</span>
<spanclass="sd"> you can use the following as mappings (between braces):</span>
<spanclass="sd"> object: the object which is moving.</span>
<spanclass="sd"> exit: the exit from which the object is moving (if found).</span>
<spanclass="sd"> origin: the location of the object before the move.</span>
<spanclass="sd"> destination: the location of the object after moving.</span>
<spanclass="sd">"""</span>
<spanclass="nb">super</span><spanclass="p">()</span><spanclass="o">.</span><spanclass="n">announce_move_to</span><spanclass="p">(</span><spanclass="n">source_location</span><spanclass="p">,</span><spanclass="n">msg</span><spanclass="o">=</span><spanclass="s2">"{object} arrives from the {exit}."</span><spanclass="p">)</span>
<h2>Add parsing with the “to” delimiter<aclass="headerlink"href="#add-parsing-with-the-to-delimiter"title="Permalink to this headline">¶</a></h2>
<p><strong>Q:</strong> How do I change commands to undestand say <codeclass="docutils literal notranslate"><spanclass="pre">give</span><spanclass="pre">obj</span><spanclass="pre">to</span><spanclass="pre">target</span></code> as well as the default <codeclass="docutils literal notranslate"><spanclass="pre">give</span><spanclass="pre">obj</span><spanclass="pre">=</span><spanclass="pre">target</span></code>?</p>
<p><strong>A:</strong> You can make change the default <codeclass="docutils literal notranslate"><spanclass="pre">MuxCommand</span></code> parent with your own class making a small change
in its <codeclass="docutils literal notranslate"><spanclass="pre">parse</span></code> method:</p>
<spanclass="k">if</span><spanclass="s2">" to "</span><spanclass="ow">in</span><spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">args</span><spanclass="p">:</span>
<spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">lhs</span><spanclass="p">,</span><spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">rhs</span><spanclass="o">=</span><spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">args</span><spanclass="o">.</span><spanclass="n">split</span><spanclass="p">(</span><spanclass="s2">" to "</span><spanclass="p">,</span><spanclass="mi">1</span><spanclass="p">)</span>
</pre></div>
</td></tr></table></div>
<p>Next you change the parent of the default commands in settings:</p>
<p>Do a <codeclass="docutils literal notranslate"><spanclass="pre">@reload</span></code> and all default commands will now use your new tweaked parent class. A copy of the
MuxCommand class is also found commented-out in the <codeclass="docutils literal notranslate"><spanclass="pre">mygame/commands/command.py</span></code> file.</p>
<p>Adding timestamp for login time and appending to a list to keep the last N login IP addresses and
timestamps is possible, also. Additionally, if you don’t want the list to grow beyond a
<codeclass="docutils literal notranslate"><spanclass="pre">do_not_exceed</span></code> length, conditionally pop a value after you’ve added it, if the length has grown too
<p><strong>NOTE:</strong> You’ll need to add <codeclass="docutils literal notranslate"><spanclass="pre">import</span><spanclass="pre">time</span></code> to generate the login timestamp.</p>
<spanclass="n">do_not_exceed</span><spanclass="o">=</span><spanclass="mi">24</span><spanclass="c1"># Keep the last two dozen entries</span>
<spanclass="n">session</span><spanclass="o">=</span><spanclass="bp">self</span><spanclass="o">.</span><spanclass="n">sessions</span><spanclass="o">.</span><spanclass="n">all</span><spanclass="p">()[</span><spanclass="o">-</span><spanclass="mi">1</span><spanclass="p">]</span><spanclass="c1"># Most recent session</span>
<p>This only stores the data. You may want to interface the <codeclass="docutils literal notranslate"><spanclass="pre">@ban</span></code> command or make a menu-driven viewer
for staff to browse the list and display how long ago the login occurred.</p>
<p><strong>A:</strong> The reason for this is because certain non-latin characters are <em>visually</em> much wider than
their len() suggests. There is little Evennia can (reliably) do about this. If you are using such
characters, you need to make sure to use a suitable mono-spaced font where are width are equal. You
can set this in your web client and need to recommend it for telnet-client users. See <aclass="reference external"href="https://github.com/evennia/evennia/issues/1522">this
discussion</a> where some suitable fonts are suggested.</p>
<li><aclass="reference internal"href="#preventing-character-from-moving-based-on-a-condition">Preventing character from moving based on a condition</a></li>
<li><aclass="reference internal"href="#reference-initiating-object-in-an-evmenu-command">Reference initiating object in an EvMenu command.</a></li>
<li><aclass="reference internal"href="#adding-color-to-default-evennia-channels">Adding color to default Evennia Channels</a></li>
<li><aclass="reference internal"href="#selectively-turn-off-commands-in-a-room">Selectively turn off commands in a room</a></li>
<li><aclass="reference internal"href="#select-command-based-on-a-condition">Select Command based on a condition</a></li>
<li><aclass="reference internal"href="#automatically-updating-code-when-reloading">Automatically updating code when reloading</a></li>
<li><aclass="reference internal"href="#changing-all-exit-messages">Changing all exit messages</a></li>
<li><aclass="reference internal"href="#add-parsing-with-the-to-delimiter">Add parsing with the “to” delimiter</a></li>
<li><aclass="reference internal"href="#store-last-used-session-ip-address">Store last used session IP address</a></li>
<li><aclass="reference internal"href="#non-latin-characters-in-evtable">Non-latin characters in EvTable</a></li>