|
| 1 | +A guide on how to compile [SourceMod](https://www.sourcemod.net/about.php) plugins. |
| 2 | + |
| 3 | +SourceMod plugins are custom scripts or addons created to enhance and modify the functionality of game servers that run on the Source engine. |
| 4 | + |
| 5 | +The programming language associated with SourceMod plugin's source code is [SourcePawn](https://github.com/alliedmodders/sourcepawn). The file extension for SourcePawn is `sp`. |
| 6 | + |
| 7 | +Compiling SourceMod plugins is quite easy and will be explained below. |
| 8 | + |
| 9 | +## Table Of Contents |
| 10 | + |
| 11 | +## Downloading SourceMod |
| 12 | +Refer to the following guide on how to download and extract SourceMod. You do **not** need to install SourceMod onto your server to build plugins. |
| 13 | + |
| 14 | +https://forum.moddingcommunity.com/t/how-to-install-update-metamod-sourcemod/60 |
| 15 | + |
| 16 | +After extracting the SourceMod files, go to the `addons/sourcemod/scripting` directory on Linux (or `addons\sourcemod\scripting` folder on Windows). |
| 17 | + |
| 18 | +## Building SourceMod Plugins |
| 19 | +Building SourceMod plugins is usually quite easy, especially on Windows. |
| 20 | +### Windows |
| 21 | +#### Windows File Explorer |
| 22 | +If you want to quickly compile plugins, you can drag and drop the plugin's source code file into the `compile.exe` executable located in the `scripting` folder. A Command Prompt window will open and you'll see the output of the build. If the build was successful, you'll see the built plugins inside of the `compiled` folder. Built SourceMod plugins typically have the `smx` file extension. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +While this method is quick and easy, the command line method explained below includes **more options** you can set. |
| 27 | + |
| 28 | +#### Command Line |
| 29 | +If you want to compile plugins using through the command line using Command Prompt or PowerShell, you will first need to launch a terminal and change to the scripting folder. |
| 30 | + |
| 31 | +Next, you'll want to use the `spcomp.exe` or `spcomp64.exe` (for 64-bit support) executables to compile the plugins. |
| 32 | + |
| 33 | +Here is a basic command that compiles a plugin. |
| 34 | + |
| 35 | +```powershell |
| 36 | +.\spcomp.exe <Plugin File Name With Extension> |
| 37 | +``` |
| 38 | + |
| 39 | +For example, if we want to compile the included `basechat` plugin, we'd use the following command. |
| 40 | + |
| 41 | +```powershell |
| 42 | +.\spcomp.exe basechat.sp |
| 43 | +``` |
| 44 | + |
| 45 | +## Linux |
| 46 | +To compile SourceMod plugins through a Linux terminal, you may use a similar process to the command line method on Windows explained above. You will need to either use the `spcomp` or `spcomp64` (for 64-bit support) executables to compile the plugins. |
| 47 | + |
| 48 | +Here is a basic command that compiles a plugin. |
| 49 | + |
| 50 | +```bash |
| 51 | +./spcomp <Plugin File Name With Extension> |
| 52 | +``` |
| 53 | + |
| 54 | +For example, if we want to compile the included `basechat` plugin, we'd use the following command. |
| 55 | + |
| 56 | +```bash |
| 57 | +./spcomp basechat.sp |
| 58 | +``` |
| 59 | + |
| 60 | +If the build was successful, you'll see the new built plugin file in the same directory as the source code (`scripting/`). |
| 61 | + |
| 62 | +## Additional CLI Options |
| 63 | +As stated above, compiling plugins through the command line allows you to set additional options. Here is the help menu output which provides a list of flags and arguments you may set. |
| 64 | + |
| 65 | +``` |
| 66 | +SourcePawn Compiler 1.11.0.6969 |
| 67 | +Copyright (c) 1997-2006 ITB CompuPhase |
| 68 | +Copyright (c) 2004-2021 AlliedModders LLC |
| 69 | +
|
| 70 | +Usage: ./spcomp [options] <filename> [filename...] |
| 71 | +
|
| 72 | +optional arguments: |
| 73 | + --show-stats Show compiler statistics on exit. |
| 74 | + -D Active directory path |
| 75 | + --active-dir=ACTIVE_DIR |
| 76 | + -e Error file path |
| 77 | + --error-file=ERROR_FILE |
| 78 | + -E, --warnings-as-errors Treat warnings as errors |
| 79 | + -h, --show-includes Show included file paths |
| 80 | + -z |
| 81 | + --compress-level=COMPRESS_LEVEL |
| 82 | + Compression level, default 9 (0=none, 1=worst, |
| 83 | + 9=best) |
| 84 | + -t, --tabsize=TABSIZE TAB indent size (in character positions, |
| 85 | + default=8) |
| 86 | + -v, --verbose=VERBOSE Verbosity level; 0=quiet, 1=normal, 2=verbose |
| 87 | + -p, --prefix=PREFIX Set name of "prefix" file |
| 88 | + -o, --output=OUTPUT Set base name of (P-code) output file |
| 89 | + -O, --opt-level=OPT_LEVEL |
| 90 | + Deprecated; has no effect |
| 91 | + -i, --include=INCLUDE Path for include files |
| 92 | + -w, --warning=WARNING Disable a specific warning by its number. |
| 93 | + -;, --require-semicolons Require a semicolon to end each statement. |
| 94 | + --syntax-only Perform a dry-run (No file output) on the input |
| 95 | + --use-stderr Use stderr instead of stdout for error messages. |
| 96 | + --no-verify Disable opcode verification (for debugging). |
| 97 | + sym=val Define constant "sym" with value "val". |
| 98 | + sym= Define constant "sym" with value 0. |
| 99 | +``` |
| 100 | + |
| 101 | +For example, on Linux, if want the successfully built `basechat` plugin to go inside the `compiled/` directory, we'd use the following command(s). |
| 102 | + |
| 103 | +```bash |
| 104 | +# Make sure compiled directory is made. |
| 105 | +mkdir -p compiled |
| 106 | + |
| 107 | +# Output: compiled/basechat.smx |
| 108 | +./spcomp -o compiled/basechat |
| 109 | +``` |
| 110 | + |
| 111 | +## Include Files |
| 112 | +There are many published SourceMod plugins that contain include files with the `inc` file extension. These files need to go into the `include/` directory/folder. Otherwise, the plugins will likely fail to compile. |
| 113 | + |
| 114 | +Additionally, you can use the `-i` flag when compiling through the command line to include directories and folders outside of the default `include` directory and folder. |
| 115 | + |
| 116 | +## Conclusion |
| 117 | +That's all! You should now know how all methods on **compiling** SourceMod plugins. |
| 118 | + |
| 119 | +If you have any questions or have feedback, please reply to this topic! |
0 commit comments