<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pioneerspacesim.net/index.php?action=history&amp;feed=atom&amp;title=Lua_Module_Tutorial</id>
	<title>Lua Module Tutorial - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pioneerspacesim.net/index.php?action=history&amp;feed=atom&amp;title=Lua_Module_Tutorial"/>
	<link rel="alternate" type="text/html" href="https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;action=history"/>
	<updated>2026-05-04T23:13:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=4776&amp;oldid=prev</id>
		<title>Nnyby at 02:38, 28 April 2026</title>
		<link rel="alternate" type="text/html" href="https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=4776&amp;oldid=prev"/>
		<updated>2026-04-28T02:38:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 02:38, 28 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot; &gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Pioneer modules are structured around game events. At startup your module should register to receive notification of the game events it is interested in. When that event occurs, the Lua function you registered will be called by the game engine and can take appropriate action.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Pioneer modules are structured around game events. At startup your module should register to receive notification of the game events it is interested in. When that event occurs, the Lua function you registered will be called by the game engine and can take appropriate action.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There are many events available, see the [&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;http&lt;/del&gt;://&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;eatenbyagrue&lt;/del&gt;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;org&lt;/del&gt;/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;f/pioneer/codedoc/files/LuaEventQueue-cpp.html EventQueue &lt;/del&gt;documentation] for details. We'll cover a couple of the basic ones here to get you started.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There are many events available, see the [&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;https&lt;/ins&gt;://&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;codedoc&lt;/ins&gt;.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;pioneerspacesim.net&lt;/ins&gt;/&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;#LuaClass:Event Event &lt;/ins&gt;documentation] for details. We'll cover a couple of the basic ones here to get you started.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Your first script ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Your first script ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pioneerwiki_com-wiki_:diff::1.12:old-4775:rev-4776 --&gt;
&lt;/table&gt;</summary>
		<author><name>Nnyby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=4775&amp;oldid=prev</id>
		<title>Nnyby: fix broken link to lua api</title>
		<link rel="alternate" type="text/html" href="https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=4775&amp;oldid=prev"/>
		<updated>2026-04-28T02:36:38Z</updated>

		<summary type="html">&lt;p&gt;fix broken link to lua api&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 02:36, 28 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l4&quot; &gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It's expected that the reader has a basic understand of [http://www.lua.org/ Lua]. Reading [http://www.lua.org/pil/ Programming in Lua] if you really want to get into the guts of this interesting and powerful language. All Lua features are available to Pioneer scripts.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It's expected that the reader has a basic understand of [http://www.lua.org/ Lua]. Reading [http://www.lua.org/pil/ Programming in Lua] if you really want to get into the guts of this interesting and powerful language. All Lua features are available to Pioneer scripts.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;You should also bookmark the [&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;http&lt;/del&gt;://&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;eatenbyagrue&lt;/del&gt;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;org/f/pioneer/codedoc/files&lt;/del&gt;/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;LuaGame-cpp.html &lt;/del&gt;API reference]. You'll need it to learn about the various functions available to your module as your script gets more complicated.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;You should also bookmark the [&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;https&lt;/ins&gt;://&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;codedoc.pioneerspacesim&lt;/ins&gt;.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;net&lt;/ins&gt;/ API reference]. You'll need it to learn about the various functions available to your module as your script gets more complicated.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Please note that the Pioneer module API is still a work in progress. If you can't figure out how to do something it may be that the API needs a new method or attribute or even larger changes. Talk to the Pioneer developers and we'll see what we can do to extend it.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Please note that the Pioneer module API is still a work in progress. If you can't figure out how to do something it may be that the API needs a new method or attribute or even larger changes. Talk to the Pioneer developers and we'll see what we can do to extend it.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pioneerwiki_com-wiki_:diff::1.12:old-4559:rev-4775 --&gt;
&lt;/table&gt;</summary>
		<author><name>Nnyby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=4559&amp;oldid=prev</id>
		<title>Zonkmachine: Mark as outdated</title>
		<link rel="alternate" type="text/html" href="https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=4559&amp;oldid=prev"/>
		<updated>2024-03-18T20:56:13Z</updated>

		<summary type="html">&lt;p&gt;Mark as outdated&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 20:56, 18 March 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Outdated}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This tutorial is intended to give a brief overview of the Pioneer module system.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This tutorial is intended to give a brief overview of the Pioneer module system.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pioneerwiki_com-wiki_:diff::1.12:old-122:rev-4559 --&gt;
&lt;/table&gt;</summary>
		<author><name>Zonkmachine</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=122&amp;oldid=prev</id>
		<title>Luomu: Imported from GH wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.pioneerspacesim.net/index.php?title=Lua_Module_Tutorial&amp;diff=122&amp;oldid=prev"/>
		<updated>2012-09-16T22:10:54Z</updated>

		<summary type="html">&lt;p&gt;Imported from GH wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This tutorial is intended to give a brief overview of the Pioneer module system.&lt;br /&gt;
&lt;br /&gt;
It's expected that the reader has a basic understand of [http://www.lua.org/ Lua]. Reading [http://www.lua.org/pil/ Programming in Lua] if you really want to get into the guts of this interesting and powerful language. All Lua features are available to Pioneer scripts.&lt;br /&gt;
&lt;br /&gt;
You should also bookmark the [http://eatenbyagrue.org/f/pioneer/codedoc/files/LuaGame-cpp.html API reference]. You'll need it to learn about the various functions available to your module as your script gets more complicated.&lt;br /&gt;
&lt;br /&gt;
Please note that the Pioneer module API is still a work in progress. If you can't figure out how to do something it may be that the API needs a new method or attribute or even larger changes. Talk to the Pioneer developers and we'll see what we can do to extend it.&lt;br /&gt;
&lt;br /&gt;
=== The event model ===&lt;br /&gt;
&lt;br /&gt;
Pioneer modules are structured around game events. At startup your module should register to receive notification of the game events it is interested in. When that event occurs, the Lua function you registered will be called by the game engine and can take appropriate action.&lt;br /&gt;
&lt;br /&gt;
There are many events available, see the [http://eatenbyagrue.org/f/pioneer/codedoc/files/LuaEventQueue-cpp.html EventQueue documentation] for details. We'll cover a couple of the basic ones here to get you started.&lt;br /&gt;
&lt;br /&gt;
== Your first script ==&lt;br /&gt;
&lt;br /&gt;
The onGameStart event is called when the game is started, either from the start menu or when a save game is loaded. Since it's the first event triggered by the engine its a good place to get started with module development.&lt;br /&gt;
&lt;br /&gt;
Before we can register to receive an event, we first have to define a function to do something interesting with that event.&lt;br /&gt;
&lt;br /&gt;
Lets start by defining a simple function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local myGameStart = function ()&lt;br /&gt;
   UI.Message(&amp;quot;Welcome to Pioneer, commander.&amp;quot;, &amp;quot;Pioneer&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;UI.Message&amp;lt;/tt&amp;gt; is a simple function that displays text on the player's control panel display (where the scanner normally appears). See the API reference for more information.&lt;br /&gt;
&lt;br /&gt;
So far we've defined a function, but we haven't told Pioneer to call it at the proper time. To do that, we have to connect the function to the appropriate event queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EventQueue.onGameStart:Connect(myGameStart)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This calls the &amp;lt;tt&amp;gt;Connect&amp;lt;/tt&amp;gt; method on the &amp;lt;tt&amp;gt;EventQueue.onGameStart&amp;lt;/tt&amp;gt; object with our function as the parameter. Now that we've done this Pioneer knows about our function and will call it every time a game starts.&lt;br /&gt;
&lt;br /&gt;
Start Pioneer, and start a game. Notice the message appears on the control panel. Congratulations, you've written your first Pioneer module.&lt;br /&gt;
&lt;br /&gt;
=== Bad guys! ===&lt;br /&gt;
&lt;br /&gt;
A fun script to write when you're starting out is one that spawns ships to attack the player, so lets write that. Here's the scenario:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;The evil Badtrons have discovered the secrets of hyperspace and have placed their evil patrol ships near the hyperspace exit points of all nearby systems. Expect to be attacked the moment you leave hyperspace.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
In the Pioneer engine only one system truly &amp;amp;quot;exists&amp;amp;quot; at any one time, so you can't just make ships and place them in all the possible systems. Instead, you catch the &amp;lt;tt&amp;gt;onEnterSystem&amp;lt;/tt&amp;gt; event and watch for the player to arrive in a new system, then spawn a bunch of ships near her to make it look like they were waiting all the time.&lt;br /&gt;
&lt;br /&gt;
Here's the full script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local myEnterSystem = function (ship)&lt;br /&gt;
   if not ship:IsPlayer() then return end&lt;br /&gt;
&lt;br /&gt;
   local badguy = Space.SpawnShipNear('Talon Military Interceptor', Game.player, 10, 20)&lt;br /&gt;
   badguy:AddEquip('PULSECANNON_1MW')&lt;br /&gt;
   badguy:AIKill(Game.player)&lt;br /&gt;
&lt;br /&gt;
   UI.ImportantMessage(&amp;quot;This is a Badtron system. All others must die.&amp;quot;, badguy.label)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
EventQueue.onEnterSystem:Connect(myEnterSystem)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Registering the function with the event queue we've seen before, so we won't go into it in much more detail. The major difference to notice is that the &amp;lt;tt&amp;gt;onEnterSystem&amp;lt;/tt&amp;gt; gets passed a parameter &amp;lt;tt&amp;gt;ship&amp;lt;/tt&amp;gt;, which is the ship that entered the system.&lt;br /&gt;
&lt;br /&gt;
The first line is testing to see who entered the system. Its important to understand that a player is just a special kind of ship, and a script might want to know when non-player ships enter a system. Your script will receive a &amp;lt;tt&amp;gt;onEnterSystem&amp;lt;/tt&amp;gt; event for every ship that arrives, even if that ship was created by another script. Its important that you check to make sure the ship &amp;amp;quot;belongs&amp;amp;quot; to you, unless of course you're doing something clever to augment or override an existing script.&lt;br /&gt;
&lt;br /&gt;
If its not the player entering the system we bail out immediately - there's nothing more to do. If it is the player then we need to create a ship. &amp;lt;tt&amp;gt;Space.SpawnShipNear&amp;lt;/tt&amp;gt; is one of several ship creation functions, each with a slightly different purpose. As the name implies, this one creates a ship near a specific object.&lt;br /&gt;
&lt;br /&gt;
The parameters to &amp;lt;tt&amp;gt;Space.SpawnShipNear&amp;lt;/tt&amp;gt; are fully described in the API reference, but they are not particularly complicated. The first parameter is the name of the ship to spawn. The second is the object to spawn it near, in this case the player (we could have used &amp;lt;tt&amp;gt;ship&amp;lt;/tt&amp;gt; here; its the same object, but &amp;lt;tt&amp;gt;Game.player&amp;lt;/tt&amp;gt; makes it clearer what's going on. The third and fourth arguments specify the minimum and maximum distance to spawn the ship from the object, in kilometres. The game engine will choose a distance and position at random based on these values.&lt;br /&gt;
&lt;br /&gt;
The ship now exists, floating dead in space. We need it to attack, but before it can do that it needs a weapon. The &amp;lt;tt&amp;gt;Ship.AddEquip&amp;lt;/tt&amp;gt; method is used to add equipment and cargo to a ship. In this case we add a basic laser to the ship.&lt;br /&gt;
&lt;br /&gt;
Our enemy ship is armed so its time to attack. &amp;lt;tt&amp;gt;Ship.AIKill&amp;lt;/tt&amp;gt; is one of a class of high-level methods to instruct the ship to take some complex action. AI methods exist to put ships into orbit, dock, and so on. &amp;lt;tt&amp;gt;AIKill&amp;lt;/tt&amp;gt; invokes the combat AI, which keeps fighting until one of the combatants dies. Here we instruct our ship to attack and kill the player.&lt;br /&gt;
&lt;br /&gt;
At this point we've done all we need to do. The ship now exists, is armed, and is trying to take out the player. We do one other thing, which is to place a message on the player's control panel. Of course this is not necessary, but it adds a little realism to the scenario. The two arguments to the message functions are the message text, and who it appears to come from. The ship's &amp;lt;tt&amp;gt;label&amp;lt;/tt&amp;gt; attribute holds the registration number of the ship. By calling the method this way we get the nice message: ''Message from AB-1234: This is a Badtron system. All others must die.''&lt;/div&gt;</summary>
		<author><name>Luomu</name></author>
		
	</entry>
</feed>