<?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%3AAutomatic_Announcements</id>
	<title>Scripts:Automatic Announcements - 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%3AAutomatic_Announcements"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:Automatic_Announcements&amp;action=history"/>
	<updated>2026-08-06T00:37:50Z</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:Automatic_Announcements&amp;diff=105&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;Ever want to have an some announcement that is automatically periodically displayed on all players&#039; screens? Here&#039;s how to do it:  &lt;pre&gt;  import bf2  import bf2.Timer  import...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:Automatic_Announcements&amp;diff=105&amp;oldid=prev"/>
		<updated>2018-06-22T15:25:55Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Ever want to have an some announcement that is automatically periodically displayed on all players&amp;#039; screens? Here&amp;#039;s how to do it:  &amp;lt;pre&amp;gt;  import bf2  import bf2.Timer  import...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Ever want to have an some announcement that is automatically periodically displayed on all players&amp;#039; screens? Here&amp;#039;s how to do it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 import bf2&lt;br /&gt;
 import bf2.Timer&lt;br /&gt;
 import host&lt;br /&gt;
 &lt;br /&gt;
 interval = 30   # Number of seconds between announcements&lt;br /&gt;
 message = &amp;quot;Your announcement message goes here&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 def onTimer(data):&lt;br /&gt;
     global message&lt;br /&gt;
     host.rcon_invoke(&amp;#039;game.sayall &amp;quot;%s&amp;quot;&amp;#039; % message)&lt;br /&gt;
 &lt;br /&gt;
 timer = bf2.Timer(onTimer, interval, 1)&lt;br /&gt;
 timer.setRecurring(interval)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To work, this script needs to be a module (in it&amp;#039;s own file--for example, &amp;quot;&amp;lt;code&amp;gt;simpleAnnounce.py&amp;lt;/code&amp;gt;&amp;quot;) which is imported by one of the main BF2 modules or packages (bf2, the Admin module, or the bf2 mod); you can import it from any of these, but because of it&amp;#039;s function, it probably makes the most sense to import it from the admin module.&lt;br /&gt;
&lt;br /&gt;
To do this, put simpleAnnounce.py into the directory &amp;lt;code&amp;gt;Battlefield 2 Server/Admin/standard_admin&amp;lt;/code&amp;gt;; then, in that same folder, edit the file &amp;lt;code&amp;gt;__init__.py&amp;lt;/code&amp;gt; and add the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; import simpleAnnounce &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(it doesn&amp;#039;t matter where you put this line inside &amp;lt;code&amp;gt;__init__.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
When the [[Admin_Module|Admin Module]] is initialized, it imports the &amp;lt;code&amp;gt;standard_admin&amp;lt;/code&amp;gt; package, which, because of the change you made, will now also import your &amp;lt;code&amp;gt;simpleAnnounce&amp;lt;/code&amp;gt; module. When a module is first imported the code in it is run, so &amp;lt;code&amp;gt;simpleAnnounce&amp;lt;/code&amp;gt; will create a [[Object_Reference#bf2.Timer|bf2.Timer]] object set to fire a [[Event_Reference#Timer_Events|TimerEvent]] every &amp;lt;code&amp;gt;interval&amp;lt;/code&amp;gt; seconds, with a callback to the &amp;lt;code&amp;gt;onTimer&amp;lt;/code&amp;gt; method. When &amp;lt;code&amp;gt;onTimer&amp;lt;/code&amp;gt; gets called every &amp;lt;code&amp;gt;interval&amp;lt;/code&amp;gt; seconds, it uses the &amp;lt;code&amp;gt;game.sayall&amp;lt;/code&amp;gt; server command to send your message to all players.&lt;br /&gt;
&lt;br /&gt;
This script is very basic--it should be easy to extend it to, for example, rotate one by one through a set of different messages, to read the messages it displays from a configuration file, etc.&lt;br /&gt;
&lt;br /&gt;
--Woody&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>