mirror of
https://github.com/evennia/evennia.git
synced 2026-03-20 14:56:30 +01:00
Updated HTML docs
This commit is contained in:
parent
f505351730
commit
a551188691
1002 changed files with 30387 additions and 9820 deletions
|
|
@ -7,11 +7,13 @@
|
|||
<title>Coding FAQ — Evennia 1.0-dev documentation</title>
|
||||
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
|
||||
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||||
<script src="_static/jquery.js"></script>
|
||||
<script src="_static/underscore.js"></script>
|
||||
<script src="_static/doctools.js"></script>
|
||||
<script src="_static/language_data.js"></script>
|
||||
|
||||
<link rel="shortcut icon" href="_static/favicon.ico"/>
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
|
|
@ -25,7 +27,10 @@
|
|||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> »</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> »</li>
|
||||
<li class="nav-item nav-item-last"><a href="#">Coding FAQ</a></li>
|
||||
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
@ -36,32 +41,44 @@
|
|||
|
||||
<div class="section" id="coding-faq">
|
||||
<h1>Coding FAQ<a class="headerlink" href="#coding-faq" title="Permalink to this headline">¶</a></h1>
|
||||
<p><em>This FAQ page is for users to share their solutions to coding problems. Keep it brief and link to the docs if you can rather than too lengthy explanations. Don’t forget to check if an answer already exists before answering - maybe you can clarify that answer rather than to make a new Q&A section.</em></p>
|
||||
<p><em>This FAQ page is for users to share their solutions to coding problems. Keep it brief and link to
|
||||
the docs if you can rather than too lengthy explanations. Don’t forget to check if an answer already
|
||||
exists before answering - maybe you can clarify that answer rather than to make a new Q&A section.</em></p>
|
||||
<div class="section" id="table-of-contents">
|
||||
<h2>Table of Contents<a class="headerlink" href="#table-of-contents" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#removing-default-commands">Removing default commands</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#preventing-character-from-moving-based-on-a-condition">Preventing character from moving based on a condition</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#reference-initiating-object-in-an-evmenu-command">Reference initiating object in an EvMenu command</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#adding-color-to-default-evennia-channels">Adding color to default Evennia Channels</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#selectively-turn-off-commands-in-a-room">Selectively turn off commands in a room</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#select-command-based-on-a-condition">Select Command based on a condition</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#automatically-updating-code-when-reloading">Automatically updating code when reloading</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#changing-all-exit-messages">Changing all exit messages</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#add-parsing-with-the-to-delimiter">Add parsing with the “to” delimiter</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#store-last-used-session-ip-address">Store last used session IP address</a></p></li>
|
||||
<li><p><a class="reference external" href="/Coding-FAQ.html#non-latin-characters-in-evtable">Use wide characters with EvTable</a></p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#removing-default-commands">Removing default commands</a></p></li>
|
||||
<li><p>[Preventing character from moving based on a condition](Coding-FAQ#preventing-character-from-
|
||||
moving-based-on-a-condition)</p></li>
|
||||
<li><p>[Reference initiating object in an EvMenu command](Coding-FAQ#reference-initiating-object-in-an-
|
||||
evmenu-command)</p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#adding-color-to-default-evennia-channels">Adding color to default Evennia Channels</a></p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#selectively-turn-off-commands-in-a-room">Selectively turn off commands in a room</a></p></li>
|
||||
<li><p><a class="reference external" href="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-
|
||||
reloading)</p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#changing-all-exit-messages">Changing all exit messages</a></p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#add-parsing-with-the-to-delimiter">Add parsing with the “to” delimiter</a></p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#store-last-used-session-ip-address">Store last used session IP address</a></p></li>
|
||||
<li><p><a class="reference external" href="Coding-FAQ.html#non-latin-characters-in-evtable">Use wide characters with EvTable</a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="removing-default-commands">
|
||||
<h2>Removing default commands<a class="headerlink" href="#removing-default-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> How does one <em>remove</em> (not replace) e.g. the default <code class="docutils literal notranslate"><span class="pre">get</span></code> <a class="reference internal" href="Commands.html"><span class="doc">Command</span></a> from the Character <a class="reference internal" href="Command-Sets.html"><span class="doc">Command Set</span></a>?</p>
|
||||
<p><strong>A:</strong> Go to <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code>. Find the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> class. It has one method named <code class="docutils literal notranslate"><span class="pre">at_cmdset_creation</span></code>. At the end of that method, add the following line: <code class="docutils literal notranslate"><span class="pre">self.remove(default_cmds.CmdGet())</span></code>. See the <a class="reference internal" href="Adding-Command-Tutorial.html"><span class="doc">Adding Commands Tutorial</span></a> for more info.</p>
|
||||
<p><strong>Q:</strong> How does one <em>remove</em> (not replace) e.g. the default <code class="docutils literal notranslate"><span class="pre">get</span></code> <a class="reference internal" href="Commands.html"><span class="doc">Command</span></a> from the
|
||||
Character <a class="reference internal" href="Command-Sets.html"><span class="doc">Command Set</span></a>?</p>
|
||||
<p><strong>A:</strong> Go to <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code>. Find the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> class. It has one
|
||||
method named <code class="docutils literal notranslate"><span class="pre">at_cmdset_creation</span></code>. At the end of that method, add the following line:
|
||||
<code class="docutils literal notranslate"><span class="pre">self.remove(default_cmds.CmdGet())</span></code>. See the <a class="reference internal" href="Adding-Command-Tutorial.html"><span class="doc">Adding Commands Tutorial</span></a>
|
||||
for more info.</p>
|
||||
</div>
|
||||
<div class="section" id="preventing-character-from-moving-based-on-a-condition">
|
||||
<h2>Preventing character from moving based on a condition<a class="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 <code class="docutils literal notranslate"><span class="pre">at_before_move</span></code> hook is called by Evennia just before performing any move. If it returns <code class="docutils literal notranslate"><span class="pre">False</span></code>, the move is aborted. Let’s say we want to check for an <a class="reference internal" href="Attributes.html"><span class="doc">Attribute</span></a> <code class="docutils literal notranslate"><span class="pre">cantmove</span></code>. Add the following code to the <code class="docutils literal notranslate"><span class="pre">Character</span></code> class:</p>
|
||||
<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 <code class="docutils literal notranslate"><span class="pre">at_before_move</span></code> hook is called by Evennia just before performing any move. If it returns
|
||||
<code class="docutils literal notranslate"><span class="pre">False</span></code>, the move is aborted. Let’s say we want to check for an <a class="reference internal" href="Attributes.html"><span class="doc">Attribute</span></a> <code class="docutils literal notranslate"><span class="pre">cantmove</span></code>.
|
||||
Add the following code to the <code class="docutils literal notranslate"><span class="pre">Character</span></code> class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
|
|
@ -78,8 +95,12 @@
|
|||
</div>
|
||||
<div class="section" id="reference-initiating-object-in-an-evmenu-command">
|
||||
<h2>Reference initiating object in an EvMenu command.<a class="headerlink" href="#reference-initiating-object-in-an-evmenu-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> An object has a Command on it starts up an EvMenu instance. How do I capture a reference to that object for use in the menu?</p>
|
||||
<p><strong>A:</strong> When an <a class="reference internal" href="EvMenu.html"><span class="doc">EvMenu</span></a> is started, the menu object is stored as <code class="docutils literal notranslate"><span class="pre">caller.ndb._menutree</span></code>. This is a good place to store menu-specific things since it will clean itself up when the menu closes. When initiating the menu, any additional keywords you give will be available for you as properties on this menu object:</p>
|
||||
<p><strong>Q:</strong> An object has a Command on it starts up an EvMenu instance. How do I capture a reference to
|
||||
that object for use in the menu?</p>
|
||||
<p><strong>A:</strong> When an <a class="reference internal" href="EvMenu.html"><span class="doc">EvMenu</span></a> is started, the menu object is stored as <code class="docutils literal notranslate"><span class="pre">caller.ndb._menutree</span></code>.
|
||||
This is a good place to store menu-specific things since it will clean itself up when the menu
|
||||
closes. When initiating the menu, any additional keywords you give will be available for you as
|
||||
properties on this menu object:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
|
|
@ -98,7 +119,8 @@
|
|||
<div class="section" id="adding-color-to-default-evennia-channels">
|
||||
<h2>Adding color to default Evennia Channels<a class="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’ <code class="docutils literal notranslate"><span class="pre">channel_prefix</span></code> method decides what is shown at the beginning of a channel send. Edit <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/channels.py</span></code> (and then <code class="docutils literal notranslate"><span class="pre">@reload</span></code>):</p>
|
||||
<p><strong>A:</strong> The Channel typeclass’ <code class="docutils literal notranslate"><span class="pre">channel_prefix</span></code> method decides what is shown at the beginning of a
|
||||
channel send. Edit <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/channels.py</span></code> (and then <code class="docutils literal notranslate"><span class="pre">@reload</span></code>):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
|
|
@ -128,12 +150,16 @@
|
|||
<span class="k">return</span> <span class="n">prefix_string</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Additional hint: To make colors easier to change from one place you could instead put the <code class="docutils literal notranslate"><span class="pre">CHANNEL_COLORS</span></code> dict in your settings file and import it as <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">django.conf.settings</span> <span class="pre">import</span> <span class="pre">CHANNEL_COLORS</span></code>.</p>
|
||||
<p>Additional hint: To make colors easier to change from one place you could instead put the
|
||||
<code class="docutils literal notranslate"><span class="pre">CHANNEL_COLORS</span></code> dict in your settings file and import it as <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">django.conf.settings</span> <span class="pre">import</span> <span class="pre">CHANNEL_COLORS</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="selectively-turn-off-commands-in-a-room">
|
||||
<h2>Selectively turn off commands in a room<a class="headerlink" href="#selectively-turn-off-commands-in-a-room" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> I want certain commands to turn off in a given room. They should still work normally for staff.</p>
|
||||
<p><strong>A:</strong> This is done using a custom cmdset on a room <a class="reference internal" href="Locks.html"><span class="doc">locked with the ‘call’ lock type</span></a>. Only if this lock is passed will the commands on the room be made available to an object inside it. Here is an example of a room where certain commands are disabled for non-staff:</p>
|
||||
<p><strong>Q:</strong> I want certain commands to turn off in a given room. They should still work normally for
|
||||
staff.</p>
|
||||
<p><strong>A:</strong> This is done using a custom cmdset on a room <a class="reference internal" href="Locks.html"><span class="doc">locked with the ‘call’ lock type</span></a>. Only
|
||||
if this lock is passed will the commands on the room be made available to an object inside it. Here
|
||||
is an example of a room where certain commands are disabled for non-staff:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
|
|
@ -183,12 +209,19 @@
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">locks</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s2">"call:not perm(Builders)"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>After <code class="docutils literal notranslate"><span class="pre">@reload</span></code>, make some <code class="docutils literal notranslate"><span class="pre">BlockingRooms</span></code> (or switch a room to it with <code class="docutils literal notranslate"><span class="pre">@typeclass</span></code>). Entering one will now replace the given commands for anyone that does not have the <code class="docutils literal notranslate"><span class="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 superusers).</p>
|
||||
<p>After <code class="docutils literal notranslate"><span class="pre">@reload</span></code>, make some <code class="docutils literal notranslate"><span class="pre">BlockingRooms</span></code> (or switch a room to it with <code class="docutils literal notranslate"><span class="pre">@typeclass</span></code>). Entering one
|
||||
will now replace the given commands for anyone that does not have the <code class="docutils literal notranslate"><span class="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
|
||||
superusers).</p>
|
||||
</div>
|
||||
<div class="section" id="select-command-based-on-a-condition">
|
||||
<h2>Select Command based on a condition<a class="headerlink" href="#select-command-based-on-a-condition" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> I want a command to be available only based on a condition. For example I want the “werewolf” command to only be available on a full moon, from midnight to three in-game time.</p>
|
||||
<p><strong>A:</strong> This is easiest accomplished by putting the “werewolf” command on the Character as normal, but to <a class="reference internal" href="Locks.html"><span class="doc">lock</span></a> it with the “cmd” type lock. Only if the “cmd” lock type is passed will the command be available.</p>
|
||||
<p><strong>Q:</strong> I want a command to be available only based on a condition. For example I want the “werewolf”
|
||||
command to only be available on a full moon, from midnight to three in-game time.</p>
|
||||
<p><strong>A:</strong> This is easiest accomplished by putting the “werewolf” command on the Character as normal,
|
||||
but to <a class="reference internal" href="Locks.html"><span class="doc">lock</span></a> it with the “cmd” type lock. Only if the “cmd” lock type is passed will the
|
||||
command be available.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
|
|
@ -210,7 +243,8 @@
|
|||
<span class="c1"># ...</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Add this to the <a class="reference internal" href="Adding-Command-Tutorial.html"><span class="doc">default cmdset as usual</span></a>. The <code class="docutils literal notranslate"><span class="pre">is_full_moon</span></code> <a class="reference external" href="/Locks.html#lock-functions">lock function</a> does not yet exist. We must create that:</p>
|
||||
<p>Add this to the <a class="reference internal" href="Adding-Command-Tutorial.html"><span class="doc">default cmdset as usual</span></a>. The <code class="docutils literal notranslate"><span class="pre">is_full_moon</span></code> <a class="reference external" href="Locks.html#lock-functions">lock
|
||||
function</a> does not yet exist. We must create that:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
|
|
@ -226,12 +260,16 @@
|
|||
<span class="c1"># return True or False</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>After a <code class="docutils literal notranslate"><span class="pre">@reload</span></code>, the <code class="docutils literal notranslate"><span class="pre">werewolf</span></code> command will be available only at the right time, that is when the <code class="docutils literal notranslate"><span class="pre">is_full_moon</span></code> lock function returns True.</p>
|
||||
<p>After a <code class="docutils literal notranslate"><span class="pre">@reload</span></code>, the <code class="docutils literal notranslate"><span class="pre">werewolf</span></code> command will be available only at the right time, that is when the
|
||||
<code class="docutils literal notranslate"><span class="pre">is_full_moon</span></code> lock function returns True.</p>
|
||||
</div>
|
||||
<div class="section" id="automatically-updating-code-when-reloading">
|
||||
<h2>Automatically updating code when reloading<a class="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 <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">pull</span></code> when you reload. And that’s pretty straightforward:</p>
|
||||
<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 <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">pull</span></code> when you reload. And that’s pretty straightforward:</p>
|
||||
<p>In <code class="docutils literal notranslate"><span class="pre">/server/conf/at_server_startstop.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
|
|
@ -254,26 +292,43 @@
|
|||
<span class="n">process</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">"git"</span><span class="p">,</span> <span class="s2">"pull"</span><span class="p">],</span> <span class="n">shell</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>That’s all. We call <code class="docutils literal notranslate"><span class="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). <code class="docutils literal notranslate"><span class="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 <code class="docutils literal notranslate"><span class="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 something like:</p>
|
||||
<p>That’s all. We call <code class="docutils literal notranslate"><span class="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). <code class="docutils literal notranslate"><span class="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 <code class="docutils literal notranslate"><span class="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
|
||||
something like:</p>
|
||||
<ol class="simple">
|
||||
<li><p>Coding on the local machine.</p></li>
|
||||
<li><p>Testing modifications.</p></li>
|
||||
<li><p>Committing once, twice or more (being sure the code is still working, unittests are pretty useful here).</p></li>
|
||||
<li><p>Committing once, twice or more (being sure the code is still working, unittests are pretty useful
|
||||
here).</p></li>
|
||||
<li><p>When the time comes, login to the development server and run <code class="docutils literal notranslate"><span class="pre">@reload</span></code>.</p></li>
|
||||
</ol>
|
||||
<p>The reloading might take one or two additional seconds, since Evennia will pull from your remote Git repository. But it will reload on it and you will have your modifications ready, without needing connecting to your server using SSH or something similar.</p>
|
||||
<p>The reloading might take one or two additional seconds, since Evennia will pull from your remote Git
|
||||
repository. But it will reload on it and you will have your modifications ready, without needing
|
||||
connecting to your server using SSH or something similar.</p>
|
||||
</div>
|
||||
<div class="section" id="changing-all-exit-messages">
|
||||
<h2>Changing all exit messages<a class="headerlink" href="#changing-all-exit-messages" title="Permalink to this headline">¶</a></h2>
|
||||
<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 <code class="docutils literal notranslate"><span class="pre">announce_move_from</span></code> and <code class="docutils literal notranslate"><span class="pre">announce_move_to</span></code>, on the <code class="docutils literal notranslate"><span class="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 these information:</p>
|
||||
<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 <code class="docutils literal notranslate"><span class="pre">announce_move_from</span></code> and
|
||||
<code class="docutils literal notranslate"><span class="pre">announce_move_to</span></code>, on the <code class="docutils literal notranslate"><span class="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
|
||||
these information:</p>
|
||||
<ul class="simple">
|
||||
<li><p>The message represents the string of characters sent to characters in the room when a character leaves.</p></li>
|
||||
<li><p>The mapping is a dictionary containing additional mappings (you will probably not need it for simple customization).</p></li>
|
||||
<li><p>The message represents the string of characters sent to characters in the room when a character
|
||||
leaves.</p></li>
|
||||
<li><p>The mapping is a dictionary containing additional mappings (you will probably not need it for
|
||||
simple customization).</p></li>
|
||||
</ul>
|
||||
<p>It is advisable to look in the <a class="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>
|
||||
<p>It is advisable to look in the <a class="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>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
|
|
@ -387,12 +442,16 @@
|
|||
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">announce_move_to</span><span class="p">(</span><span class="n">source_location</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s2">"{object} arrives from the {exit}."</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>We override both hooks, but call the parent hook to display a different message. If you read the provided docstrings, you will better understand why and how we use mappings (information between braces). You can provide additional mappings as well, if you want to set a verb to move, for instance, or other, extra information.</p>
|
||||
<p>We override both hooks, but call the parent hook to display a different message. If you read the
|
||||
provided docstrings, you will better understand why and how we use mappings (information between
|
||||
braces). You can provide additional mappings as well, if you want to set a verb to move, for
|
||||
instance, or other, extra information.</p>
|
||||
</div>
|
||||
<div class="section" id="add-parsing-with-the-to-delimiter">
|
||||
<h2>Add parsing with the “to” delimiter<a class="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 <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">obj</span> <span class="pre">to</span> <span class="pre">target</span></code> as well as the default <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">obj</span> <span class="pre">=</span> <span class="pre">target</span></code>?</p>
|
||||
<p><strong>A:</strong> You can make change the default <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> parent with your own class making a small change in its <code class="docutils literal notranslate"><span class="pre">parse</span></code> method:</p>
|
||||
<p><strong>A:</strong> You can make change the default <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> parent with your own class making a small change
|
||||
in its <code class="docutils literal notranslate"><span class="pre">parse</span></code> method:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
|
|
@ -419,7 +478,8 @@ MuxCommand class is also found commented-out in the <code class="docutils litera
|
|||
</div>
|
||||
<div class="section" id="store-last-used-session-ip-address">
|
||||
<h2>Store last used session IP address<a class="headerlink" href="#store-last-used-session-ip-address" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> If a user has already logged out of an Evennia account, their IP is no longer visible to staff that wants to ban-by-ip (instead of the user) with <code class="docutils literal notranslate"><span class="pre">@ban/ip</span></code>?</p>
|
||||
<p><strong>Q:</strong> If a user has already logged out of an Evennia account, their IP is no longer visible to
|
||||
staff that wants to ban-by-ip (instead of the user) with <code class="docutils literal notranslate"><span class="pre">@ban/ip</span></code>?</p>
|
||||
<p><strong>A:</strong> One approach is to write the IP from the last session onto the “account” account object.</p>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">typeclasses/accounts.py</span></code></p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
|
|
@ -429,7 +489,10 @@ MuxCommand class is also found commented-out in the <code class="docutils litera
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">lastsite</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sessions</span><span class="o">.</span><span class="n">all</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">address</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<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 <code class="docutils literal notranslate"><span class="pre">do_not_exceed</span></code> length, conditionally pop a value after you’ve added it, if the length has grown too long.</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
|
||||
<code class="docutils literal notranslate"><span class="pre">do_not_exceed</span></code> length, conditionally pop a value after you’ve added it, if the length has grown too
|
||||
long.</p>
|
||||
<p><strong>NOTE:</strong> You’ll need to add <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">time</span></code> to generate the login timestamp.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
|
|
@ -450,7 +513,8 @@ MuxCommand class is also found commented-out in the <code class="docutils litera
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">lastsite</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>This only stores the data. You may want to interface the <code class="docutils literal notranslate"><span class="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>This only stores the data. You may want to interface the <code class="docutils literal notranslate"><span class="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>
|
||||
</div>
|
||||
<div class="section" id="non-latin-characters-in-evtable">
|
||||
<h2>Non-latin characters in EvTable<a class="headerlink" href="#non-latin-characters-in-evtable" title="Permalink to this headline">¶</a></h2>
|
||||
|
|
@ -462,7 +526,11 @@ MuxCommand class is also found commented-out in the <code class="docutils litera
|
|||
<span class="o">+~~~~~~+~~~~~~+</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<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 <a class="reference external" href="https://github.com/evennia/evennia/issues/1522">this discussion</a> where some suitable fonts are suggested.</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 <a class="reference external" href="https://github.com/evennia/evennia/issues/1522">this
|
||||
discussion</a> where some suitable fonts are suggested.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -530,7 +598,10 @@ MuxCommand class is also found commented-out in the <code class="docutils litera
|
|||
<li class="right" >
|
||||
<a href="py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> »</li>
|
||||
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> »</li>
|
||||
<li class="nav-item nav-item-last"><a href="#">Coding FAQ</a></li>
|
||||
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue