For these tutorials you must use an editor that saves files as plain text. I use SciTE because it has syntax highlighting and some people prefer Notepad++ which also has syntax highlighting. Those are free editors you can download. There are some commercial editors and they can be very expensive. You can use Windows Notepad or the equivalent editor on Linux but those don't have syntax highlighting for your code.
If you need a lightweight code editor I have provided a ZIP file at the end of this tutorial of version 3.6.6 of SciTE. I have also written a small tutorial on configuring it for your POL installation.
Adding items Part 01.
Items are declared, or more properly defined, in an itemdesc.cfg file. We will look at some examples of item definitions. I will be using itemdesc.cfg files from the POL Distro. Unless otherwise specified the examples will be taken from the itemdesc.cfg file in \pol\config.
Go ahead and open the itemdesc.cfg file in \pol\config in your editor and let's look at the first two items defined in the file.
Code: Select all
Item 0x2
{
Name ank1a
movable 0
}
Item 0x3
{
Name ank1b
movable 0
}
So let's create a custom ank. We will call the parts customank1a and customank1b. For these you will need the Graphic element.
Code: Select all
Item 0x20002
{
Name customank1a
Graphic 0x2
movable 0
}
Item 0x20003
{
Name customank1b
Graphic 0x3
movable 0
}
Code: Select all
# 0x9c18 - 0x10fff unused
0x11000 SmallBoat boat
# 0x11001 - 0x11003 unused
0x11004 SmallDragonBoat boat
# 0x11005 - 0x11007 unused
0x11008 MediumBoat boat
# 0x11009 - 0x1100b unused
0x1100c MediumDragonBoat boat
# 0x1100d - 0x1100f unused
0x11010 LargeBoat boat
# 0x11011 - 0x11013 unused
0x11014 LargeDragonBoat boat
# 0x11015 - 0x11017 unused
We have added the Graphic element to these custom anks so that POL knows to use the ank graphic for these objects. If you create a custom object you must assign it a valid graphic number, something from the art tile graphics that are defined in your client files. If you do not do that POL will complain and shut down. It will tell you that ObjType <some number> doesn't have a graphic assigned to it. That may not be the exact phrase it uses but it will be similar. A good tool for viewing the art tiles is UO Fiddler.
If you have not opened itemdesc.cfg in \pol\config then open that file now in your editor and go to the end of the file and copy the items from this tutorial and paste them at the end of the file and save it then start POL. Login to your server. You can create the anks using .create customank1a and .create customank1b. That would create them in your backpack but unless you have your moveany privilege set then you would have to use .unlock to set them to movable. Otherwise they are locked down in your backpack and because they have the movable element set to 0 are not movable. There is another item creation command, .createat, which gives you a target cursor that allows you to target the location where you want to place the item. So at this point go ahead and add these items to the itemdesc.cfg file in \pol\config and start POL and use .createat 0x20002 and place the customank1a in the world. Oh. You noticed I used the ObjType number in that .createat command? You can use either the Name of the item or the ObjType number to create an item.
Once you have created the item, depending on your settings in Options in your client, either hover your mouse over the customank1a or single click on it. Notice it displays the name "customank1a". I like to play shards that are more role play oriented and that is not very role play-ish. POL insists on unique names for items so you could change the name to something unique but you have the other half of the ank and it requires a unique name. Since the two halves make one ank you don't actually want one half of the ank to appear as one name and the other half to appear named something else. Thankfully there is a solution, the Desc element which means "description". Let's add that to our customank items.
Code: Select all
Item 0x20002
{
Name customank1a
Desc Healig Ank
Graphic 0x2
movable 0
}
Item 0x20003
{
Name customank1b
Desc Healig Ank
Graphic 0x3
movable 0
}
Alright, we've created a custom item called Healing Ank. It heal's players correct? Well, not yet. It needs to have a script attached to it to do that. There are a number of script types that can be assigned to items that make those items do things. The first script we are going to look at is a UseScript. You can also use the element name Script instead of UseScript but I will use the traditional name here. When the item has a use script attached to it that script is executed when the item is "used" by double-clicking on it.
But before I discuss UseScripts I want to discuss creating a package for our healing ank. A package is basically what the name implies, a special place where you put things. That helps keep them organized and can make it easier for sharing your creations with others if you want to. Packages are typically kept in the \pol\pkg directory and have their own directory there. Packages can be inside directories in the pkg directory. If you open \pol\pkg\items you will see some subdirectories there that are packages. A package directory contains a special file named pkg.cfg. Here is what the contents of a typical pkg.cfg file looks like:
Code: Select all
Enabled 1
Name things
Maintainer Yukiko
Email hopelives@outlook.com
Version 1.0
The second line is of course the name of the package. Curiously this does not have to be the same as the directory in which the package is located. I could create a directory named "stuff" that contains the "things" package but it's customary to give the directory the same name as the package to avoid confusion.
The next line is obvious. The maintainer of the package. This usually is the creator but not always. Some older packages that have been released and abandoned but then have been used and undergone major modifications and upgrades would have a new maintainer. You should always give attribution to the original creator in the comments section of the scripts. It's not necessarily a requirement but it is good programming etiquette.
The next line is obvious. It's the eMail address of the maintainer and the last line is the version number of the package.
So let's create a package for the healing ank. Open the \pol\pkg\items directory and create a folder there and name it "healingank" (without the quotes). Open that folder and create another folder inside that one named "config" (no quotes). Open that folder and create a file named itemdesc.cfg. Load that file in your editor. Go back to the itemdesc.cfg file you opened in \pol\config and select the two custom ank items you placed in there and cut them from that file and paste them in the new itemdesc.cfg file. Save and close the itemdesc.cfg that you had opened in \pol\config.
Switch back to the new itemdesc.cfg file in the healingank folder that you just created and let's change their Name property to something that is relevant to what they are and do. What could be more relevant than "healingank1a" and "healingank1b" (again without the quotes). Save that file but keep it open in your editor.
Now go bank to the main healingank folder and create a file named pkg.cfg there. Open it in your editor and paste the following lines in the file:
Code: Select all
Enabled 1
Name healingank
Maintainer <your name goes here>
Email <your email address goes here>
Version 1.0
You can leave the version at 1.0 because this will be version 1.0 of the healingank package.
Save the file.
Now we have a neat little package where we can add the UseScript for the ank parts.
Ok. Let's make them do what they are supposed to do. For that we need a script. Here is a simple little script that will do what we want it to do:
Code: Select all
use uo;
include ":attributes:attributes";
program heal(who, healingank)
// Get the character's hit points and compare their current HP to their maximum HP.
// If they are greater than or equal to their maximum hit points then don't do any healing
// and tell them privately they don't need to be healed using font 1 and colour 88 (blue) text.
// Then exit the script via the return statement.
if(GetHP(who) >= GetMaxHP(who))
PrintTextAbovePrivate( healingank, "You hear: You do not need healing.", who, 1, 88, 0x00 );
return;
endif
// We will be nice and grant the player up to 100 hit points of healing.
var amount := 100;
// HealDamage will only heal to their maximum hit points.
HealDamage(who, amount);
// Play a sparkly effect around the player.
PlayObjectCenteredEffect(who, FX_SPARK_EFFECT, 7, 0x10);
// Play the "Ahhh..." healing sound we have all come to know and love.
PlaySoundEffect(who, SFX_SPELL_HEAL);
// Have the ank tell them privately they have been healed this time with colour 66 (green) text.
PrintTextAbovePrivate( healingank, "You hear: You have been healed.", who, 1, 66, 0x00 );
endprogram
Go back to the itemdesc.cfg file you created for this package and enter the line Script healAnk after the Graphic line. Your itemdesc.cfg file should look like this:
Code: Select all
Item 0x20002
{
Name healingank1a
Desc Healig Ank
Graphic 0x2
UseScript healAnk
movable 0
}
Item 0x20003
{
Name healingank1b
Desc Healig Ank
Graphic 0x3
UseScript healAnk
movable 0
}
Double click on either part of the ank and see what happens. You should "hear" that you do not need healing. To test the
*speaks with a loud booming voice"
HEALING POWER
of your ank type the command .info and target yourself. Click on the button by "Stats and Vitals". Now click on the button next to "Life". A gump will open up. Backspace over the number there and type 5 and click the "Okay" button. Right-click on the main info gump to close it. Now double-click on the ank and see what happens. Check you Hit Points in your Status gump and you should be at full health.
Congratulations! You have created your first working object and you also have a new item you can add to the world.
I hope this helped you understand how items are defined in POL. There is more to come in this series.
Here is the SciTE editor I mentioned. When you download it, unzip it to your hard drive. It is a Windows program. There should be a Linux version available from SciTE website but you will want to copy the escript.properties and the SciTEGlobal.properties files from the ZIP file to your SciTE directory in Linux because those files contain syntax highlighting and eScript configuration data that allows SciTE to compile a script from within the editor.
Once you have SciTE on your machine open the Scite folder and double-click on the SciTE executable. Then choose Options from the menu. Look in the list of files for Open escript.properties and click on that. Look for the POL Root Folder section near the top of the file. In that section you will see POLROOT=C:\pol. Change that to the location of your POL installation, save and close the file. That's all you need to do to configure the version of SciTE you downloaded. If you get SciTE rom the SciTE website you need to copy the escript.properties and SciTEGlobal.properties files from the ZIP file because SciTE has loading of eScript *.src files disabled in the SciTEGlobal.properties file and the syntax highlighting in the escript.properties file provided by the website is very outdated. You will probably want to change the association of *.src, *.ini, and *.cfg files to be loaded by SciTE when you double-click on them. To do this, for each file type, right click on a file of one of the types and choose Properties from the context menu. In the properties window you will see Opens with:. Click the Change button and in the file selection window that opens locate the SciTE program and select it. Click on Apply and close that properties window. Do this for the other two file types and you are all set.
Note: When changing the Opens with setting you need to be aware that some programs may already be assigned to open that type of file. Visual Studio for example is assigned to open *.inc files. So be very certain you want to reassign SciTE to open these files when you double-click them. If you are unsure then DON'T change the Open as setting. You can always open the files from within SciTE using the File menu.
One last thing. To compile a script you have open in SciTE you can choose Tools --> Compile in the menu or simply press <control> F7. Oh and keep in mind that *.inc files do not compile. I can't count the number of times I have been editing an include (inc) file and forgot it was an include file and become frustrated when SciTE refused to compile it. I think it happened again just last week in fact.
When compiling a script (*.src) SciTE saves the file before attempting to compile it. If you have any include files that a script you are editing needs to access don't forget to save any changes you have made to the include files before compiling your script. I've forgotten to do that too.
I hope SciTE serves you well. I have been using it a long time and, though its settings are a bit quirky, I like it.