Difference between revisions of "Compiling SourceMod Plugins"

From AlliedModders Wiki
Jump to: navigation, search
(Recommend Spider before the web compiler)
 
(12 intermediate revisions by 10 users not shown)
Line 1: Line 1:
#include <sourcemod>
+
Okay, so you've read the [[Introduction to SourcePawn]] and [[Introduction to SourceMod Plugins]] and now you want to actually compile a plugin.
#include <sdktools>
+
 
+
The simplest way to compile a plugin that doesn't rely on any custom include files is using [https://spider.limetech.io/ Spider] or [http://www.sourcemod.net/compiler.php the web compiler].
public Plugin:myinfo =
+
 
{
+
Alternatively, you can use the executable compiler distributed with SourceMod. You can use this simply if you like compiling locally rather than using the web compiler. You have to use the local compiler if your plugin relies on custom include files. The compiler is included in the sourcemod/scripting/ folder of the [http://www.sourcemod.net/downloads.php SourceMod distribution].
name = "My First Plugin",
+
 
author = "Me",
+
Windows: open up a command prompt (Start->Run or WindowsKey+R, then "cmd"):
description = "My first plugin ever"
+
cd <sourcemod>\scripting
version = "1.0.0.0",
+
  spcomp myplugin.sp
url = "http://www.sourcemod.net/"
+
[http://www.computerhope.com/cdhlp.htm cd command reference]
}
+
 
+
Alternatively, you can simply drag the .sp file on top of spcomp.exe, which will compile the plugin for you.
public OnPluginStart()
+
 
{
+
Linux: Depending on your Linux flavour you need to install the libc6 and libstdc++6 32bit libraries before you start to compile
RegAdminCmd("sm_myslap", Command_MySlap, ADMFLAG_SLAY)
+
 
}
+
Example for Ubuntu:
   
+
  apt-get install libc6:i386 lib32stdc++6
public Action:Command_MySlap(client, args)
+
 
{
+
Then use:
new String:arg1[32], String:arg2[32]
+
  ./compile.sh myplugin.sp
new damage
+
 
+
Now simply move the .smx (not .sp) file from sourcemod/scripting/compiled/ to the sourcemod/plugins/ folder.
/* Get the first argument */
+
 
GetCmdArg(1, arg1, sizeof(arg1))
+
'''Note:''' When compiling preexisting plugins it is easiest to move the included from the plugin source folder to the include folder in your sourcemod/scripting/include. Please see [[Spcomp_switches]] specifically the ''-i'' parameter for specifying a different folder for includes.
+
 
/* If there are 2 or more arguments, and the second argument fetch
+
[http://forums.alliedmods.net/showthread.php?t=52664 Reference Source]
* is successful, convert it to an integer.
+
 
*/
+
See Also: [http://forums.alliedmods.net/forumdisplay.php?f=107 Scripting Forum]
if (args >= 2 && GetCmdArg(2, arg2, sizeof(arg2)))
 
{
 
damage = StringToInt(arg2)
 
}
 
   
 
/* Try and find a matching player */
 
new target = FindTarget(client, arg1)
 
if (target == -1)
 
{
 
/* FindTarget() automatically replies with the  
 
* failure reason.
 
*/
 
return Plugin_Handled;
 
}
 
 
SlapPlayer(target, damage)
 
 
new String:name[MAX_NAME_LENGTH]
 
 
GetClientName(target, name, sizeof(name))
 
ReplyToCommand(client, "[SM] You slapped %s for %d damage!", name, damage)
 
 
return Plugin_Handled;
 
}000
 

Latest revision as of 10:27, 25 November 2023

Okay, so you've read the Introduction to SourcePawn and Introduction to SourceMod Plugins and now you want to actually compile a plugin.

The simplest way to compile a plugin that doesn't rely on any custom include files is using Spider or the web compiler.

Alternatively, you can use the executable compiler distributed with SourceMod. You can use this simply if you like compiling locally rather than using the web compiler. You have to use the local compiler if your plugin relies on custom include files. The compiler is included in the sourcemod/scripting/ folder of the SourceMod distribution.

Windows: open up a command prompt (Start->Run or WindowsKey+R, then "cmd"):

cd <sourcemod>\scripting
spcomp myplugin.sp

cd command reference

Alternatively, you can simply drag the .sp file on top of spcomp.exe, which will compile the plugin for you.

Linux: Depending on your Linux flavour you need to install the libc6 and libstdc++6 32bit libraries before you start to compile

Example for Ubuntu:

 apt-get install libc6:i386 lib32stdc++6

Then use:

./compile.sh myplugin.sp

Now simply move the .smx (not .sp) file from sourcemod/scripting/compiled/ to the sourcemod/plugins/ folder.

Note: When compiling preexisting plugins it is easiest to move the included from the plugin source folder to the include folder in your sourcemod/scripting/include. Please see Spcomp_switches specifically the -i parameter for specifying a different folder for includes.

Reference Source

See Also: Scripting Forum