Introduction to Pawn Scripting in SA-MP
SA-MP (San Andreas Multiplayer) uses the Pawn scripting language to define everything that happens on your server — from player commands to game events and automated systems. If you've never written a line of code before, don't worry. Pawn is beginner-friendly, and this guide will take you from zero to your first working script.
Setting Up Your Development Environment
Before writing any code, you need the right tools installed on your machine:
- SA-MP Server Package — Download the server files from the official SA-MP website.
- Pawno IDE — Included in the SA-MP server package. It's a lightweight editor with syntax highlighting.
- SA-MP Include Files — These are
.incfiles that define all SA-MP functions. They come bundled with Pawno.
Once installed, navigate to the /pawno/ folder inside your server directory and open pawno.exe.
Understanding the Basic Script Structure
Every SA-MP gamemode script follows a consistent structure. Here's what a minimal, valid script looks like:
#include <a_samp>
public OnGameModeInit()
{
print("My First Script Loaded!");
return 1;
}
public OnGameModeExit()
{
return 1;
}
Let's break this down:
- #include <a_samp> — Imports all core SA-MP functions and constants.
- OnGameModeInit() — Called once when the server starts. Ideal for setup logic.
- OnGameModeExit() — Called when the server shuts down. Use it for cleanup.
- return 1 — Most SA-MP callbacks require you to return a value. Returning 1 signals success.
Creating Your First Player Command
Commands are how players interact with your server. The most common way to handle them is via OnPlayerCommandText:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/hello", true) == 0)
{
SendClientMessage(playerid, 0xFFFF00FF, "Hello, welcome to the server!");
return 1;
}
return 0;
}
When a player types /hello, they'll see a yellow message welcoming them. The strcmp function compares the command text, and the hex value 0xFFFF00FF defines the message colour (RGBA format).
Compiling and Testing Your Script
Once your script is written:
- Save the file in the
/gamemodes/folder with a.pwnextension. - Click Compile in Pawno (or press F5). Fix any errors shown in the output panel.
- Edit
server.cfgto setgamemode0 yourscriptname 1. - Start the server and connect via SA-MP to test your command.
Common Beginner Mistakes to Avoid
- Forgetting semicolons at the end of statements.
- Mismatching curly braces
{ }. - Using
==for assignment instead of=. - Not returning a value from callbacks.
Next Steps
Once you're comfortable with the basics, explore topics like variables, loops, arrays, and timers. The SA-MP community wiki and forums are excellent resources for advancing your skills. Happy scripting!