<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AEvalPy</id>
	<title>Scripts:EvalPy - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AEvalPy"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:EvalPy&amp;action=history"/>
	<updated>2026-08-06T01:08:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:EvalPy&amp;diff=124&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__ == What It Does  ==  * Allows you to test snippets of Python code while the server is running, without having to restart it to load changes from files.  == Installatio...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:EvalPy&amp;diff=124&amp;oldid=prev"/>
		<updated>2018-06-22T15:35:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__ == What It Does  ==  * Allows you to test snippets of Python code while the server is running, without having to restart it to load changes from files.  == Installatio...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
== What It Does  ==&lt;br /&gt;
&lt;br /&gt;
* Allows you to test snippets of Python code while the server is running, without having to restart it to load changes from files.&lt;br /&gt;
&lt;br /&gt;
== Installation  ==&lt;br /&gt;
&lt;br /&gt;
# Browse to &amp;lt;code&amp;gt;admin/standard_admin&amp;lt;/code&amp;gt; in your bf2 server directory&lt;br /&gt;
# Edit &amp;lt;code&amp;gt;__init__.py&amp;lt;/code&amp;gt; so it looks something like the code snippet below.&lt;br /&gt;
# Save the below code to &amp;lt;code&amp;gt;admin/standard_admin/eval.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Make sure RCON is configured, then run your server. If &amp;quot;&amp;lt;code&amp;gt;eval.py loaded&amp;lt;/code&amp;gt;&amp;quot; comes up in your server console it should work from there.&lt;br /&gt;
&lt;br /&gt;
This doesn&amp;#039;t work from the server console. You&amp;#039;ll have to use an actual RCON client to use the command this script creates. The &amp;lt;code&amp;gt;remoteconsole.py&amp;lt;/code&amp;gt; script should work just fine.&lt;br /&gt;
&lt;br /&gt;
The command is &amp;quot;&amp;lt;code&amp;gt;eval [statement]&amp;lt;/code&amp;gt;&amp;quot;. An example would be something like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rcon&amp;gt; eval for i in dir(bf2.objectManager.getObjectsOfTemplate(&amp;#039;c4_explosives&amp;#039;)[0]): ctx.write(str(i) + &amp;#039;\n&amp;#039;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which then might return:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
__doc__&lt;br /&gt;
getChildren&lt;br /&gt;
getParent&lt;br /&gt;
getPosition&lt;br /&gt;
getRotation&lt;br /&gt;
getTemplateProperty&lt;br /&gt;
hasArmor&lt;br /&gt;
isControlPoint&lt;br /&gt;
isPlayerControlObject&lt;br /&gt;
isValid&lt;br /&gt;
setPosition&lt;br /&gt;
setRotation&lt;br /&gt;
templateName&lt;br /&gt;
token&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; Be extra careful when using &amp;lt;code&amp;gt;ctx.write()&amp;lt;/code&amp;gt; over RCON. Though I have the script set to catch all exceptions, giving &amp;lt;code&amp;gt;ctx.write()&amp;lt;/code&amp;gt; a non-string will still cause an exception. Failure to take this into account can cause RCON to die completely. Using &amp;lt;code&amp;gt;ctx.write(str(variable))&amp;lt;/code&amp;gt; should keep you safe.&lt;br /&gt;
&lt;br /&gt;
== Code  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== __init__.py  ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import autobalance&lt;br /&gt;
import tk_punish&lt;br /&gt;
import eval&lt;br /&gt;
&lt;br /&gt;
autobalance.init()&lt;br /&gt;
tk_punish.init()&lt;br /&gt;
eval.init()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== eval.py  ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# script for eval()ing python code over rcon&lt;br /&gt;
# -- by dackz (http://dackz.net/)&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import new&lt;br /&gt;
import default&lt;br /&gt;
import bf2&lt;br /&gt;
import host&lt;br /&gt;
import game&lt;br /&gt;
import standard_admin&lt;br /&gt;
from bf2 import g_debug&lt;br /&gt;
&lt;br /&gt;
def write(self, text): self.write_original(str(text))&lt;br /&gt;
&lt;br /&gt;
def rcmd_eval(self, ctx, cmd):&lt;br /&gt;
    try:&lt;br /&gt;
        eval(compile(cmd, &amp;#039;&amp;lt;string&amp;gt;&amp;#039;, &amp;#039;exec&amp;#039;))&lt;br /&gt;
    except:&lt;br /&gt;
        ctx.write(str(sys.exc_info()[0]).split(&amp;#039;.&amp;#039;)[-1] + &amp;#039;: &amp;#039; + str(sys.exc_info()[1]) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
def init():&lt;br /&gt;
    if g_debug: print &amp;#039;initialising eval script&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    default.CommandContext.write_original = default.CommandContext.write&lt;br /&gt;
    newMethod = new.instancemethod(write, None, default.CommandContext)&lt;br /&gt;
    default.CommandContext.write = newMethod&lt;br /&gt;
&lt;br /&gt;
    newMethod = new.instancemethod(rcmd_eval, default.server, default.AdminServer)&lt;br /&gt;
    default.AdminServer.rcmd_eval = newMethod&lt;br /&gt;
    default.server.rcon_cmds[&amp;#039;eval&amp;#039;] = default.AdminServer.rcmd_eval&lt;br /&gt;
&lt;br /&gt;
    host.rcon_invoke(&amp;#039;echo &amp;quot;eval.py loaded&amp;quot;&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>