Hey guys,
This is my first of tutorials, just an explanation of the language syntax followed by a "Hello World!"
- SourceMod plugins are compiled SourcePawn scripts. I actually created and somewhat actively support Superhero: Source and War3Source, which are both SourceMod plugins. The plugins are loaded with a SourceMM plugin called SourceMod. SourceMod provides native functions as well as an extensive extension interface. To compile a SourcePawn script:
Windows: Open command prompt, press Start->Run and type "cmd" without quotes and press enter.
cd C:/path/to/scripting/directory/
spcomp.exe spscript.sp
Linux: Open terminal.
cd /home/user/path/to/scripting/directory/
./spcomp spscript.sp
Please reference the following sites for more information: http://sourcemod.com/ - http://sourcemm.net/
Please be logical before asking questions about these instructions.
- SourcePawn is a typeless 32-bit language. There are only a small amount of datatypes, which can be an advantage. Get to know Handle, Cell, String (BYTE), Float, and bool. Please watch for a future tutorial for a further explanation on these types and their abilities.
- The Source Engine can be manipulated in various ways. For example, events are fired throughout gameplay. For example, if you were designing a plugin for logging statistics, you could listen on the event player_death to track the circumstances of the death. This will be touched on more in the event tutorial that I will one day right.
- How do I write a SourcePawn script? What programs do I need?
You don't need anything other than an operational Source Dedicated Server and a text editor. For advanced development, you can reference an extension tutorial to expand SourceMod with additional C++ interfaces. I probably won't write a tutorial on this any time soon unless there is a significant amount of interest. ( This can be expressed via the positive karma I will receive in comment form )
As noted before, you need a text editor. You may experience issues if you aren't working with the UTF-8 format. I wouldn't worry much, I, however, personally recommend either Notepad++ or PSPad. I am not certain that either of these will run in Linux, but give it a shot.
- Lets do this! What's next?
What would a rookie tutorial be without a "Hello World!"?
Open up the text editor of your choice and create the following file called helloworld.sp in the scripting directory:
#include <sourcemod> // This line tells the compiler (spcomp) to include all of the scripting inside of sourcemod.inc in the includes folder
// This line is a comment, as you can see from above this is denoted with a "//" preceding text that should be ignored by the compiler.
public OnPluginStart()
{
// In a string, which is a series of letters, the character '\' is treated as something called an escape character.
// The symbol that precedes the '\' denotes the type of escape sequence. When typing '\n' the compiler will see: Create new line. This is similar to the BR tag in HTML.
// Notice that the PrintToServer function AUTOMATICALLY adds an '\n' at the end of your input string, there is no need for one at the end.
PrintToServer("Hello world! \n Anthony is so nice, he wrote this crazy wicked tutorial for SourceMod plugins!");
}
Was that so hard? See the beginning of this tutorial and compile this bad boy. Drag the output file (helloworld.smx) into the plugins directory, located inside the sourcemod directory.
Restart your server and you will see this wonderful tutorial make you smile
Please ask questions or make comments within this thread. If your issue is SourceMod specific, but unrelated to this thread, feel free to create a thread in the correct sub-forum. Personal Messages are typically ignored unless they are just that... "personal."
I'm done. Enjoy.