[Tutorial] Coding Sourcemod the Eclipse Way

This tutorial was found on http://uboo.tv/showthread.php?p=13262. I happened upon it when I did a search on google for using Sourcepawn inside of eclipse. Unfortunately the website was experiencing a 404 when I attempted to visit it, so I ripped everything from the cached google page and decided to host it off of Silicate Illusion to ensure that the thread continues to live on. All credit for this article goes to MacNetron.ps for sharing his insight into programming Sourcemod Plugins through Eclipse.

I have located what appears to be the original thread here http://playstuff.net/showthread.php?p=13262. Again, all credits for this tutorial goes to Macnetron.PS.

Note: I have made some changes to this article to reflect the version of eclipse I’m running at this time (3.4 Ganymede). Although there will be some differences, the concept is the same. I will usually note down the differences between the original article and what I have done to get this to work.

Although Sourcemod code is fairly simple and you really can code it with just your favorite editor in c/c++ mode for syntax highlighting and compile it commandline, it is far more geeky to do it in Eclipse.

Main advantages for me are:
– I know Eclipse very well (Java ftw!)
– I can run external commands easy and capture the output
– code repository integration

Download the latest Eclipse IDE for C/C++ Developers. If you already have a copy of eclipse, you can easily obtain the CDT by going to the Help > Software Update section of eclipse, and installing the CDT Through your versions update site.

Extract it and start it by just running eclipse.exe. I do advise creating a shortcut with the version number and the flavor of eclipse (ie. ” Eclipse 3.5 CPP”). Believe it or not, I’ve got 4 different Eclipses.

For workspace, similar advice. In my case: “D:\workspace-3.5-cpp”. You really don’t want to have different Eclipses share the same workspace as your layout and plugins are saved in your workspace. Different versions may break your workspace!

Get rid of the welcome screen and create a new project in the left part (Project Explorer):

new project

A wizard will show up. Choose General – Project:

new project wizard

And give the project a nice name. Eclipse will automatically create the project in your workspace:

new project wizard

Now, I add my current EmptyServerMapChange source code. Just drag ‘n drop the file, or copy/paste.

add sp file to project

As you might be able to see, the icon on the .sp is an EditPlus one. Clicking it will open the file in EditPlus. Lets change it to Eclipse and associate it with the C/C++ editor.
Open the Preferences by Window -> Preferences and navigate to General -> Editors -> File associations.
Add the file type *.sp and add C/C++ as Associated editor:

edit .sp file assocation.

That is better!

Correctly associated file.

Now we can code in Eclipse, but still need to compile the code command line. Of course we add the sourcepawn compiler as an external tool so we can run that tool from Eclipse and compile the code:

Add External tool

Click the button to add a new launch configuration and fill in the name of the script, location of the sourcepawn compiler, working directory is our project location (is a variable) and the argument given to the commandline is our selected resource (also variable):

Note: For my copy of Ganymede I had to use “${resource_loc}” with the quotes since my command was different and my directory containing the source files contained spaces.

external tool wizard

On tab Refresh, make sure the refresh is enabled and on project containing the selected resource. This makes sure you don’t have to hit the refresh button but the .smx will show up immediately:

external tools wizard

Last on tab Common, enable the display of this task:

external tools wizard

Now reap the fruits of our hard labor. Select the .sp and run the tool:

Working external tool