Setting up your PAWN environment

If you want to write cool gamemodes, your work environment should be as comfortable as possible. I'll share my standard setup, suitable for work with multiple separate projects. This guide is specific for windows, but if you are running linux distro as your main OS, I guess you can handle that yourself.

Update: It seems that I was wrong about windows symlinks, they aren't that terrible! Substitute every instance of "hard link" in this tutorial to "symlink". The link shell extension provides option to do that as well, and your links can now survive source updates.

List of contents

  1. Toolkit
  2. Folder layout
  3. Dependencies
  4. Editor
  5. Starting a new project

Toolkit

  1. Link shell extension - unfortunately windows doesn't support symlinks as nicely as unix, and vagrant/docker is overkill for our purposes. We'll share most libraries across projects, and we won't have to worry about updating pawn libraries one by one.
  2. Sublime text 3 - we'll go in-depth about that one later. It's free, but will nag you every now and then about buying it.
  3. Git for windows - windows latest version is 1.9.5, 2 isn't ported yet as it requires a lot of hacks around POSIX libraries. Maybe one day...
  4. (optional) Virtualbox + CentOS x32 - most servers are working on CentOS, so we have to make sure that our server won't crash for some random reason. This one is optional though, you can go rough.

Once you gather all required elements, let's start...

Folder layout

Being organised is a very important trait to have if you want to be a good developer. This is the most basic setup you can get.

- Your root workbench folder
-- Template
-- Resources
-- Example project

Resources folder will serve as a hub for keeping all PAWN libraries, and samp related things. Template will serve as a base for each new project.

Dependencies

First, fetch yourself samp server for windows. Save and extract it into your Resources folder. After doing that, select samp-server.exe, samp-npc.exe, announce.exe and server.cfg, then right-click and select "Use as link source". Enter your Template folder, right-click then select Create link => Clone hard link. Voila, now anytime you update your samp-server in Resources, the one in Template will be uploaded as well.

We need some directory initial directory structure. In Template create pawno folder with include subfolder. Also create standard folders: gamemodes, filterscripts, scriptfiles, and plugins.

Go back to your server folder, enter pawno/include, select all files, and use them as a link source as we did with samp-server.exe. Then go into Template/pawno/include and create hard link of all includes here.

We could use standard compiler, but we won't as it has a whole bunch of known problems. Download latest pawncc release for windows (don't download pawndisasm, as we don't need it). Select all files in the folder as a link source, and hard link them in your Template/pawno.

Your compiler is ready for work!

Editor

You've probably already met PAWNO, the editor bundled with samp server. For beginners it's sufficient tool, but if you want to step up your game - you have to step up your editor as well. Introducing - sublime text 3. It's lightning fast, has great community base, and is my go-to multitool. This is not an editor course, but I can highly recommend this tutsplus.com article. It made me realise how much my previous editor sucked (in fact I used two, heavy IDE for webdevelopment, notepad++ for everything else). Of course, sublime is my personal preference, there are hundreds of awesome tools available - Atom for example.

You already should've installed it. We need to set it up for our PAWN development. Download this Southclaw pawn package. In sublime menu select Preferences => Browse packages. Open User folder, and paste there the package (preferable in a folder, so you won't be confused with what is what).

Now download my default build system, and paste it into your User folder as well.

Well done, now your environment is awesome!

Starting a new project

Finally! All that setup will be reusable for each new project. How to start a new one?

  1. git bash should be available in your start menu, fire it up.
  2. Navigate to your root folder (for me it would be cd /d/Workbench), and type: git init <name of your project> - keep the name short, as it will be the name of the project folder, for example git init Foobar. Don't close the console.
  3. Copy all contents of Template folder, and paste them into project folder. If you're wondering why we won't use hard links here, it's because sometimes updates will result in BC break. If you want bleeding-edge updates, hard link is the way to go, except server.cfg file.
  4. In sublime text open new window. Select Project -> Save project as..., and save it in your new project folder. Then click Project -> Add Folder to project and select your project folder again. Now you should have all files in left-side menu.
  5. Again in sublime, right-click top level folder, and select New file. Immediately save is as .gitignore. It's contents should be as follows:

    *
    !*/
    !.gitignore
    !filterscripts/**/*
    !gamemodes/**/*
    *.amx
    
  6. Create main pwn file. Assuming your project name is HWRP, create a file named gamemodes/HWRP.pwn which will be your main pwn file.
  7. Dump some initial content into it:

    #include <a_samp>
    main() {
        print("It seems everything works!");
    }
    
  8. Press f5 - if you've done everything correctly, your amx should be ready!
  9. I hope you didn't close your git bash, because it's gonna be important now. Navigate into your project's main folder, and execute git add .gitignore gamemodes/<project name>.pwn, then git commit -m "It seems I made a gamemode". Voila, you now entered the big league of tracking changes in your files. I'll explain what git does some other time.

Conclusion

That was a long process, but now your projects are not few scattered around HDD files, but properly managed, revisioned and structured files. If you stick around with my blog, you'll learn both PAWN and sublime text tricks, YSI library usage, and maybe we'll write some simple gamemode.

Thanks for reading!