<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Adding a Script</title><link>https://sourceforge.net/p/hercules/wiki/Adding%2520a%2520Script/</link><description>Recent changes to Adding a Script</description><atom:link href="https://sourceforge.net/p/hercules/wiki/Adding%20a%20Script/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 20 Feb 2023 05:00:31 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/hercules/wiki/Adding%20a%20Script/feed" rel="self" type="application/rss+xml"/><item><title>Adding a Script modified by Brynner</title><link>https://sourceforge.net/p/hercules/wiki/Adding%2520a%2520Script/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;{{outdated}}&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#adding-and-activating-scripts"&gt;Adding and Activating Scripts&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#a-new-script"&gt;A New Script&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#configuration-files"&gt;Configuration Files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-npc-in-game"&gt;The NPC in Game&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#client-side"&gt;Client Side&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#lua"&gt;Lua&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sprite"&gt;Sprite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#tips-hints"&gt;Tips &amp;amp; Hints&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="adding-and-activating-scripts"&gt;Adding and Activating Scripts&lt;/h2&gt;
&lt;p&gt;Scripts are usually kept in the &lt;em&gt;npc&lt;/em&gt; folder for the sake of organization even&lt;br/&gt;
though scripts can contain more than a mere NPC. All files are saved as text&lt;br/&gt;
files. Scripts cannot be loaded on to the server unless their text file is&lt;br/&gt;
activated in a *.conf file.&lt;/p&gt;
&lt;h3 id="a-new-script"&gt;A New Script&lt;/h3&gt;
&lt;p&gt;New scripts must be saved as a text file first. The file may be located&lt;br/&gt;
anywhere in the Hercules directory, but is in the &lt;em&gt;npc&lt;/em&gt; folder by default.&lt;/p&gt;
&lt;h3 id="configuration-files"&gt;Configuration Files&lt;/h3&gt;
&lt;p&gt;Any text editor may be used to edit &lt;em&gt;.conf files. The _npc/&lt;/em&gt;.conf_ files are&lt;br/&gt;
used to determine which script text files should be loaded. There are about a&lt;br/&gt;
dozen &lt;em&gt;.conf that handle different groups of scripts for the purpose of&lt;br/&gt;
organization. It does not matter which &lt;/em&gt;.conf holds your custom scripts as&lt;br/&gt;
long as the path is correct.&lt;/p&gt;
&lt;p&gt;Typical *.conf entry layout:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;npc&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;npc&lt;/span&gt;&lt;span class="sr"&gt;/path/to/&lt;/span&gt;&lt;span class="n"&gt;yourscript1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;txt&lt;/span&gt;
&lt;span class="c1"&gt;// npc: npc/path/to/yourscript2.txt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Note how the second line is preceded with a double slash. Content on the same&lt;br/&gt;
line after double slashes will not be parsed. In other words, &lt;em&gt;script2.txt&lt;/em&gt;&lt;br/&gt;
will not be loaded. The slashes can be used to write comments.&lt;/p&gt;
&lt;p&gt;{{git|npc/pre-re/scripts_main.conf}} or {{git|npc/re/scripts_main.conf}}&lt;br/&gt;
determines which of the *.conf will be read by the server.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;npc&lt;/span&gt;&lt;span class="sr"&gt;/path/to/&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;conf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="the-npc-in-game"&gt;The NPC in Game&lt;/h3&gt;
&lt;p&gt;After adding the script, it must be loaded before the script contents take&lt;br/&gt;
effect in game. There are a few ways to do this.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The map server can be rebooted. This is generally the safest route though not the most convenient for active servers. &lt;/li&gt;
&lt;li&gt;The GM command &lt;strong&gt;@reloadscript&lt;/strong&gt; maybe used in game, though this may cause monster spawn bugs. &lt;/li&gt;
&lt;li&gt;If a script needs to be reloaded because it has been edited, the GM commands &lt;strong&gt;@loadnpc&lt;/strong&gt; and &lt;strong&gt;@unloadnpc&lt;/strong&gt; may be used. This method is not convenient for script texts that contain multiple NPCs. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="client-side"&gt;Client Side&lt;/h2&gt;
&lt;p&gt;The NPC name used in examples is "Teddy".&lt;/p&gt;
&lt;h3 id="lua"&gt;Lua&lt;/h3&gt;
&lt;p&gt;The two files you will need to open and edit are "jobname.lua" and&lt;br/&gt;
"npcidentity.lua". Jobname.lua will look like:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;    [jobtbl.NPCNAME] = "NPCNAME",
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;    [jobtbl.TEDDY] = "TEDDY",
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;npcidentity.lua will look like:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;    ["NPCNAME"] = NPCID,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;    ["TEDDY"] = 587,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If your NPC has spaces in its name, its best to either remove them or replace&lt;br/&gt;
them with underscores. So if the NPC's name was Brown Teddy the sprite's name&lt;br/&gt;
would be Brown_Teddy.spr or BrownTeddy.spr and the lua files would be&lt;br/&gt;
BROWN_TEDDY or BROWNTEDDY. Whatever ID you choose for your sprite, either NPC&lt;br/&gt;
Sprite name(Case-Sensitive, In Capital Letters) or ID will be use in the&lt;br/&gt;
script. The beginning of my script will look like:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;    xmas_in,111,107,3   script  Teddy   587,{
    xmas_in,111,107,3   script  Teddy   TEDDY,{
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="sprite"&gt;Sprite&lt;/h3&gt;
&lt;p&gt;The sprite part is straightforward, just Teddy.spr is fine, you don't need&lt;br/&gt;
Teddy_m.spr or anything like that, but if you want to add m for male to the&lt;br/&gt;
name you can do that, but it won't effect its functionality in-game. NPC&lt;br/&gt;
sprites are located in data/sprite/npc.&lt;/p&gt;
&lt;h2 id="tips-hints"&gt;Tips &amp;amp; Hints&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;If you are copy/pasting a script from a forum, be sure to check that the tabs are still intact. &lt;/li&gt;
&lt;li&gt;Remember that paths and file names are case sensitive. &lt;/li&gt;
&lt;li&gt;Remember to save after editing. &lt;/li&gt;
&lt;li&gt;Create your own NPC folder and &lt;em&gt;.conf file. This will make it much easier to keep track of your own scripts and can reduce the hassle when merging new revisions of Hercules. Follow the basic layout of the other &lt;/em&gt;.conf files and remember to import the *.conf in {{git|npc/scripts_main.conf}} &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;[Category:Scripting]&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brynner</dc:creator><pubDate>Mon, 20 Feb 2023 05:00:31 -0000</pubDate><guid>https://sourceforge.nete59dc19f22e1aeaadedc3cc1fbfd38e95bd2d8aa</guid></item></channel></rss>