<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alliedmods.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matthias+Vance</id>
	<title>AlliedModders Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alliedmods.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matthias+Vance"/>
	<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/Special:Contributions/Matthias_Vance"/>
	<updated>2026-05-26T00:46:46Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.6</generator>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Supported_Games_(Metamod:Source)&amp;diff=7802</id>
		<title>Supported Games (Metamod:Source)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Supported_Games_(Metamod:Source)&amp;diff=7802"/>
		<updated>2010-08-22T10:53:31Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Metamod:Source]] generally tries to support all Source engine based games. However, some API features may only be supported by some games. This does not mean these features will not work on games not listed here, but that games listed here are specifically known and tested to work.&lt;br /&gt;
&lt;br /&gt;
*'''[[Introduction to SourceMM Coding#User_Message_Enumeration|User Message API Functions]]''' - &amp;lt;tt&amp;gt;GetUserMessageCount()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;FindUserMessage()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;GetUserMessage()&amp;lt;/tt&amp;gt;&lt;br /&gt;
**Battle Grounds 2&lt;br /&gt;
**Counter-Strike: Source&lt;br /&gt;
**Day of Defeat: Source&lt;br /&gt;
**Dystopia&lt;br /&gt;
**Garry's Mod 10&lt;br /&gt;
**Goldeneye: Source&lt;br /&gt;
**Half-Life 2: Capture the Flag&lt;br /&gt;
**Half-Life 2: Deathmatch&lt;br /&gt;
**The Hidden: Source&lt;br /&gt;
**Insects Infestation&lt;br /&gt;
**Jailbreak!&lt;br /&gt;
**Kreedz Climbing&lt;br /&gt;
**Pirates, Vikings, and Knights II&lt;br /&gt;
**Team Fortress 2&lt;br /&gt;
**The Ship&lt;br /&gt;
**SourceForts&lt;br /&gt;
**Zombie Master&lt;br /&gt;
**Dark Messiah&lt;br /&gt;
**Left 4 Dead&lt;br /&gt;
**Left 4 Dead 2&lt;br /&gt;
&lt;br /&gt;
[[Category:Metamod:Source Documentation]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Introduction_to_SourcePawn_(legacy_syntax)&amp;diff=7798</id>
		<title>Introduction to SourcePawn (legacy syntax)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Introduction_to_SourcePawn_(legacy_syntax)&amp;diff=7798"/>
		<updated>2010-08-19T09:30:55Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: /* Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This guide is designed to give you a very basic overview to fundamentals of scripting in SourcePawn.  [[Pawn]] is a &amp;quot;scripting&amp;quot; language used to embed functionality in other programs.  That means it is not a standalone language, like C++ or Java, and its details will differ based on the application.  SourcePawn is the version of Pawn used in [[SourceMod]].&lt;br /&gt;
&lt;br /&gt;
This guide does not tell you how to write SourceMod plugins; it is intended as an overview of the syntax and semantics of the language instead.  Read the separate article, [[Introduction to SourceMod Plugins]] for SourceMod API specifics.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Non-Programmer Intro=&lt;br /&gt;
This section is intended for non-programmers.  If you're still confused, you may want to pick up a book on another language, such as PHP, Python, or Java, to get a better idea of what programming is like.&lt;br /&gt;
&lt;br /&gt;
==Symbols/Keywords==&lt;br /&gt;
A symbol is a series of letters, numbers, and/or underscores, that uniquely represents something.  Symbols are case-sensitive (unlike PHP, where sometimes they are not).  Symbols do not start with any special character, though they must start with a letter.  &lt;br /&gt;
&lt;br /&gt;
There are a few reserved symbols that have special meaning.  For example, &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;return&amp;lt;/tt&amp;gt; are special constructs in the language that will explained later.  They cannot be used as symbol names.&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
There a few important constructs you should know before you begin to script.  The first is a '''variable'''.  A variable is a symbol, or name, that holds data. For example, the variable &amp;quot;a&amp;quot; could hold the number &amp;quot;2&amp;quot;, &amp;quot;16&amp;quot;, &amp;quot;0&amp;quot;, et cetera.  Variables are created for storage space throughout a program.  Variables must be declared before being used, using the &amp;quot;new&amp;quot; keyword.  Data is assigned to variables using the equal sign (=).  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a, b, c, d;&lt;br /&gt;
&lt;br /&gt;
a = 5;&lt;br /&gt;
b = 16;&lt;br /&gt;
c = 0;&lt;br /&gt;
d = 500;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SourcePawn, variables have two types, which will be explained in more detail further on.&lt;br /&gt;
*Cells (arbitrary numerical data), as shown above.&lt;br /&gt;
*Strings (a series of text characters)&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
The next important concept is '''functions'''. Functions are symbols or names that perform an action.  That means when you activate them, they carry out a specific sequence of code.  There are a few types of functions, but every function is activated the same way.  &amp;quot;Calling a function&amp;quot; is the term for invoking a function's action.  Function calls are constructed like this:&lt;br /&gt;
&amp;lt;pawn&amp;gt;function(&amp;lt;parameters&amp;gt;)&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;show(56);   //Activates &amp;quot;show&amp;quot; function, and gives the number 56 to it&lt;br /&gt;
show();     //Activates &amp;quot;show&amp;quot; function with no data, blank&lt;br /&gt;
show(a);    //Activates &amp;quot;show&amp;quot; function, gives a variable's contents as data&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every piece of data passed to a function is called a '''parameter'''.  A function can have any number of parameters (there is a &amp;quot;reasonable&amp;quot; limit of 32 in SourceMod).  Parameters will be explained further in the article.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
Note any text that appears after a &amp;quot;//&amp;quot; is considered a &amp;quot;comment&amp;quot; and is not actual code.  There are two comment styles:&lt;br /&gt;
*&amp;lt;tt&amp;gt;//&amp;lt;/tt&amp;gt; - Double slash, everything following on that line is ignored.&lt;br /&gt;
*&amp;lt;tt&amp;gt;/* */&amp;lt;/tt&amp;gt; - Multi-line comment, everything in between the asterisks is ignored.  You cannot nest these.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Block Coding==&lt;br /&gt;
The next concept is block coding. You can group code into &amp;quot;blocks&amp;quot; separated by { and }. This effectively makes one large block of code act as one statement. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;{&lt;br /&gt;
   here;&lt;br /&gt;
   is;&lt;br /&gt;
   some;&lt;br /&gt;
   code;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Block coding using braces is used everywhere in programming.  Blocks of code can be nested within each other.  It is a good idea to adapt a consistent and readable indentation style early on to prevent spaghetti-looking code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Language Paradigms=&lt;br /&gt;
Pawn may seem similar to other languages, like C, but it has fundamental differences.  It is not important that you immediately understand these differences, but they may be helpful if you're familiar with another language already.&lt;br /&gt;
*'''Pawn is not typed.'''  Pawn only has one data type, the '''cell'''.  This will be explained in detail later.  [Below it says that there are two types: cell and string.]&lt;br /&gt;
*'''Pawn is not garbage collected.''' Pawn, as a language, has no built-in memory allocation, and thus has no garbage.  If a function allocates memory, you may be responsible for freeing it.&lt;br /&gt;
*'''Pawn is not object oriented.''' Pawn is procedural, and relies on subroutines.  It also does not have C structs.&lt;br /&gt;
*'''Pawn is not functional.''' Pawn is procedural, and does not support lambda functions or late binding or anything else you might find in a very high-level language, like Python or Ruby.&lt;br /&gt;
*'''Pawn is single-threaded.''' As of this writing, Pawn is not thread safe.  &lt;br /&gt;
*'''Pawn is not interpreted.''' Well, it &amp;quot;sort of&amp;quot; is.  It gets interpreted at a very low level.  You must run your code through a compiler, which produces a binary.  This binary will work on any platform that the host application uses.  This speeds up loading time and lets you check errors easier.&lt;br /&gt;
&lt;br /&gt;
These language design decisions were made by ITB CompuPhase.  It is designed for low-level embedded devices and is thus very small and very fast.&lt;br /&gt;
&lt;br /&gt;
=Variables=&lt;br /&gt;
In Pawn there are two variable types: the '''cell''' and the '''String'''.  A cell can store 32 bits of numerical data.  A String is a sequential/flat list of UTF-8 text characters.&lt;br /&gt;
&lt;br /&gt;
A '''cell''' has no inherent type, however, cells can be '''tagged'''.  A tag lets you enforce where certain cells can be used.  The default tags are:&lt;br /&gt;
*(nothing), or '''_''' - No tag.  Usually used for whole numbers ([http://en.wikipedia.org/wiki/Integer Integers]).&lt;br /&gt;
*'''Float''' - Used for floating point (fractional) numbers.&lt;br /&gt;
*'''bool''' - Used for storing either '''true''' or '''false'''.&lt;br /&gt;
&lt;br /&gt;
Strings are different and will be explained in the next sections.&lt;br /&gt;
&lt;br /&gt;
==Declaration==&lt;br /&gt;
Examples of different valid variable declarations:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5;&lt;br /&gt;
new Float:b = 5.0;&lt;br /&gt;
new bool:c = true;&lt;br /&gt;
new bool:d = 0;      //Works because 0 is false&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Invalid variable usage:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5.0;         //Tag mismatch.  5.0 is tagged as Float&lt;br /&gt;
new Float:b = 5;     //Tag mismatch.  5 is not tagged.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a variable is not assigned upon declaration, it will be set to 0.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a;        //Set to 0&lt;br /&gt;
new Float:b;  //Set to 0.0&lt;br /&gt;
new bool:c;   //Set to false&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment==&lt;br /&gt;
Variables can be re-assigned data after they are created.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a, Float:b, bool:c;&lt;br /&gt;
&lt;br /&gt;
a = 5;&lt;br /&gt;
b = 5.0;&lt;br /&gt;
c = true;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Arrays=&lt;br /&gt;
An array is a sequence of data in a sequential list.  Arrays are useful for storing multiple pieces of data in one variable, and often greatly simplify many tasks.  &lt;br /&gt;
&lt;br /&gt;
==Declaration==&lt;br /&gt;
An array is declared using brackets.  Some examples of arrays:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new players[32];     //Stores 32 cells (numbers)&lt;br /&gt;
new Float:origin[3]; //Stores 3 floating point numbers&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, arrays are initialized to 0.  You can assign them different default values, however:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[5] = {1, 2, 3, 4, 5};       //Stores 1, 2, 3, 4, 5 in the cells.&lt;br /&gt;
new Float:origin[3] = {1.0, 2.0, 3.0};  //Stores 1.0, 2.0, 3.0 in the cells.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can leave out the array size if you're going to pre-assign data to it.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[] = {1, 3, 5, 7, 9};&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The compiler will automatically deduce that you intended an array of size 5.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
Using an array is just like using a normal variable.  The only difference is the array must be '''indexed'''.  Indexing an array means choosing the element which you wish to use.&lt;br /&gt;
&lt;br /&gt;
For example, here is an example of the above code using indexes:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[5], Float:origin[3];&lt;br /&gt;
&lt;br /&gt;
numbers[0] = 1;&lt;br /&gt;
numbers[1] = 2;&lt;br /&gt;
numbers[2] = 3;&lt;br /&gt;
numbers[3] = 4;&lt;br /&gt;
numbers[4] = 5;&lt;br /&gt;
origin[0] = 1.0;&lt;br /&gt;
origin[1] = 2.0;&lt;br /&gt;
origin[2] = 3.0;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the '''index''' is what's in between the brackets.  The index always starts from 0.  That is, if an array has N elements, its valid indexes are from 0 to N-1.  Accessing the data at these indexes works like a normal variable.&lt;br /&gt;
&lt;br /&gt;
To use an incorrect index will cause an error.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[5];&lt;br /&gt;
&lt;br /&gt;
numbers[5] = 20;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may look correct, but 5 is not a valid index.  The highest valid index is 4.&lt;br /&gt;
&lt;br /&gt;
You can use any expression as an index.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a, numbers[5];&lt;br /&gt;
&lt;br /&gt;
a = 1;                   //Set a = 1&lt;br /&gt;
numbers[a] = 4;          //Set numbers[1] = 4&lt;br /&gt;
numbers[numbers[a]] = 2; //Set numbers[4] = 2&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Expressions will be discussed in depth later in the article.&lt;br /&gt;
&lt;br /&gt;
=Strings=&lt;br /&gt;
Strings are a convenient method of storing text.  The characters are stored in an array.  The string is terminated by a '''null terminator''', or a 0.  Without a null terminator, Pawn would not know where to stop reading the string.  All strings are UTF-8 in SourcePawn.&lt;br /&gt;
&lt;br /&gt;
Notice that Strings are a combination of arrays and cells.  Unlike other languages, this means you must know how much space a string will use in advance.  That is, strings are not dynamic.  They can only grow to the space you allocate for them.&lt;br /&gt;
&lt;br /&gt;
''Note for experts:  They're not actually cells.  SourcePawn uses 8-bit storage for String arrays as an optimization.  This is what makes String a type and not a tag.''&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
Strings are declared almost equivalently to arrays.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new String:message[] = &amp;quot;Hello!&amp;quot;;&lt;br /&gt;
new String:clams[6] = &amp;quot;Clams&amp;quot;;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are equivalent to doing:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new String:message[7], String:clams[6];&lt;br /&gt;
&lt;br /&gt;
message[0] = 'H';&lt;br /&gt;
message[1] = 'e';&lt;br /&gt;
message[2] = 'l';&lt;br /&gt;
message[3] = 'l';&lt;br /&gt;
message[4] = 'o';&lt;br /&gt;
message[5] = '!';&lt;br /&gt;
message[6] = 0;&lt;br /&gt;
clams[0] = 'C';&lt;br /&gt;
clams[1] = 'l';&lt;br /&gt;
clams[2] = 'a';&lt;br /&gt;
clams[3] = 'm';&lt;br /&gt;
clams[4] = 's';&lt;br /&gt;
clams[5] = 0;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although strings are rarely initialized in this manner, it is very important to remember the concept of the null terminator, which signals the end of a string.  The compiler, and most SourceMod functions will automatically null-terminate for you, so it is mainly important when manipulating strings directly.&lt;br /&gt;
&lt;br /&gt;
Note that a string is enclosed in double-quotes, but a character is enclosed in single quotes.&lt;br /&gt;
&lt;br /&gt;
==Characters==&lt;br /&gt;
A character of text can be used in either a String or a cell.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new String:text[] = &amp;quot;Crab&amp;quot;;&lt;br /&gt;
new clam;&lt;br /&gt;
&lt;br /&gt;
clam = 'D';         //Set clam to 'D'&lt;br /&gt;
text[0] = 'A';      //Change the 'C' to 'A', it is now 'Arab'&lt;br /&gt;
clam = text[0];     //Set clam to 'A'&lt;br /&gt;
text[1] = clam;     //Change the 'r' to 'A', is is now 'AAab'&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What you can't do is mix character arrays with strings.  The internal storage is different.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new clams[] = &amp;quot;Clams&amp;quot;;                       //Invalid, needs String: type&lt;br /&gt;
new clams[] = {'C', 'l', 'a', 'm', 's', 0};  //Valid, but NOT A STRING.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Functions=&lt;br /&gt;
Functions, as stated before, are isolated blocks of code that perform an action.  They can be invoked, or '''called''', with '''parameters''' that give specific options.&lt;br /&gt;
&lt;br /&gt;
There are two types of ways functions are called:&lt;br /&gt;
*'''direct call''' - You specifically call a function in your code.&lt;br /&gt;
*'''callback''' - The application calls a function in your code, as if it were an event trigger.&lt;br /&gt;
&lt;br /&gt;
There are six types of functions:&lt;br /&gt;
*'''native''': A direct, internal function provided by the application.&lt;br /&gt;
*'''public''': A callback function that is visible to the application and other scripts.&lt;br /&gt;
*'''normal''': A normal function that only you can call.&lt;br /&gt;
*'''static''': The scope of this function is restricted to the current file, can be used in combination with stock.&lt;br /&gt;
*'''stock''': A normal function provided by an include file.  If unused, it won't be compiled.&lt;br /&gt;
*'''forward''': This function is a global event provided by the application.  If you implement it, it will be a callback.&lt;br /&gt;
&lt;br /&gt;
All code in Pawn must exist in functions.  This is in contrast to languages like PHP, Perl, and Python which let you write global code.  That is because Pawn is a callback-based language: it responds to actions from a parent application, and functions must be written to handle those actions.  Although our examples often contain free-floating code, this is purely for demonstration purposes.  Free-floating code in our examples implies the code is part of some function.&lt;br /&gt;
&lt;br /&gt;
==Declaration==&lt;br /&gt;
Unlike variables, functions do not need to be declared before you use them.  Functions have two pieces, the '''prototype''' and the '''body'''.  The prototype contains the name of your function and the parameters it will accept.  The body is the contents of its code.&lt;br /&gt;
&lt;br /&gt;
Example of a function:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
AddTwoNumbers(first, second)&lt;br /&gt;
{&lt;br /&gt;
  new sum = first + second;&lt;br /&gt;
&lt;br /&gt;
  return sum;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a simple function.  The prototype is this line:&lt;br /&gt;
&amp;lt;pawn&amp;gt;AddTwoNumbers(first, second)&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Broken down, it means:&lt;br /&gt;
*&amp;lt;tt&amp;gt;AddTwoNumbers&amp;lt;/tt&amp;gt; - Name of the function.&lt;br /&gt;
*&amp;lt;tt&amp;gt;first&amp;lt;/tt&amp;gt; - Name of the first parameter, which is a simple cell.&lt;br /&gt;
*&amp;lt;tt&amp;gt;second&amp;lt;/tt&amp;gt; - Name of the second parameter, which is a simple cell.&lt;br /&gt;
&lt;br /&gt;
The body is a simple block of code.  It creates a new variable, called &amp;lt;tt&amp;gt;sum&amp;lt;/tt&amp;gt;, and assigns it the value of the two parameters added together (more on expressions later).  The important thing to notice is the &amp;lt;tt&amp;gt;return&amp;lt;/tt&amp;gt; statement, which tells the function to end and return a value to the caller of the function.  All functions ''return a cell'' upon completion.  That means, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;new sum = AddTwoNumbers(4, 5);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code will assign the number 9 to sum.  The function adds the two inputs, and the sum is given as the '''return value'''.  If a function has no return statement or does not place a value in the return statement, it returns 0 by default.&lt;br /&gt;
&lt;br /&gt;
A function can accept any type of input.  It can return any cell, but not arrays or strings.  Example:  &lt;br /&gt;
&amp;lt;pawn&amp;gt;Float:AddTwoFloats(Float:a, Float:b)&lt;br /&gt;
{&lt;br /&gt;
   new Float:sum = a + b;&lt;br /&gt;
 &lt;br /&gt;
   return sum;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Note that if in the above function, you returned a non-Float, you would get a tag mismatch.''&lt;br /&gt;
&lt;br /&gt;
You can, of course, pass variables to functions:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new numbers[3] = {1, 2, 0};&lt;br /&gt;
&lt;br /&gt;
numbers[2] = AddTwoNumbers(numbers[0], numbers[1]);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that cells are passed '''by value'''.  That is, their value cannot be changed by the function.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
&lt;br /&gt;
ChangeValue(a);&lt;br /&gt;
&lt;br /&gt;
ChangeValue(b)&lt;br /&gt;
{&lt;br /&gt;
   b = 5;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code would not change the value of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;.  That is because a copy of the value in &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; is passed instead of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; itself.  &lt;br /&gt;
&lt;br /&gt;
More examples of functions will be provided throughout the article.&lt;br /&gt;
&lt;br /&gt;
==Publics==&lt;br /&gt;
Public functions are used to implement callbacks.  You should not create a public function unless it is specifically implementing a callback.  For example, here are two callbacks from &amp;lt;tt&amp;gt;sourcemod.inc&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;forward OnPluginStart();&lt;br /&gt;
forward OnClientDisconnected(client);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To implement and receive these two events, you would write functions as such:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;public OnPluginStart()&lt;br /&gt;
{&lt;br /&gt;
   /* Code here */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public OnClientDisconnected(client)&lt;br /&gt;
{&lt;br /&gt;
   /* Code here */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''public''' keyword exposes the function publicly, and allows the parent application to directly call the function.&lt;br /&gt;
&lt;br /&gt;
==Natives==&lt;br /&gt;
Natives are builtin functions provided by SourceMod.  You can call them as if they were a normal function.  For example, SourceMod has the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;native FloatRound(Float:num);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be called like so:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new num = FloatRound(5.2);     //Results in num = 5&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Array Parameters==&lt;br /&gt;
You can pass arrays or Strings as parameters.  It is important to note that these are passed '''by reference'''.  That is, rather than making a copy of the data, the data is referenced directly.  There is a simple way of explaining this more concretely.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new example[] = {1, 2, 3, 4, 5};&lt;br /&gt;
&lt;br /&gt;
ChangeArray(example, 2, 29);&lt;br /&gt;
&lt;br /&gt;
ChangeArray(array[], index, value)&lt;br /&gt;
{&lt;br /&gt;
   array[index] = value;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function sets the given index in the array to a given value.  When it is run on our example array, it changes index 2 to from the value 3 to 29.  I.e.:&lt;br /&gt;
&amp;lt;pawn&amp;gt;example[2] = 29;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is only possible because the array can be directly modified.  To prevent an array from being modified, you can mark it as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;.  This will raise an error on code that attempts to modify it.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;CantChangeArray(const array[], index, value)&lt;br /&gt;
{&lt;br /&gt;
   array[index] = value;    //Won't compile&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good idea to use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; in array parameters if you know the array won't be modified; this can prevent coding mistakes.&lt;br /&gt;
&lt;br /&gt;
=Expressions=&lt;br /&gt;
Expressions are exactly the same as they are in mathematics.  They are groups of operators/symbols which evaluate to one piece of data.  They are often parenthetical (comprised of parenthesis).  They contain a strict &amp;quot;order of operations.&amp;quot;  They can contain variables, functions, numbers, and expressions themselves can be nested inside other expressions, or even passed as parameters.&lt;br /&gt;
&lt;br /&gt;
The simplest expression is a single number.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
0;   //Returns the number 0&lt;br /&gt;
(0); //Returns the number 0 as well&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although expressions can return any value, they are also said to either return ''zero or non-zero''.  In that sense, ''zero'' is ''false'', and ''non-zero'' is ''true''.  For example, -1 is '''true''' in Pawn, since it is non-zero.  Do not assume negative numbers are false.&lt;br /&gt;
&lt;br /&gt;
The order of operations for expressions is similar to C.  PMDAS: Parenthesis, Multiplication, Division, Addition, Subtraction.  Here are some example expressions:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
5 + 6;                   //Evaluates to 11&lt;br /&gt;
5 * 6 + 3;               //Evaluates to 33&lt;br /&gt;
5 * (6 + 3);             //Evaluates to 45&lt;br /&gt;
5.0 + 2.3;               //Evaluates to 7.3&lt;br /&gt;
(5 * 6) % 7;             //Modulo operator, evaluates to 2&lt;br /&gt;
(5 + 3) / 2 * 4 - 9;     //Evaluates to 7&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As noted, expressions can contain variables, or even functions:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5 * 6;&lt;br /&gt;
new b = a * 3;      //Evaluates to 90&lt;br /&gt;
new c = AddTwoNumbers(a, b) + (a * b);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note:  String manipulation routines may be found in the string.inc file located in the include subdirectory.  They may be browsed through the [http://docs.sourcemod.net/api/ API Reference] as well.&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
There are a few extra helpful operators in Pawn.  The first set simplifies self-aggregation expressions.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
&lt;br /&gt;
a = a + 5;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Can be rewritten as:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
a += 5;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is true of the following operators in Pawn:&lt;br /&gt;
*Four-function: *, /, -, +&lt;br /&gt;
*Bit-wise: |, &amp;amp;, ^, ~, &amp;lt;&amp;lt;, &amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, there are increment/decrement operators:&lt;br /&gt;
&amp;lt;pawn&amp;gt;a = a + 1;&lt;br /&gt;
a = a - 1;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Can be simplified as:&lt;br /&gt;
&amp;lt;pawn&amp;gt;a++;&lt;br /&gt;
a--;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As an advanced note, the ++ or -- can come before the variable (pre-increment, pre-decrement) or after the variable (post-increment, post-decrement).  The difference is in how the rest of the expression containing them sees their result.&lt;br /&gt;
&lt;br /&gt;
* ''Pre:'' The variable is incremented before evaluation, and the rest of the expression sees the new value.&lt;br /&gt;
* ''Post:'' The variable is incremented after evaluation, and the rest of the expression sees the old value.&lt;br /&gt;
&lt;br /&gt;
In other words, &amp;lt;tt&amp;gt;a++&amp;lt;/tt&amp;gt; evaluates to the value of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; while &amp;lt;tt&amp;gt;++a&amp;lt;/tt&amp;gt; evaluates to the value of &amp;lt;tt&amp;gt;a + 1&amp;lt;/tt&amp;gt;.  In both cases &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; is incremented by &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
new b = a++;   // b = 5, a = 6  (1)&lt;br /&gt;
new c = ++a;   // a = 7, c = 7  (2)&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In (1) &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; is assigned &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;'s ''old'' value ''before'' it is incremented to &amp;lt;tt&amp;gt;6&amp;lt;/tt&amp;gt;, but in (2) &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; is assigned &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;'s ''new'' value ''after'' it is incremented to &amp;lt;tt&amp;gt;7&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Comparison Operators==&lt;br /&gt;
There are six operators for comparing two values numerically, and the result is either true (non-zero) or false (zero):&lt;br /&gt;
*&amp;lt;tt&amp;gt;a == b&amp;lt;/tt&amp;gt; - True if a and b have the same value.&lt;br /&gt;
*&amp;lt;tt&amp;gt;a != b&amp;lt;/tt&amp;gt; - True if a and b have different values.&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;gt; b&amp;lt;/tt&amp;gt; - True if a is greater than b&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;gt;= b&amp;lt;/tt&amp;gt; - True if a is greater than or equal to b&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;lt; b&amp;lt;/tt&amp;gt; - True if a is less than b&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;lt;= b&amp;lt;/tt&amp;gt; - True if a is less than or equal to b&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
(1 != 3);         //Evaluates to true because 1 is not equal to 3.&lt;br /&gt;
(3 + 3 == 6);     //Evaluates to true because 3+3 is 6.&lt;br /&gt;
(5 - 2 &amp;gt;= 4);     //Evaluates to false because 3 is less than 4.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that these operators do not work on arrays or strings.  That is, you cannot compare either using &amp;lt;tt&amp;gt;==&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Truth Operators==&lt;br /&gt;
These truth values can be combined using three boolean operators:&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;&amp;amp; b&amp;lt;/tt&amp;gt; - True if both a and b are true. False if a or b (or both) is false.&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
! &amp;lt;tt&amp;gt;&amp;amp;&amp;amp;&amp;lt;/tt&amp;gt; !! 0 !! 1&lt;br /&gt;
|-&lt;br /&gt;
! 0&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
! 1&lt;br /&gt;
| 0 || 1&lt;br /&gt;
|}&lt;br /&gt;
*&amp;lt;tt&amp;gt;a || b&amp;lt;/tt&amp;gt; - True if a or b (or both) is true. False if both a and b are false.&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
! &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;||&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; !! 0 !! 1&lt;br /&gt;
|-&lt;br /&gt;
! 0&lt;br /&gt;
| 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
! 1&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
*&amp;lt;tt&amp;gt;!a&amp;lt;/tt&amp;gt; - True if a is false. False if a is true.&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
! &amp;lt;tt&amp;gt;!&amp;lt;/tt&amp;gt; !! 0 !! 1&lt;br /&gt;
|- &lt;br /&gt;
!&lt;br /&gt;
| 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
(1 || 0);         //Evaluates to true because the expression 1 is true&lt;br /&gt;
(1 &amp;amp;&amp;amp; 0);         //Evaluates to false because the expression 0 is false&lt;br /&gt;
(!1 || 0);        //Evaluates to false because !1 is false.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Left/Right Values==&lt;br /&gt;
Two important concepts are left-hand and right-hand values, or l-values and r-values.  An l-value is what appears on the left-hand side of a variable assignment, and an r-value is what appears on the right side of a variable assignment.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; is an l-value and &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt; is an r-value.&lt;br /&gt;
&lt;br /&gt;
The rules:&lt;br /&gt;
*'''Expressions are never l-values'''.&lt;br /&gt;
*'''Variables are both l-values and r-values'''.&lt;br /&gt;
&lt;br /&gt;
=Conditionals=&lt;br /&gt;
Conditional statements let you only run code if a certain condition is matched.&lt;br /&gt;
&lt;br /&gt;
==If Statements==&lt;br /&gt;
If statements test one or more conditions.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
if (a == 5)&lt;br /&gt;
{&lt;br /&gt;
   /* Code that will run if the expression was true */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They can be extended to handle more cases as well:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
if (a == 5)&lt;br /&gt;
{&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&lt;br /&gt;
else if (a == 6)&lt;br /&gt;
{&lt;br /&gt;
   /* Code  */&lt;br /&gt;
}&lt;br /&gt;
else if (a == 7)&lt;br /&gt;
{&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also handle the case of no expression being matched.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
if (a == 5)&lt;br /&gt;
{&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
   /* Code that will run if no expressions were true */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Switch Statements==&lt;br /&gt;
Switch statements are restricted if statements.  They test one expression for a series of possible values.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
switch (a)&lt;br /&gt;
{&lt;br /&gt;
   case 5:&lt;br /&gt;
   {&lt;br /&gt;
      /* code */&lt;br /&gt;
   }&lt;br /&gt;
   case 6:&lt;br /&gt;
   {&lt;br /&gt;
      /* code */&lt;br /&gt;
   }&lt;br /&gt;
   case 7:&lt;br /&gt;
   {&lt;br /&gt;
      /* code */&lt;br /&gt;
   }&lt;br /&gt;
   case 8, 9, 10:&lt;br /&gt;
   {&lt;br /&gt;
      /* Code */&lt;br /&gt;
   }&lt;br /&gt;
   default:&lt;br /&gt;
   {&lt;br /&gt;
      /* will run if no case matched */&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike some other languages, switches are not fall-through.  That is, multiple cases will never be run.  When a case matches its code is executed, and the switch is then immediately terminated.&lt;br /&gt;
&lt;br /&gt;
=Loops=&lt;br /&gt;
Loops allow you to conveniently repeat a block of code while a given condition remains true.  &lt;br /&gt;
&lt;br /&gt;
==For Loops==&lt;br /&gt;
For loops are loops which have four parts:&lt;br /&gt;
*The '''initialization''' statement - run once before the first loop.&lt;br /&gt;
*The '''condition''' statement - checks whether the next loop should run, including the first one.  The loop terminates when this expression evaluates to false.&lt;br /&gt;
*The '''iteration''' statement - run after each loop.&lt;br /&gt;
*The '''body''' block - run each time the '''condition''' statement evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
for ( /* initialization */ ; /* condition */ ; /* iteration */ )&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A simple example is a function to sum an array:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};&lt;br /&gt;
new sum = SumArray(array, 10);&lt;br /&gt;
&lt;br /&gt;
SumArray(const array[], count)&lt;br /&gt;
{&lt;br /&gt;
   new total;&lt;br /&gt;
&lt;br /&gt;
   for (new i = 0; i &amp;lt; count; i++)&lt;br /&gt;
   {&lt;br /&gt;
      total += array[i];&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return total;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Broken down:&lt;br /&gt;
*&amp;lt;tt&amp;gt;new i = 0&amp;lt;/tt&amp;gt; - Creates a new variable for the loop, sets it to 0.&lt;br /&gt;
*&amp;lt;tt&amp;gt;i &amp;lt; count&amp;lt;/tt&amp;gt; - Only runs the loop if &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; is less than &amp;lt;tt&amp;gt;count&amp;lt;/tt&amp;gt;.  This ensures that the loop stops reading at a certain point.  In this case, we don't want to read invalid indexes in the array.&lt;br /&gt;
*&amp;lt;tt&amp;gt;i++&amp;lt;/tt&amp;gt; - Increments &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; by one after each loop.  This ensures that the loop doesn't run forever; eventually &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; will become too big and the loop will end.&lt;br /&gt;
&lt;br /&gt;
Thus, the &amp;lt;tt&amp;gt;SumArray&amp;lt;/tt&amp;gt; function will loop through each valid index of the array, each time adding that value of the array into a sum.  For loops are very common for processing arrays like this.&lt;br /&gt;
&lt;br /&gt;
==While Loops==&lt;br /&gt;
While loops are less common than for loops but are actually the simplest possible loop.  They have only two parts:&lt;br /&gt;
*The '''condition''' statement - checked before each loop.  The loop terminates when it evaluates to false.&lt;br /&gt;
*The '''body''' block - run each time through the loop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
while ( /* condition */ )&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the condition expression remains true, the loop will continue.  Every for loop can be rewritten as a while loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
/* initialization */&lt;br /&gt;
while ( /* condition */ )&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
   /* iteration */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is the previous for loop rewritten as a while loop:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
SumArray(const array[], count)&lt;br /&gt;
{&lt;br /&gt;
   new total, i;&lt;br /&gt;
&lt;br /&gt;
   while (i &amp;lt; count)&lt;br /&gt;
   {&lt;br /&gt;
      total += array[i];&lt;br /&gt;
      i++;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return total;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also '''do...while''' loops which are even less common.  These are the same as while loops except the condition check is AFTER each loop, rather than before.  This means the loop is always run at least once.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
}&lt;br /&gt;
while ( /* condition */ );&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Loop Control==&lt;br /&gt;
There are two cases in which you want to selectively control a loop:&lt;br /&gt;
*'''skipping''' one iteration of the loop but continuing as normal, or;&lt;br /&gt;
*'''breaking''' the loop entirely before it's finished.&lt;br /&gt;
&lt;br /&gt;
Let's say you have a function which takes in an array and searches for a matching number.  You want it to stop once the number is found:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Returns the array index where the value is, or -1 if not found.&lt;br /&gt;
 */&lt;br /&gt;
SearchInArray(const array[], count, value)&lt;br /&gt;
{&lt;br /&gt;
   new index = -1;&lt;br /&gt;
 &lt;br /&gt;
   for (new i = 0; i &amp;lt; count; i++)&lt;br /&gt;
   {&lt;br /&gt;
      if (array[i] == value)&lt;br /&gt;
      {&lt;br /&gt;
         index = i;&lt;br /&gt;
         break;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return index;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Certainly, this function could simply &amp;lt;tt&amp;gt;return i&amp;lt;/tt&amp;gt; instead, but the example shows how &amp;lt;tt&amp;gt;break&amp;lt;/tt&amp;gt; will terminate the loop.&lt;br /&gt;
&lt;br /&gt;
Similarly, the &amp;lt;tt&amp;gt;continue&amp;lt;/tt&amp;gt; keyword skips an iteration of a loop.  For example, let's say we wanted to sum all even numbers:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
SumEvenNumbers(const array[], count)&lt;br /&gt;
{&lt;br /&gt;
   new sum;&lt;br /&gt;
 &lt;br /&gt;
   for (new i = 0; i &amp;lt; count; i++)&lt;br /&gt;
   {&lt;br /&gt;
      /* If divisibility by 2 is 1, we know it's odd */&lt;br /&gt;
      if (array[i] % 2 == 1)&lt;br /&gt;
      {&lt;br /&gt;
         /* Skip the rest of this loop iteration */&lt;br /&gt;
         continue;&lt;br /&gt;
      }&lt;br /&gt;
      sum += array[i];&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return sum;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
Scope refers to the '''visibility''' of code.  That is, code at one level may not be &amp;quot;visible&amp;quot; to code at another level.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new A, B, C;&lt;br /&gt;
&lt;br /&gt;
Function1()&lt;br /&gt;
{&lt;br /&gt;
   new B;&lt;br /&gt;
&lt;br /&gt;
   Function2();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Function2()&lt;br /&gt;
{&lt;br /&gt;
   new C;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;C&amp;lt;/tt&amp;gt; exist at '''global scope'''.  They can be seen by any function.  However, the &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt; is not the same variable as the &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; at the global level.  Instead, it is at '''local scope''', and is thus a '''local variable'''.&lt;br /&gt;
&lt;br /&gt;
Similarly, &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Function2&amp;lt;/tt&amp;gt; know nothing about each other's variables.&lt;br /&gt;
&lt;br /&gt;
Not only is the variable private to &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt;, but it is re-created each time the function is invoked.  Imagine this:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
Function1()&lt;br /&gt;
{&lt;br /&gt;
   new B;&lt;br /&gt;
&lt;br /&gt;
   Function1();&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt; calls itself.  Of course, this is infinite recursion (a bad thing), but the idea is that each time the function runs, there is a new copy of &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt;.  When the function ends, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is destroyed, and the value is lost.&lt;br /&gt;
&lt;br /&gt;
This property can be simplified by saying that a variable's scope is equal to the nesting level it is in.  That is, a variable at global scope is visible globally to all functions.  A variable at local scope is visible to all code blocks &amp;quot;beneath&amp;quot; its nesting level.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;Function1()&lt;br /&gt;
{&lt;br /&gt;
   new A;&lt;br /&gt;
&lt;br /&gt;
   if (A)&lt;br /&gt;
   {&lt;br /&gt;
      A = 5;&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is valid since A's scope extends throughout the function.  The following code, however, is not valid:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
Function1()&lt;br /&gt;
{&lt;br /&gt;
   new A;&lt;br /&gt;
&lt;br /&gt;
   if (A)&lt;br /&gt;
   {&lt;br /&gt;
      new B = 5;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   B = 5;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is declared in a new code block.  That means &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is only accessible to that code block (and all sub-blocks nested within).  As soon as the code block terminates, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is no longer valid.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Dynamic Arrays=&lt;br /&gt;
Dynamic arrays are arrays which don't have a hardcoded size.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;Function1(size)&lt;br /&gt;
{&lt;br /&gt;
   new array[size];&lt;br /&gt;
&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dynamic arrays can have any expression as their size as long as the expression evaluates to a number larger than 0.  Like normal arrays, SourcePawn does not know the array size after it is created; you have to save it if you want it later.&lt;br /&gt;
&lt;br /&gt;
Dynamic arrays are only valid at the local scope level, since code cannot exist globally.&lt;br /&gt;
&lt;br /&gt;
=Extended Variable Declarations=&lt;br /&gt;
Variables can be declared in more ways than simply &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==decl==&lt;br /&gt;
===Purpose===&lt;br /&gt;
By default, all variables in Pawn are initialized to zero.  If there is an explicit initializer, the variable is initialized to the expression after the &amp;lt;tt&amp;gt;=&amp;lt;/tt&amp;gt; token.  At a local scope, this can be a run-time expense.  The &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; keyword (which is only valid at local scope) was introduced to let users decide if they want variables initialized or not.&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; should not be used on single cell variables.  There is almost never any benefit.&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
new d;&lt;br /&gt;
new String:blah[512];&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; is equal to 5 and &amp;lt;tt&amp;gt;d&amp;lt;/tt&amp;gt; is equal to 0.  The run-time expense of this initialization is negligible.  However, &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; is a large array, and the expense of initializing the entire array to 0s could be detrimental in certain situations.  &lt;br /&gt;
&lt;br /&gt;
Note that &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; does not need to be zeroed.  In between being declared with &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt; and stored with &amp;lt;tt&amp;gt;Format()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; is never loaded or read.  Thus this code would be more efficiently written as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
new d;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Caveats===&lt;br /&gt;
The downside to &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; is that it means its variables will start with &amp;quot;garbage&amp;quot; contents.  For example, if we were to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
new d;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
PrintToServer(&amp;quot;%s&amp;quot;, blah);&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code may crash the server, because &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; may be completely corrupt (strings require a terminator, and that may not be present).  Similarly, if we did:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
decl d;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value of &amp;lt;tt&amp;gt;d&amp;lt;/tt&amp;gt; is now undefined.  It could be any value, negative or positive.  &lt;br /&gt;
&lt;br /&gt;
Note that it is easy to efficiently make strings safe.  The example below shows how to terminate a garbage string:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
blah[0] = '\0';&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Golden Rules===&lt;br /&gt;
*'''Only use decl if in between declaring and loading/reading the value, you are absolutely sure there is at least one store/set operation that gives the variable valid data.'''&lt;br /&gt;
*'''Do not prematurely optimize.'''  Likewise, there is no need to use &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; on non-arrays, because there is no added expense for initializing a single cell value.&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
This example is NOT as efficient as a &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new String:blah[512] = &amp;quot;a&amp;quot;;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Even though the string is only one character, the &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt; operator guarantees the rest of the array will be zeroed as well.&lt;br /&gt;
&lt;br /&gt;
Also note, it is valid to explicitly initialize a &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; '''ONLY''' with strings:&lt;br /&gt;
&amp;lt;pawn&amp;gt;decl String:blah[512] = &amp;quot;a&amp;quot;;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, any other tag will fail to compile, because the purpose of &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; is to avoid any initialization:&lt;br /&gt;
&amp;lt;pawn&amp;gt;decl Float:blah[512] = {1.0};&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==static==&lt;br /&gt;
The &amp;lt;tt&amp;gt;static&amp;lt;/tt&amp;gt; keyword is available at global and local scope.  It has different meanings in each.&lt;br /&gt;
&lt;br /&gt;
===Global static===&lt;br /&gt;
A global static variable can only be accessed from within the same file.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;//file1.inc&lt;br /&gt;
static Float:g_value1 = 0.15f;&lt;br /&gt;
&lt;br /&gt;
//file2.inc&lt;br /&gt;
static Float:g_value2 = 0.15f;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a plugin includes both of these files, it will not be able to use either &amp;lt;tt&amp;gt;g_value1&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;g_value2&amp;lt;/tt&amp;gt;.  This is a simple information hiding mechanism, and is similar to declaring member variables as &amp;lt;tt&amp;gt;private&amp;lt;/tt&amp;gt; in languages like C++, Java, or C#.&lt;br /&gt;
&lt;br /&gt;
===Local static===&lt;br /&gt;
A local static variable is a global variable that is only visible from its local lexical scope.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
MyFunction(inc)&lt;br /&gt;
{&lt;br /&gt;
   static counter = -1;&lt;br /&gt;
&lt;br /&gt;
   counter += inc;&lt;br /&gt;
&lt;br /&gt;
   return counter;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, &amp;lt;tt&amp;gt;counter&amp;lt;/tt&amp;gt; is technically a global variable -- it is initialized once to -1 and is never initialized again.  It does not exist on the stack.  That means each time &amp;lt;tt&amp;gt;MyFunction&amp;lt;/tt&amp;gt; runs, the &amp;lt;tt&amp;gt;counter&amp;lt;/tt&amp;gt; variable and its storage in memory is the same.&lt;br /&gt;
&lt;br /&gt;
Take this example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;MyFunction(5);&lt;br /&gt;
MyFunction(6);&lt;br /&gt;
MyFunction(10);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, &amp;lt;tt&amp;gt;counter&amp;lt;/tt&amp;gt; will be &amp;lt;tt&amp;gt;-1 + 5 + 6 + 10&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;20&amp;lt;/tt&amp;gt;, because it persists beyond the frame of the function.  Note this may pose problems for recursive functions: if your function may be recursive, then &amp;lt;tt&amp;gt;static&amp;lt;/tt&amp;gt; is usually not a good idea unless your code is re-entrant.  &lt;br /&gt;
&lt;br /&gt;
The benefit of a local static variable is that you don't have to clutter your script with global variables.  As long as the variable doesn't need to be read by another function, you can squirrel it inside the function and its persistence will be guaranteed.&lt;br /&gt;
&lt;br /&gt;
Note that statics can exist in any local scope:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
MyFunction(inc)&lt;br /&gt;
{&lt;br /&gt;
   if (inc &amp;gt; 0)&lt;br /&gt;
   {&lt;br /&gt;
      static counter;&lt;br /&gt;
      return (counter += inc);&lt;br /&gt;
   }&lt;br /&gt;
   return -1;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Scripting]]&lt;br /&gt;
&lt;br /&gt;
{{LanguageSwitch}}&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Introduction_to_SourcePawn_(legacy_syntax)&amp;diff=7733</id>
		<title>Introduction to SourcePawn (legacy syntax)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Introduction_to_SourcePawn_(legacy_syntax)&amp;diff=7733"/>
		<updated>2010-06-03T05:36:03Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: /* Natives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This guide is designed to give you a very basic overview to fundamentals of scripting in SourcePawn.  [[Pawn]] is a &amp;quot;scripting&amp;quot; language used to embed functionality in other programs.  That means it is not a standalone language, like C++ or Java, and its details will differ based on the application.  SourcePawn is the version of Pawn used in [[SourceMod]].&lt;br /&gt;
&lt;br /&gt;
This guide does not tell you how to write SourceMod plugins; it is intended as an overview of the syntax and semantics of the language instead.  Read the separate article, [[Introduction to SourceMod Plugins]] for SourceMod API specifics.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Non-Programmer Intro=&lt;br /&gt;
This section is intended for non-programmers.  If you're still confused, you may want to pick up a book on another language, such as PHP, Python, or Java, to get a better idea of what programming is like.&lt;br /&gt;
&lt;br /&gt;
==Symbols/Keywords==&lt;br /&gt;
A symbol is a series of letters, numbers, and/or underscores, that uniquely represents something.  Symbols are case-sensitive (unlike PHP, where sometimes they are not).  Symbols do not start with any special character, though they must start with a letter.  &lt;br /&gt;
&lt;br /&gt;
There are a few reserved symbols that have special meaning.  For example, &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;return&amp;lt;/tt&amp;gt; are special constructs in the language that will explained later.  They cannot be used as symbol names.&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
There a few important constructs you should know before you begin to script.  The first is a '''variable'''.  A variable is a symbol, or name, that holds data. For example, the variable &amp;quot;a&amp;quot; could hold the number &amp;quot;2&amp;quot;, &amp;quot;16&amp;quot;, &amp;quot;0&amp;quot;, et cetera.  Variables are created for storage space throughout a program.  Variables must be declared before being used, using the &amp;quot;new&amp;quot; keyword.  Data is assigned to variables using the equal sign (=).  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a, b, c, d;&lt;br /&gt;
&lt;br /&gt;
a = 5;&lt;br /&gt;
b = 16;&lt;br /&gt;
c = 0;&lt;br /&gt;
d = 500;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SourcePawn, variables have two types, which will be explained in more detail further on.&lt;br /&gt;
*Cells (arbitrary numerical data), as shown above.&lt;br /&gt;
*Strings (a series of text characters)&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
The next important concept is '''functions'''. Functions are symbols or names that perform an action.  That means when you activate them, they carry out a specific sequence of code.  There are a few types of functions, but every function is activated the same way.  &amp;quot;Calling a function&amp;quot; is the term for invoking a function's action.  Function calls are constructed like this:&lt;br /&gt;
&amp;lt;pawn&amp;gt;function(&amp;lt;parameters&amp;gt;)&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;show(56);   //Activates &amp;quot;show&amp;quot; function, and gives the number 56 to it&lt;br /&gt;
show();     //Activates &amp;quot;show&amp;quot; function with no data, blank&lt;br /&gt;
show(a);    //Activates &amp;quot;show&amp;quot; function, gives a variable's contents as data&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every piece of data passed to a function is called a '''parameter'''.  A function can have any number of parameters (there is a &amp;quot;reasonable&amp;quot; limit of 32 in SourceMod).  Parameters will be explained further in the article.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
Note any text that appears after a &amp;quot;//&amp;quot; is considered a &amp;quot;comment&amp;quot; and is not actual code.  There are two comment styles:&lt;br /&gt;
*&amp;lt;tt&amp;gt;//&amp;lt;/tt&amp;gt; - Double slash, everything following on that line is ignored.&lt;br /&gt;
*&amp;lt;tt&amp;gt;/* */&amp;lt;/tt&amp;gt; - Multi-line comment, everything in between the asterisks is ignored.  You cannot nest these.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Block Coding==&lt;br /&gt;
The next concept is block coding. You can group code into &amp;quot;blocks&amp;quot; separated by { and }. This effectively makes one large block of code act as one statement. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;{&lt;br /&gt;
   here;&lt;br /&gt;
   is;&lt;br /&gt;
   some;&lt;br /&gt;
   code;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Block coding using braces is used everywhere in programming.  Blocks of code can be nested within each other.  It is a good idea to adapt a consistent and readable indentation style early on to prevent spaghetti-looking code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Language Paradigms=&lt;br /&gt;
Pawn may seem similar to other languages, like C, but it has fundamental differences.  It is not important that you immediately understand these differences, but they may be helpful if you're familiar with another language already.&lt;br /&gt;
*'''Pawn is not typed.'''  Pawn only has one data type, the '''cell'''.  This will be explained in detail later.  [Below it says that there are two types: cell and string.]&lt;br /&gt;
*'''Pawn is not garbage collected.''' Pawn, as a language, has no built-in memory allocation, and thus has no garbage.  If a function allocates memory, you may be responsible for freeing it.&lt;br /&gt;
*'''Pawn is not object oriented.''' Pawn is procedural, and relies on subroutines.  It also does not have C structs.&lt;br /&gt;
*'''Pawn is not functional.''' Pawn is procedural, and does not support lambda functions or late binding or anything else you might find in a very high-level language, like Python or Ruby.&lt;br /&gt;
*'''Pawn is single-threaded.''' As of this writing, Pawn is not thread safe.  &lt;br /&gt;
*'''Pawn is not interpreted.''' Well, it &amp;quot;sort of&amp;quot; is.  It gets interpreted at a very low level.  You must run your code through a compiler, which produces a binary.  This binary will work on any platform that the host application uses.  This speeds up loading time and lets you check errors easier.&lt;br /&gt;
&lt;br /&gt;
These language design decisions were made by ITB CompuPhase.  It is designed for low-level embedded devices and is thus very small and very fast.&lt;br /&gt;
&lt;br /&gt;
=Variables=&lt;br /&gt;
In Pawn there are two variable types: the '''cell''' and the '''String'''.  A cell can store 32 bits of numerical data.  A String is a sequential/flat list of UTF-8 text characters.&lt;br /&gt;
&lt;br /&gt;
A '''cell''' has no inherent type, however, cells can be '''tagged'''.  A tag lets you enforce where certain cells can be used.  The default tags are:&lt;br /&gt;
*(nothing), or '''_''' - No tag.  Usually used for whole numbers ([http://en.wikipedia.org/wiki/Integer Integers]).&lt;br /&gt;
*'''Float''' - Used for floating point (fractional) numbers.&lt;br /&gt;
*'''bool''' - Used for storing either '''true''' or '''false'''.&lt;br /&gt;
&lt;br /&gt;
Strings are different and will be explained in the next sections.&lt;br /&gt;
&lt;br /&gt;
==Declaration==&lt;br /&gt;
Examples of different valid variable declarations:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5;&lt;br /&gt;
new Float:b = 5.0;&lt;br /&gt;
new bool:c = true;&lt;br /&gt;
new bool:d = 0;      //Works because 0 is false&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Invalid variable usage:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5.0;         //Tag mismatch.  5.0 is tagged as Float&lt;br /&gt;
new Float:b = 5;     //Tag mismatch.  5 is not tagged.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a variable is not assigned upon declaration, it will be set to 0.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a;        //Set to 0&lt;br /&gt;
new Float:b;  //Set to 0.0&lt;br /&gt;
new bool:c;   //Set to false&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment==&lt;br /&gt;
Variables can be re-assigned data after they are created.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a, Float:b, bool:c;&lt;br /&gt;
&lt;br /&gt;
a = 5;&lt;br /&gt;
b = 5.0;&lt;br /&gt;
c = true;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Arrays=&lt;br /&gt;
An array is a sequence of data in a sequential list.  Arrays are useful for storing multiple pieces of data in one variable, and often greatly simplify many tasks.  &lt;br /&gt;
&lt;br /&gt;
==Declaration==&lt;br /&gt;
An array is declared using brackets.  Some examples of arrays:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new players[32];     //Stores 32 cells (numbers)&lt;br /&gt;
new Float:origin[3]; //Stores 3 floating point numbers&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, arrays are initialized to 0.  You can assign them different default values, however:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[5] = {1, 2, 3, 4, 5};       //Stores 1, 2, 3, 4, 5 in the cells.&lt;br /&gt;
new Float:origin[3] = {1.0, 2.0, 3.0};  //Stores 1.0, 2.0, 3.0 in the cells.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can leave out the array size if you're going to pre-assign data to it.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[] = {1, 3, 5, 7, 9};&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The compiler will automatically deduce that you intended an array of size 5.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
Using an array is just like using a normal variable.  The only difference is the array must be '''indexed'''.  Indexing an array means choosing the element which you wish to use.&lt;br /&gt;
&lt;br /&gt;
For example, here is an example of the above code using indexes:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[5], Float:origin[3];&lt;br /&gt;
&lt;br /&gt;
numbers[0] = 1;&lt;br /&gt;
numbers[1] = 2;&lt;br /&gt;
numbers[2] = 3;&lt;br /&gt;
numbers[3] = 4;&lt;br /&gt;
numbers[4] = 5;&lt;br /&gt;
origin[0] = 1.0;&lt;br /&gt;
origin[1] = 2.0;&lt;br /&gt;
origin[2] = 3.0;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the '''index''' is what's in between the brackets.  The index always starts from 0.  That is, if an array has N elements, its valid indexes are from 0 to N-1.  Accessing the data at these indexes works like a normal variable.&lt;br /&gt;
&lt;br /&gt;
To use an incorrect index will cause an error.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new numbers[5];&lt;br /&gt;
&lt;br /&gt;
numbers[5] = 20;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may look correct, but 5 is not a valid index.  The highest valid index is 4.&lt;br /&gt;
&lt;br /&gt;
You can use any expression as an index.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a, numbers[5];&lt;br /&gt;
&lt;br /&gt;
a = 1;                   //Set a = 1&lt;br /&gt;
numbers[a] = 4;          //Set numbers[1] = 4&lt;br /&gt;
numbers[numbers[a]] = 2; //Set numbers[4] = 2&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Expressions will be discussed in depth later in the article.&lt;br /&gt;
&lt;br /&gt;
=Strings=&lt;br /&gt;
Strings are a convenient method of storing text.  The characters are stored in an array.  The string is terminated by a '''null terminator''', or a 0.  Without a null terminator, Pawn would not know where to stop reading the string.  All strings are UTF-8 in SourcePawn.&lt;br /&gt;
&lt;br /&gt;
Notice that Strings are a combination of arrays and cells.  Unlike other languages, this means you must know how much space a string will use in advance.  That is, strings are not dynamic.  They can only grow to the space you allocate for them.&lt;br /&gt;
&lt;br /&gt;
''Note for experts:  They're not actually cells.  SourcePawn uses 8-bit storage for String arrays as an optimization.  This is what makes String a type and not a tag.''&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
Strings are declared almost equivalently to arrays.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new String:message[] = &amp;quot;Hello!&amp;quot;;&lt;br /&gt;
new String:clams[6] = &amp;quot;Clams&amp;quot;;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are equivalent to doing:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new String:message[7], String:clams[6];&lt;br /&gt;
&lt;br /&gt;
message[0] = 'H';&lt;br /&gt;
message[1] = 'e';&lt;br /&gt;
message[2] = 'l';&lt;br /&gt;
message[3] = 'l';&lt;br /&gt;
message[4] = 'o';&lt;br /&gt;
message[5] = '!';&lt;br /&gt;
message[6] = 0;&lt;br /&gt;
clams[0] = 'C';&lt;br /&gt;
clams[1] = 'l';&lt;br /&gt;
clams[2] = 'a';&lt;br /&gt;
clams[3] = 'm';&lt;br /&gt;
clams[4] = 's';&lt;br /&gt;
clams[5] = 0;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although strings are rarely initialized in this manner, it is very important to remember the concept of the null terminator, which signals the end of a string.  The compiler, and most SourceMod functions will automatically null-terminate for you, so it is mainly important when manipulating strings directly.&lt;br /&gt;
&lt;br /&gt;
Note that a string is enclosed in double-quotes, but a character is enclosed in single quotes.&lt;br /&gt;
&lt;br /&gt;
==Characters==&lt;br /&gt;
A character of text can be used in either a String or a cell.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new String:text[] = &amp;quot;Crab&amp;quot;;&lt;br /&gt;
new clam;&lt;br /&gt;
&lt;br /&gt;
clam = 'D';         //Set clam to 'D'&lt;br /&gt;
text[0] = 'A';      //Change the 'C' to 'A', it is now 'Arab'&lt;br /&gt;
clam = text[0];     //Set clam to 'A'&lt;br /&gt;
text[1] = clam;     //Change the 'r' to 'A', is is now 'AAab'&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What you can't do is mix character arrays with strings.  The internal storage is different.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new clams[] = &amp;quot;Clams&amp;quot;;                       //Invalid, needs String: type&lt;br /&gt;
new clams[] = {'C', 'l', 'a', 'm', 's', 0};  //Valid, but NOT A STRING.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Functions=&lt;br /&gt;
Functions, as stated before, are isolated blocks of code that perform an action.  They can be invoked, or '''called''', with '''parameters''' that give specific options.&lt;br /&gt;
&lt;br /&gt;
There are two types of ways functions are called:&lt;br /&gt;
*'''direct call''' - You specifically call a function in your code.&lt;br /&gt;
*'''callback''' - The application calls a function in your code, as if it were an event trigger.&lt;br /&gt;
&lt;br /&gt;
There are five types of functions:&lt;br /&gt;
*'''native''': A direct, internal function provided by the application.&lt;br /&gt;
*'''public''': A callback function that is visible to the application and other scripts.&lt;br /&gt;
*'''normal''': A normal function that only you can call.&lt;br /&gt;
*'''stock''': A normal function provided by an include file.  If unused, it won't be compiled.&lt;br /&gt;
*'''forward''': This function is a global event provided by the application.  If you implement it, it will be a callback.&lt;br /&gt;
&lt;br /&gt;
All code in Pawn must exist in functions.  This is in contrast to languages like PHP, Perl, and Python which let you write global code.  That is because Pawn is a callback-based language: it responds to actions from a parent application, and functions must be written to handle those actions.  Although our examples often contain free-floating code, this is purely for demonstration purposes.  Free-floating code in our examples implies the code is part of some function.&lt;br /&gt;
&lt;br /&gt;
==Declaration==&lt;br /&gt;
Unlike variables, functions do not need to be declared before you use them.  Functions have two pieces, the '''prototype''' and the '''body'''.  The prototype contains the name of your function and the parameters it will accept.  The body is the contents of its code.&lt;br /&gt;
&lt;br /&gt;
Example of a function:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
AddTwoNumbers(first, second)&lt;br /&gt;
{&lt;br /&gt;
  new sum = first + second;&lt;br /&gt;
&lt;br /&gt;
  return sum;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a simple function.  The prototype is this line:&lt;br /&gt;
&amp;lt;pawn&amp;gt;AddTwoNumbers(first, second)&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Broken down, it means:&lt;br /&gt;
*&amp;lt;tt&amp;gt;AddTwoNumbers&amp;lt;/tt&amp;gt; - Name of the function.&lt;br /&gt;
*&amp;lt;tt&amp;gt;first&amp;lt;/tt&amp;gt; - Name of the first parameter, which is a simple cell.&lt;br /&gt;
*&amp;lt;tt&amp;gt;second&amp;lt;/tt&amp;gt; - Name of the second parameter, which is a simple cell.&lt;br /&gt;
&lt;br /&gt;
The body is a simple block of code.  It creates a new variable, called &amp;lt;tt&amp;gt;sum&amp;lt;/tt&amp;gt;, and assigns it the value of the two parameters added together (more on expressions later).  The important thing to notice is the &amp;lt;tt&amp;gt;return&amp;lt;/tt&amp;gt; statement, which tells the function to end and return a value to the caller of the function.  All functions ''return a cell'' upon completion.  That means, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;new sum = AddTwoNumbers(4, 5);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code will assign the number 9 to sum.  The function adds the two inputs, and the sum is given as the '''return value'''.  If a function has no return statement or does not place a value in the return statement, it returns 0 by default.&lt;br /&gt;
&lt;br /&gt;
A function can accept any type of input.  It can return any cell, but not arrays or strings.  Example:  &lt;br /&gt;
&amp;lt;pawn&amp;gt;Float:AddTwoFloats(Float:a, Float:b)&lt;br /&gt;
{&lt;br /&gt;
   new Float:sum = a + b;&lt;br /&gt;
 &lt;br /&gt;
   return sum;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Note that if in the above function, you returned a non-Float, you would get a tag mismatch.''&lt;br /&gt;
&lt;br /&gt;
You can, of course, pass variables to functions:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new numbers[3] = {1, 2, 0};&lt;br /&gt;
&lt;br /&gt;
numbers[2] = AddTwoNumbers(numbers[0], numbers[1]);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that cells are passed '''by value'''.  That is, their value cannot be changed by the function.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
&lt;br /&gt;
ChangeValue(a);&lt;br /&gt;
&lt;br /&gt;
ChangeValue(b)&lt;br /&gt;
{&lt;br /&gt;
   b = 5;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code would not change the value of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;.  That is because a copy of the value in &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; is passed instead of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; itself.  &lt;br /&gt;
&lt;br /&gt;
More examples of functions will be provided throughout the article.&lt;br /&gt;
&lt;br /&gt;
==Publics==&lt;br /&gt;
Public functions are used to implement callbacks.  You should not create a public function unless it is specifically implementing a callback.  For example, here are two callbacks from &amp;lt;tt&amp;gt;sourcemod.inc&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;forward OnPluginStart();&lt;br /&gt;
forward OnClientDisconnected(client);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To implement and receive these two events, you would write functions as such:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;public OnPluginStart()&lt;br /&gt;
{&lt;br /&gt;
   /* Code here */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public OnClientDisconnected(client)&lt;br /&gt;
{&lt;br /&gt;
   /* Code here */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''public''' keyword exposes the function publicly, and allows the parent application to directly call the function.&lt;br /&gt;
&lt;br /&gt;
==Natives==&lt;br /&gt;
Natives are builtin functions provided by SourceMod.  You can call them as if they were a normal function.  For example, SourceMod has the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;native FloatRound(Float:num);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be called like so:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new num = FloatRound(5.2);     //Results in num = 5&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Array Parameters==&lt;br /&gt;
You can pass arrays or Strings as parameters.  It is important to note that these are passed '''by reference'''.  That is, rather than making a copy of the data, the data is referenced directly.  There is a simple way of explaining this more concretely.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new example[] = {1, 2, 3, 4, 5};&lt;br /&gt;
&lt;br /&gt;
ChangeArray(example, 2, 29);&lt;br /&gt;
&lt;br /&gt;
ChangeArray(array[], index, value)&lt;br /&gt;
{&lt;br /&gt;
   array[index] = value;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function sets the given index in the array to a given value.  When it is run on our example array, it changes index 2 to from the value 3 to 29.  I.e.:&lt;br /&gt;
&amp;lt;pawn&amp;gt;example[2] = 29;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is only possible because the array can be directly modified.  To prevent an array from being modified, you can mark it as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;.  This will raise an error on code that attempts to modify it.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;CantChangeArray(const array[], index, value)&lt;br /&gt;
{&lt;br /&gt;
   array[index] = value;    //Won't compile&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good idea to use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; in array parameters if you know the array won't be modified; this can prevent coding mistakes.&lt;br /&gt;
&lt;br /&gt;
=Expressions=&lt;br /&gt;
Expressions are exactly the same as they are in mathematics.  They are groups of operators/symbols which evaluate to one piece of data.  They are often parenthetical (comprised of parenthesis).  They contain a strict &amp;quot;order of operations.&amp;quot;  They can contain variables, functions, numbers, and expressions themselves can be nested inside other expressions, or even passed as parameters.&lt;br /&gt;
&lt;br /&gt;
The simplest expression is a single number.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
0;   //Returns the number 0&lt;br /&gt;
(0); //Returns the number 0 as well&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although expressions can return any value, they are also said to either return ''zero or non-zero''.  In that sense, ''zero'' is ''false'', and ''non-zero'' is ''true''.  For example, -1 is '''true''' in Pawn, since it is non-zero.  Do not assume negative numbers are false.&lt;br /&gt;
&lt;br /&gt;
The order of operations for expressions is similar to C.  PMDAS: Parenthesis, Multiplication, Division, Addition, Subtraction.  Here are some example expressions:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
5 + 6;                   //Evaluates to 11&lt;br /&gt;
5 * 6 + 3;               //Evaluates to 33&lt;br /&gt;
5 * (6 + 3);             //Evaluates to 45&lt;br /&gt;
5.0 + 2.3;               //Evaluates to 7.3&lt;br /&gt;
(5 * 6) % 7;             //Modulo operator, evaluates to 2&lt;br /&gt;
(5 + 3) / 2 * 4 - 9;     //Evaluates to 7&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As noted, expressions can contain variables, or even functions:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5 * 6;&lt;br /&gt;
new b = a * 3;      //Evaluates to 90&lt;br /&gt;
new c = AddTwoNumbers(a, b) + (a * b);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note:  String manipulation routines may be found in the string.inc file located in the include subdirectory.  They may be browsed through the [http://docs.sourcemod.net/api/ API Reference] as well.&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
There are a few extra helpful operators in Pawn.  The first set simplifies self-aggregation expressions.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
&lt;br /&gt;
a = a + 5;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Can be rewritten as:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
a += 5;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is true of the following operators in Pawn:&lt;br /&gt;
*Four-function: *, /, -, +&lt;br /&gt;
*Bit-wise: |, &amp;amp;, ^, ~, &amp;lt;&amp;lt;, &amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, there are increment/decrement operators:&lt;br /&gt;
&amp;lt;pawn&amp;gt;a = a + 1;&lt;br /&gt;
a = a - 1;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Can be simplified as:&lt;br /&gt;
&amp;lt;pawn&amp;gt;a++;&lt;br /&gt;
a--;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As an advanced note, the ++ or -- can come before the variable (pre-increment, pre-decrement) or after the variable (post-increment, post-decrement).  The difference is in how the rest of the expression containing them sees their result.&lt;br /&gt;
&lt;br /&gt;
* ''Pre:'' The variable is incremented before evaluation, and the rest of the expression sees the new value.&lt;br /&gt;
* ''Post:'' The variable is incremented after evaluation, and the rest of the expression sees the old value.&lt;br /&gt;
&lt;br /&gt;
In other words, &amp;lt;tt&amp;gt;a++&amp;lt;/tt&amp;gt; evaluates to the value of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; while &amp;lt;tt&amp;gt;++a&amp;lt;/tt&amp;gt; evaluates to the value of &amp;lt;tt&amp;gt;a + 1&amp;lt;/tt&amp;gt;.  In both cases &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; is incremented by &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;new a = 5;&lt;br /&gt;
new b = a++;   // b = 5, a = 6  (1)&lt;br /&gt;
new c = ++a;   // a = 7, c = 7  (2)&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In (1) &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; is assigned &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;'s ''old'' value ''before'' it is incremented to &amp;lt;tt&amp;gt;6&amp;lt;/tt&amp;gt;, but in (2) &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; is assigned &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;'s ''new'' value ''after'' it is incremented to &amp;lt;tt&amp;gt;7&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Comparison Operators==&lt;br /&gt;
There are six operators for comparing two values numerically, and the result is either true (non-zero) or false (zero):&lt;br /&gt;
*&amp;lt;tt&amp;gt;a == b&amp;lt;/tt&amp;gt; - True if a and b have the same value.&lt;br /&gt;
*&amp;lt;tt&amp;gt;a != b&amp;lt;/tt&amp;gt; - True if a and b have different values.&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;gt; b&amp;lt;/tt&amp;gt; - True if a is greater than b&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;gt;= b&amp;lt;/tt&amp;gt; - True if a is greater than or equal to b&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;lt; b&amp;lt;/tt&amp;gt; - True if a is less than b&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;lt;= b&amp;lt;/tt&amp;gt; - True if a is less than or equal to b&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
(1 != 3);         //Evaluates to true because 1 is not equal to 3.&lt;br /&gt;
(3 + 3 == 6);     //Evaluates to true because 3+3 is 6.&lt;br /&gt;
(5 - 2 &amp;gt;= 4);     //Evaluates to false because 3 is less than 4.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that these operators do not work on arrays or strings.  That is, you cannot compare either using &amp;lt;tt&amp;gt;==&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Truth Operators==&lt;br /&gt;
These truth values can be combined using three boolean operators:&lt;br /&gt;
*&amp;lt;tt&amp;gt;a &amp;amp;&amp;amp; b&amp;lt;/tt&amp;gt; - True if both a and b are true. False if a or b (or both) is false.&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
! &amp;lt;tt&amp;gt;&amp;amp;&amp;amp;&amp;lt;/tt&amp;gt; !! 0 !! 1&lt;br /&gt;
|-&lt;br /&gt;
! 0&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
! 1&lt;br /&gt;
| 0 || 1&lt;br /&gt;
|}&lt;br /&gt;
*&amp;lt;tt&amp;gt;a || b&amp;lt;/tt&amp;gt; - True if a or b (or both) is true. False if both a and b are false.&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
! &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;||&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; !! 0 !! 1&lt;br /&gt;
|-&lt;br /&gt;
! 0&lt;br /&gt;
| 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
! 1&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
*&amp;lt;tt&amp;gt;!a&amp;lt;/tt&amp;gt; - True if a is false. False if a is true.&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
! &amp;lt;tt&amp;gt;!&amp;lt;/tt&amp;gt; !! 0 !! 1&lt;br /&gt;
|- &lt;br /&gt;
!&lt;br /&gt;
| 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
(1 || 0);         //Evaluates to true because the expression 1 is true&lt;br /&gt;
(1 &amp;amp;&amp;amp; 0);         //Evaluates to false because the expression 0 is false&lt;br /&gt;
(!1 || 0);        //Evaluates to false because !1 is false.&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Left/Right Values==&lt;br /&gt;
Two important concepts are left-hand and right-hand values, or l-values and r-values.  An l-value is what appears on the left-hand side of a variable assignment, and an r-value is what appears on the right side of a variable assignment.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new a = 5;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; is an l-value and &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt; is an r-value.&lt;br /&gt;
&lt;br /&gt;
The rules:&lt;br /&gt;
*'''Expressions are never l-values'''.&lt;br /&gt;
*'''Variables are both l-values and r-values'''.&lt;br /&gt;
&lt;br /&gt;
=Conditionals=&lt;br /&gt;
Conditional statements let you only run code if a certain condition is matched.&lt;br /&gt;
&lt;br /&gt;
==If Statements==&lt;br /&gt;
If statements test one or more conditions.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
if (a == 5)&lt;br /&gt;
{&lt;br /&gt;
   /* Code that will run if the expression was true */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They can be extended to handle more cases as well:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
if (a == 5)&lt;br /&gt;
{&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&lt;br /&gt;
else if (a == 6)&lt;br /&gt;
{&lt;br /&gt;
   /* Code  */&lt;br /&gt;
}&lt;br /&gt;
else if (a == 7)&lt;br /&gt;
{&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also handle the case of no expression being matched.  For example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
if (a == 5)&lt;br /&gt;
{&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
   /* Code that will run if no expressions were true */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Switch Statements==&lt;br /&gt;
Switch statements are restricted if statements.  They test one expression for a series of possible values.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
switch (a)&lt;br /&gt;
{&lt;br /&gt;
   case 5:&lt;br /&gt;
   {&lt;br /&gt;
      /* code */&lt;br /&gt;
   }&lt;br /&gt;
   case 6:&lt;br /&gt;
   {&lt;br /&gt;
      /* code */&lt;br /&gt;
   }&lt;br /&gt;
   case 7:&lt;br /&gt;
   {&lt;br /&gt;
      /* code */&lt;br /&gt;
   }&lt;br /&gt;
   case 8, 9, 10:&lt;br /&gt;
   {&lt;br /&gt;
      /* Code */&lt;br /&gt;
   }&lt;br /&gt;
   default:&lt;br /&gt;
   {&lt;br /&gt;
      /* will run if no case matched */&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike some other languages, switches are not fall-through.  That is, multiple cases will never be run.  When a case matches its code is executed, and the switch is then immediately terminated.&lt;br /&gt;
&lt;br /&gt;
=Loops=&lt;br /&gt;
Loops allow you to conveniently repeat a block of code while a given condition remains true.  &lt;br /&gt;
&lt;br /&gt;
==For Loops==&lt;br /&gt;
For loops are loops which have four parts:&lt;br /&gt;
*The '''initialization''' statement - run once before the first loop.&lt;br /&gt;
*The '''condition''' statement - checks whether the next loop should run, including the first one.  The loop terminates when this expression evaluates to false.&lt;br /&gt;
*The '''iteration''' statement - run after each loop.&lt;br /&gt;
*The '''body''' block - run each time the '''condition''' statement evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
for ( /* initialization */ ; /* condition */ ; /* iteration */ )&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A simple example is a function to sum an array:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};&lt;br /&gt;
new sum = SumArray(array, 10);&lt;br /&gt;
&lt;br /&gt;
SumArray(const array[], count)&lt;br /&gt;
{&lt;br /&gt;
   new total;&lt;br /&gt;
&lt;br /&gt;
   for (new i = 0; i &amp;lt; count; i++)&lt;br /&gt;
   {&lt;br /&gt;
      total += array[i];&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return total;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Broken down:&lt;br /&gt;
*&amp;lt;tt&amp;gt;new i = 0&amp;lt;/tt&amp;gt; - Creates a new variable for the loop, sets it to 0.&lt;br /&gt;
*&amp;lt;tt&amp;gt;i &amp;lt; count&amp;lt;/tt&amp;gt; - Only runs the loop if &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; is less than &amp;lt;tt&amp;gt;count&amp;lt;/tt&amp;gt;.  This ensures that the loop stops reading at a certain point.  In this case, we don't want to read invalid indexes in the array.&lt;br /&gt;
*&amp;lt;tt&amp;gt;i++&amp;lt;/tt&amp;gt; - Increments &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; by one after each loop.  This ensures that the loop doesn't run forever; eventually &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt; will become too big and the loop will end.&lt;br /&gt;
&lt;br /&gt;
Thus, the &amp;lt;tt&amp;gt;SumArray&amp;lt;/tt&amp;gt; function will loop through each valid index of the array, each time adding that value of the array into a sum.  For loops are very common for processing arrays like this.&lt;br /&gt;
&lt;br /&gt;
==While Loops==&lt;br /&gt;
While loops are less common than for loops but are actually the simplest possible loop.  They have only two parts:&lt;br /&gt;
*The '''condition''' statement - checked before each loop.  The loop terminates when it evaluates to false.&lt;br /&gt;
*The '''body''' block - run each time through the loop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
while ( /* condition */ )&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the condition expression remains true, the loop will continue.  Every for loop can be rewritten as a while loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
/* initialization */&lt;br /&gt;
while ( /* condition */ )&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
   /* iteration */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is the previous for loop rewritten as a while loop:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
SumArray(const array[], count)&lt;br /&gt;
{&lt;br /&gt;
   new total, i;&lt;br /&gt;
&lt;br /&gt;
   while (i &amp;lt; count)&lt;br /&gt;
   {&lt;br /&gt;
      total += array[i];&lt;br /&gt;
      i++;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return total;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also '''do...while''' loops which are even less common.  These are the same as while loops except the condition check is AFTER each loop, rather than before.  This means the loop is always run at least once.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
   /* body */&lt;br /&gt;
}&lt;br /&gt;
while ( /* condition */ );&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Loop Control==&lt;br /&gt;
There are two cases in which you want to selectively control a loop:&lt;br /&gt;
*'''skipping''' one iteration of the loop but continuing as normal, or;&lt;br /&gt;
*'''breaking''' the loop entirely before it's finished.&lt;br /&gt;
&lt;br /&gt;
Let's say you have a function which takes in an array and searches for a matching number.  You want it to stop once the number is found:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Returns the array index where the value is, or -1 if not found.&lt;br /&gt;
 */&lt;br /&gt;
SearchInArray(const array[], count, value)&lt;br /&gt;
{&lt;br /&gt;
   new index = -1;&lt;br /&gt;
 &lt;br /&gt;
   for (new i = 0; i &amp;lt; count; i++)&lt;br /&gt;
   {&lt;br /&gt;
      if (array[i] == value)&lt;br /&gt;
      {&lt;br /&gt;
         index = i;&lt;br /&gt;
         break;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return index;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Certainly, this function could simply &amp;lt;tt&amp;gt;return i&amp;lt;/tt&amp;gt; instead, but the example shows how &amp;lt;tt&amp;gt;break&amp;lt;/tt&amp;gt; will terminate the loop.&lt;br /&gt;
&lt;br /&gt;
Similarly, the &amp;lt;tt&amp;gt;continue&amp;lt;/tt&amp;gt; keyword skips an iteration of a loop.  For example, let's say we wanted to sum all even numbers:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
SumEvenNumbers(const array[], count)&lt;br /&gt;
{&lt;br /&gt;
   new sum;&lt;br /&gt;
 &lt;br /&gt;
   for (new i = 0; i &amp;lt; count; i++)&lt;br /&gt;
   {&lt;br /&gt;
      /* If divisibility by 2 is 1, we know it's odd */&lt;br /&gt;
      if (array[i] % 2 == 1)&lt;br /&gt;
      {&lt;br /&gt;
         /* Skip the rest of this loop iteration */&lt;br /&gt;
         continue;&lt;br /&gt;
      }&lt;br /&gt;
      sum += array[i];&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return sum;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Scope=&lt;br /&gt;
Scope refers to the '''visibility''' of code.  That is, code at one level may not be &amp;quot;visible&amp;quot; to code at another level.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new A, B, C;&lt;br /&gt;
&lt;br /&gt;
Function1()&lt;br /&gt;
{&lt;br /&gt;
   new B;&lt;br /&gt;
&lt;br /&gt;
   Function2();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Function2()&lt;br /&gt;
{&lt;br /&gt;
   new C;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;C&amp;lt;/tt&amp;gt; exist at '''global scope'''.  They can be seen by any function.  However, the &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt; is not the same variable as the &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; at the global level.  Instead, it is at '''local scope''', and is thus a '''local variable'''.&lt;br /&gt;
&lt;br /&gt;
Similarly, &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Function2&amp;lt;/tt&amp;gt; know nothing about each other's variables.&lt;br /&gt;
&lt;br /&gt;
Not only is the variable private to &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt;, but it is re-created each time the function is invoked.  Imagine this:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
Function1()&lt;br /&gt;
{&lt;br /&gt;
   new B;&lt;br /&gt;
&lt;br /&gt;
   Function1();&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, &amp;lt;tt&amp;gt;Function1&amp;lt;/tt&amp;gt; calls itself.  Of course, this is infinite recursion (a bad thing), but the idea is that each time the function runs, there is a new copy of &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt;.  When the function ends, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is destroyed, and the value is lost.&lt;br /&gt;
&lt;br /&gt;
This property can be simplified by saying that a variable's scope is equal to the nesting level it is in.  That is, a variable at global scope is visible globally to all functions.  A variable at local scope is visible to all code blocks &amp;quot;beneath&amp;quot; its nesting level.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;Function1()&lt;br /&gt;
{&lt;br /&gt;
   new A;&lt;br /&gt;
&lt;br /&gt;
   if (A)&lt;br /&gt;
   {&lt;br /&gt;
      A = 5;&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is valid since A's scope extends throughout the function.  The following code, however, is not valid:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
Function1()&lt;br /&gt;
{&lt;br /&gt;
   new A;&lt;br /&gt;
&lt;br /&gt;
   if (A)&lt;br /&gt;
   {&lt;br /&gt;
      new B = 5;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   B = 5;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is declared in a new code block.  That means &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is only accessible to that code block (and all sub-blocks nested within).  As soon as the code block terminates, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is no longer valid.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Dynamic Arrays=&lt;br /&gt;
Dynamic arrays are arrays which don't have a hardcoded size.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;Function1(size)&lt;br /&gt;
{&lt;br /&gt;
   new array[size];&lt;br /&gt;
&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dynamic arrays can have any expression as their size as long as the expression evaluates to a number larger than 0.  Like normal arrays, SourcePawn does not know the array size after it is created; you have to save it if you want it later.&lt;br /&gt;
&lt;br /&gt;
Dynamic arrays are only valid at the local scope level, since code cannot exist globally.&lt;br /&gt;
&lt;br /&gt;
=Extended Variable Declarations=&lt;br /&gt;
Variables can be declared in more ways than simply &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==decl==&lt;br /&gt;
===Purpose===&lt;br /&gt;
By default, all variables in Pawn are initialized to zero.  If there is an explicit initializer, the variable is initialized to the expression after the &amp;lt;tt&amp;gt;=&amp;lt;/tt&amp;gt; token.  At a local scope, this can be a run-time expense.  The &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; keyword (which is only valid at local scope) was introduced to let users decide if they want variables initialized or not.&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; should not be used on single cell variables.  There is almost never any benefit.&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
new d;&lt;br /&gt;
new String:blah[512];&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; is equal to 5 and &amp;lt;tt&amp;gt;d&amp;lt;/tt&amp;gt; is equal to 0.  The run-time expense of this initialization is negligible.  However, &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; is a large array, and the expense of initializing the entire array to 0s could be detrimental in certain situations.  &lt;br /&gt;
&lt;br /&gt;
Note that &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; does not need to be zeroed.  In between being declared with &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt; and stored with &amp;lt;tt&amp;gt;Format()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; is never loaded or read.  Thus this code would be more efficiently written as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
new d;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Caveats===&lt;br /&gt;
The downside to &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; is that it means its variables will start with &amp;quot;garbage&amp;quot; contents.  For example, if we were to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
new d;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
PrintToServer(&amp;quot;%s&amp;quot;, blah);&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code may crash the server, because &amp;lt;tt&amp;gt;blah&amp;lt;/tt&amp;gt; may be completely corrupt (strings require a terminator, and that may not be present).  Similarly, if we did:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new c = 5;&lt;br /&gt;
decl d;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
Format(blah, sizeof(blah), &amp;quot;%d %d&amp;quot;, c, d);&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value of &amp;lt;tt&amp;gt;d&amp;lt;/tt&amp;gt; is now undefined.  It could be any value, negative or positive.  &lt;br /&gt;
&lt;br /&gt;
Note that it is easy to efficiently make strings safe.  The example below shows how to terminate a garbage string:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
decl String:blah[512];&lt;br /&gt;
&lt;br /&gt;
blah[0] = '\0';&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Golden Rules===&lt;br /&gt;
*'''Only use decl if in between declaring and loading/reading the value, you are absolutely sure there is at least one store/set operation that gives the variable valid data.'''&lt;br /&gt;
*'''Do not prematurely optimize.'''  Likewise, there is no need to use &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; on non-arrays, because there is no added expense for initializing a single cell value.&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
This example is NOT as efficient as a &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
new String:blah[512] = &amp;quot;a&amp;quot;;&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Even though the string is only one character, the &amp;lt;tt&amp;gt;new&amp;lt;/tt&amp;gt; operator guarantees the rest of the array will be zeroed as well.&lt;br /&gt;
&lt;br /&gt;
Also note, it is valid to explicitly initialize a &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; '''ONLY''' with strings:&lt;br /&gt;
&amp;lt;pawn&amp;gt;decl String:blah[512] = &amp;quot;a&amp;quot;;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, any other tag will fail to compile, because the purpose of &amp;lt;tt&amp;gt;decl&amp;lt;/tt&amp;gt; is to avoid any initialization:&lt;br /&gt;
&amp;lt;pawn&amp;gt;decl Float:blah[512] = {1.0};&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==static==&lt;br /&gt;
The &amp;lt;tt&amp;gt;static&amp;lt;/tt&amp;gt; keyword is available at global and local scope.  It has different meanings in each.&lt;br /&gt;
&lt;br /&gt;
===Global static===&lt;br /&gt;
A global static variable can only be accessed from within the same file.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;//file1.inc&lt;br /&gt;
static Float:g_value1 = 0.15f;&lt;br /&gt;
&lt;br /&gt;
//file2.inc&lt;br /&gt;
static Float:g_value2 = 0.15f;&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a plugin includes both of these files, it will not be able to use either &amp;lt;tt&amp;gt;g_value1&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;g_value2&amp;lt;/tt&amp;gt;.  This is a simple information hiding mechanism, and is similar to declaring member variables as &amp;lt;tt&amp;gt;private&amp;lt;/tt&amp;gt; in languages like C++, Java, or C#.&lt;br /&gt;
&lt;br /&gt;
===Local static===&lt;br /&gt;
A local static variable is a global variable that is only visible from its local lexical scope.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
MyFunction(inc)&lt;br /&gt;
{&lt;br /&gt;
   static counter = -1;&lt;br /&gt;
&lt;br /&gt;
   counter += inc;&lt;br /&gt;
&lt;br /&gt;
   return counter;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, &amp;lt;tt&amp;gt;counter&amp;lt;/tt&amp;gt; is technically a global variable -- it is initialized once to -1 and is never initialized again.  It does not exist on the stack.  That means each time &amp;lt;tt&amp;gt;MyFunction&amp;lt;/tt&amp;gt; runs, the &amp;lt;tt&amp;gt;counter&amp;lt;/tt&amp;gt; variable and its storage in memory is the same.&lt;br /&gt;
&lt;br /&gt;
Take this example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;MyFunction(5);&lt;br /&gt;
MyFunction(6);&lt;br /&gt;
MyFunction(10);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, &amp;lt;tt&amp;gt;counter&amp;lt;/tt&amp;gt; will be &amp;lt;tt&amp;gt;-1 + 5 + 6 + 10&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;20&amp;lt;/tt&amp;gt;, because it persists beyond the frame of the function.  Note this may pose problems for recursive functions: if your function may be recursive, then &amp;lt;tt&amp;gt;static&amp;lt;/tt&amp;gt; is usually not a good idea unless your code is re-entrant.  &lt;br /&gt;
&lt;br /&gt;
The benefit of a local static variable is that you don't have to clutter your script with global variables.  As long as the variable doesn't need to be read by another function, you can squirrel it inside the function and its persistence will be guaranteed.&lt;br /&gt;
&lt;br /&gt;
Note that statics can exist in any local scope:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;&lt;br /&gt;
MyFunction(inc)&lt;br /&gt;
{&lt;br /&gt;
   if (inc &amp;gt; 0)&lt;br /&gt;
   {&lt;br /&gt;
      static counter;&lt;br /&gt;
      return (counter += inc);&lt;br /&gt;
   }&lt;br /&gt;
   return -1;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Scripting]]&lt;br /&gt;
&lt;br /&gt;
{{LanguageSwitch}}&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Porting_to_Orange_Box&amp;diff=7692</id>
		<title>Porting to Orange Box</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Porting_to_Orange_Box&amp;diff=7692"/>
		<updated>2010-05-01T11:03:11Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__FORCETOC__&lt;br /&gt;
Porting Valve Server Plugins or Metamod:Source plugins to Orange Box is not very difficult.  This article explores some of the changes and how to simplify them.&lt;br /&gt;
&lt;br /&gt;
Users of Metamod:Source should upgrade to Metamod:Source 1.7 and use the 1.6+ API (see [[MM:S API Differences]]).&lt;br /&gt;
&lt;br /&gt;
This document will assume a single preprocessor macro, &amp;lt;tt&amp;gt;ORANGEBOX_BUILD&amp;lt;/tt&amp;gt;, determines that an Orange Box build is being made.&lt;br /&gt;
&lt;br /&gt;
=Command Callbacks=&lt;br /&gt;
In the original Half-Life 2 engine, all commands used &amp;lt;tt&amp;gt;IVEngineServer::Cmd_Arg*&amp;lt;/tt&amp;gt; in order to receive information about the current command's tokenization.  However, these functions have been completely removed, and a new re-entrant version is in place.&lt;br /&gt;
&lt;br /&gt;
Each of the following callbacks:&lt;br /&gt;
&amp;lt;cpp&amp;gt;void IServerGameClients::ClientCommand(edict_t *pEdict);&lt;br /&gt;
typedef void (*FnCommandCallback)(void);&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Is now:&lt;br /&gt;
&amp;lt;cpp&amp;gt;void IServerGameClients::ClientCommand(edict_t *pEdict, const CCommand &amp;amp;args);&lt;br /&gt;
typedef void (*FnCommandCallback)(const CCommand &amp;amp;args);&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Definitions for &amp;lt;tt&amp;gt;CCommand&amp;lt;/tt&amp;gt; can be found in &amp;lt;tt&amp;gt;convar.h&amp;lt;/tt&amp;gt;.  A simple way to work around this change is to use wrapper functions.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
#if defined ORANGEBOX_BUILD&lt;br /&gt;
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &amp;amp;);&lt;br /&gt;
#else&lt;br /&gt;
SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if !defined ORANGEBOX_BUILD&lt;br /&gt;
class CCommand&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
	const char *ArgS()&lt;br /&gt;
	{&lt;br /&gt;
		return engine-&amp;gt;Cmd_Args();&lt;br /&gt;
	}&lt;br /&gt;
	int ArgC()&lt;br /&gt;
	{&lt;br /&gt;
		return engine-&amp;gt;Cmd_Argc();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	const char *Arg(int index)&lt;br /&gt;
	{&lt;br /&gt;
		return engine-&amp;gt;Cmd_Argv(index);&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined ORANGEBOX_BUILD&lt;br /&gt;
void Hook_ClientCommand(edict_t *pEntity, const CCommand &amp;amp;args)&lt;br /&gt;
#else&lt;br /&gt;
void Hook_ClientCommand(edict_t *pEntity)&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
#if !defined ORANGEBOX_BUILD&lt;br /&gt;
	CCommand args;&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
	const char *cmd = args.Arg(0);&lt;br /&gt;
	/* ... stuff ... */&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=ConCommandBaseMgr Removed=&lt;br /&gt;
ConCommandBaseMgr has been removed.  That means the normal call, &amp;lt;tt&amp;gt;ConCommandBaseMgr::OneTimeInit()&amp;lt;/tt&amp;gt;, is no longer applicable.  There are two other solutions to registering your ConVars and ConCommands:&lt;br /&gt;
*Use &amp;lt;tt&amp;gt;ConVar_Register&amp;lt;/tt&amp;gt; instead.&lt;br /&gt;
*Use &amp;lt;tt&amp;gt;META_REGCVAR&amp;lt;/tt&amp;gt; on each pointer (it will work on any ConCommandBase *) pointer, or &amp;lt;tt&amp;gt;META_REGCMD&amp;lt;/tt&amp;gt; on each individual command name.&lt;br /&gt;
&lt;br /&gt;
It is highly recommended that Metamod:Source plugins go through Metamod:Source's ConCommandBase registration process.  This will make your plugin more compatible across engines and other plugins.  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
class BaseAccessor : public IConCommandBaseAccessor&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
	bool RegisterConCommandBase(ConCommandBase *pVar)&lt;br /&gt;
	{&lt;br /&gt;
		META_REGCVAR(pVar);&lt;br /&gt;
	}&lt;br /&gt;
} s_BaseAccessor;&lt;br /&gt;
&lt;br /&gt;
void SetupEverything()&lt;br /&gt;
{&lt;br /&gt;
#if defined ORANGEBOX_BUILD&lt;br /&gt;
	/* NOTE! g_pCvar must be set to a valid ICvar instance first. */&lt;br /&gt;
	ConVar_Register(0, &amp;amp;s_BaseAccessor);&lt;br /&gt;
#else&lt;br /&gt;
	ConCommandBaseMgr::OneTimeInit(&amp;amp;s_BaseAccessor);&lt;br /&gt;
#endif&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that Valve Server Plugins can pass &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt; to use the default accessor.  '''Metamod:Source plugins should not do this.'''  Otherwise, Metamod:Source will not be able to keep track of the ConCommandBase allocations per-plugin.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Renamings/Removals=&lt;br /&gt;
*&amp;lt;tt&amp;gt;VENGINE_CVAR_INTERFACE_VERSION&amp;lt;/tt&amp;gt; was renamed to &amp;lt;tt&amp;gt;CVAR_INTERFACE_VERSION&amp;lt;/tt&amp;gt;.&lt;br /&gt;
*&amp;lt;tt&amp;gt;FCVAR_PLUGIN&amp;lt;/tt&amp;gt; was removed.  It is probably no longer needed with the advent of &amp;lt;tt&amp;gt;ConVar_Unregister&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Sample Port=&lt;br /&gt;
An example of a plugin that fully supports both versions is [http://www.bailopan.net/stripper Stripper:Source] ([http://svn.alliedmods.net/viewvc.cgi/sourcemm/stripper/?root=dvander SVN here]).  &lt;br /&gt;
&lt;br /&gt;
Note that this plugin uses the new &amp;quot;extended loading&amp;quot; API available in Metamod:Source 1.6.0.  The thin-loader library runs on any Metamod:Source version, and will correctly pick one of 6 child plugins to load.  This allows Stripper:Source to be distributed as one package with no configuration hassle.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Metamod:Source Development]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Creating_Natives_(SourceMod_Scripting)&amp;diff=7685</id>
		<title>Creating Natives (SourceMod Scripting)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Creating_Natives_(SourceMod_Scripting)&amp;diff=7685"/>
		<updated>2010-04-26T17:45:43Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: Changed AskPluginLoad to AskPluginLoad2.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SourceMod allows plugins to create their own natives that other plugins can use.  This is very similar to AMX Mod X's {{amxx_func|register_native}} function.  It is a powerful inter-plugin communication resource that can greatly enhance the functionality you provide.&lt;br /&gt;
&lt;br /&gt;
''Prerequisites:'' You should have a good grasp of Pawn or SourcePawn scripting, as well as how [[Tags (Scripting)|Tags]] work.&amp;lt;br&amp;gt;&lt;br /&gt;
''Note:'' Most functions herein can be found in the [[SourceMod SDK]], under &amp;lt;tt&amp;gt;plugins/include/functions.inc&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before creating natives, you should always document and specify exactly how they will work.  This means writing your &amp;quot;include file&amp;quot; beforehand.  Not only does this guide you in writing your natives, but it has the added benefit of completing a large portion of documentation at the same time.&lt;br /&gt;
&lt;br /&gt;
==Include File==&lt;br /&gt;
For our first example, let's start off with a simple native that adds two numbers, a float and a non-float.  It might look like this:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/** Double-include prevention */&lt;br /&gt;
#if defined _mynatives_included_&lt;br /&gt;
  #endinput&lt;br /&gt;
#endif&lt;br /&gt;
#define _mynatives_included_&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Adds two numbers together.&lt;br /&gt;
 *&lt;br /&gt;
 * @param num1    An integer.&lt;br /&gt;
 * @param num2    A float.&lt;br /&gt;
 * @return        The float value of the integer and float added together.&lt;br /&gt;
 */&lt;br /&gt;
native Float:My_AddNumbers(num1, num2);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The documentation and commenting style above is a SourceMod Development Team convention.  While you are not required to follow it for your own code, it may be a good idea to enhance readability (as readers will expect the style to conform).&lt;br /&gt;
&lt;br /&gt;
==Creating the Native==&lt;br /&gt;
To actually create the native, first let's define the native handler itself.  From &amp;lt;tt&amp;gt;functions.inc&amp;lt;/tt&amp;gt; we can see that this follows the prototype:&lt;br /&gt;
&amp;lt;pawn&amp;gt;functag NativeCall public(Handle:plugin, numParams);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, we have a function like:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Native_My_AddNumbers(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we don't use the same function name as we did in our include file.  This is to prevent a possible ''name clash''.  Otherwise, two different symbols (one a native, another a function) could have the same name, and that's not allowed.  We'll see later how we bind the native to its actual name.&lt;br /&gt;
&lt;br /&gt;
Next, we need to implement our native.  &lt;br /&gt;
&amp;lt;pawn&amp;gt;public Native_My_AddNumbers(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   /* Retrieve the first parameter we receive */&lt;br /&gt;
   new num1 = GetNativeCell(1)&lt;br /&gt;
   /* Retrieve the second parameter we receive */&lt;br /&gt;
   new Float:num2 = Float:GetNativeCell(2)&lt;br /&gt;
   /* Add them together */&lt;br /&gt;
   new Float:value = num1 + num2&lt;br /&gt;
   /* Return the value */&lt;br /&gt;
   return _:value&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should note four important details.  The first is that we have to manually grab the parameters -- they're not easily sent via arguments.  This is for technical reasons that go beyond the scope of this document.  That means you have to know exactly ''how'' to grab each parameter.  For our example, we know that both parameters are simply cells, and thus we can use &amp;lt;tt&amp;gt;GetNativeCell&amp;lt;/tt&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
However, the second detail is that there is no &amp;lt;tt&amp;gt;GetNativeCellFloat&amp;lt;/tt&amp;gt;.  This is because a &amp;lt;tt&amp;gt;Float&amp;lt;/tt&amp;gt; is still a cell; the data is just interpreted differently.  Thus, we ''change'' the tag to &amp;lt;tt&amp;gt;Float&amp;lt;/tt&amp;gt; manual.  '''This is different from calling float(GetNativeCell(2)).'''  In fact, that would not work; the &amp;lt;tt&amp;gt;float()&amp;lt;/tt&amp;gt; call would interpret the cell as an integer, when in fact it's already a float, just with the wrong tag (i.e., no tag at all).&lt;br /&gt;
&lt;br /&gt;
Similarly, the third detail is that we cannot simply put &amp;lt;tt&amp;gt;return value&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;return FloatRound(value)&amp;lt;/tt&amp;gt;.  The reason is that our native is supposed to be returning a float.  If we return &amp;lt;tt&amp;gt;value&amp;lt;/tt&amp;gt;, we'll get a tag mismatch.  If we return &amp;lt;tt&amp;gt;FloatRound(value)&amp;lt;/tt&amp;gt;, we'll be returning an integer when a float is expected.  The solution is to change the tag to the default tag, which will retain the value but remove the tag warning.&lt;br /&gt;
&lt;br /&gt;
Lastly, we did not need to verify &amp;lt;tt&amp;gt;numParams&amp;lt;/tt&amp;gt;.  The compiler will always send the correct amount of parameters - the user can't mess this up in any easy way.  Only if you use variadic arguments, or add parameters and need to support older binaries, do you need to handle &amp;lt;tt&amp;gt;numParams&amp;lt;/tt&amp;gt; variations.&lt;br /&gt;
&lt;br /&gt;
==Registering the Native==&lt;br /&gt;
Natives must be registered in &amp;lt;tt&amp;gt;AskPluginLoad&amp;lt;/tt&amp;gt;.  Although they can be registered elsewhere, only this function guarantees that all other plugins will see your native.  The definition for this forward is in &amp;lt;tt&amp;gt;sourcemod.inc&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)&lt;br /&gt;
{&lt;br /&gt;
   CreateNative(&amp;quot;My_AddNumbers&amp;quot;, Native_My_AddNumbers);&lt;br /&gt;
   return APLRes_Success;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, any plugin will be able to use our native as if it were from a Core or a C++ extension.&lt;br /&gt;
&lt;br /&gt;
=Usage=&lt;br /&gt;
==By-Reference==&lt;br /&gt;
Sometimes, it may be desirable to return data through by-reference parameters.  For example, observe the following native prototype:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Closes a Handle, and sets the variable to INVALID_HANDLE by reference.&lt;br /&gt;
 *&lt;br /&gt;
 * @param hndl     Handle to close and clear.&lt;br /&gt;
 * @return         Anything that CloseHandle() returns.&lt;br /&gt;
 */&lt;br /&gt;
native bool:AltCloseHandle(&amp;amp;Handle:hndl);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An implementation of this would look like:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Native_AltCloseHandle(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   new Handle:hndl = Handle:GetNativeCellRef(1);&lt;br /&gt;
   SetNativeCellRef(1, 0);   /* Zero out the variable by reference */&lt;br /&gt;
   return CloseHandle(hndl);&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, we have a native that is &amp;quot;safer&amp;quot; than a normal &amp;lt;tt&amp;gt;CloseHandle&amp;lt;/tt&amp;gt;, as it ensures we don't hold onto invalid Handles.&lt;br /&gt;
&lt;br /&gt;
==Strings==&lt;br /&gt;
Strings can be retrieved and altered via dynamic natives.  Observe the following native prototype:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Converts a string to upper case.&lt;br /&gt;
 *&lt;br /&gt;
 * @param str      String to convert.&lt;br /&gt;
 * @noreturn&lt;br /&gt;
 */&lt;br /&gt;
native StringToUpper(String:str[]);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An implementation of this is very easy, because of dynamic arrays:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Native_StringToUpper(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   new len&lt;br /&gt;
   GetNativeStringLength(1, len)&lt;br /&gt;
&lt;br /&gt;
   if (len &amp;lt;= 0)&lt;br /&gt;
   {&lt;br /&gt;
      return&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   new String:str[len+1]&lt;br /&gt;
   GetNativeString(1, str, len+1)&lt;br /&gt;
&lt;br /&gt;
   for (new i=0; i&amp;lt;len; i++)&lt;br /&gt;
   {&lt;br /&gt;
      /* 5th bit specifies case in ASCII -- &lt;br /&gt;
       * this is not UTF-8 compatible.&lt;br /&gt;
       */&lt;br /&gt;
      if ((str[i] &amp;amp; (1&amp;lt;&amp;lt;5)) == (1&amp;lt;&amp;lt;5))&lt;br /&gt;
      {&lt;br /&gt;
         str[i] &amp;amp;= ~(1&amp;lt;&amp;lt;5)&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   SetNativeString(1, str, len+1, false)&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Arrays==&lt;br /&gt;
Working with arrays is very similar to strings.  For example, observe the following native prototype:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Sums an array of numbers and returns the sum.&lt;br /&gt;
 *&lt;br /&gt;
 * @param array     Array of numbers to sum.&lt;br /&gt;
 * @param size      Size of array.&lt;br /&gt;
 * @return          Sum of the array elements.&lt;br /&gt;
 */&lt;br /&gt;
native SumArray(const array[], size);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An implementation of this could look like:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Native_SumArray(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   new size = GetNativeCell(2)&lt;br /&gt;
   if (size &amp;lt; 1)&lt;br /&gt;
   {&lt;br /&gt;
      return 0&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   new array[size], total&lt;br /&gt;
   GetNativeArray(1, array, size)&lt;br /&gt;
&lt;br /&gt;
   for (new i=0; i&amp;lt;size; i++)&lt;br /&gt;
   {&lt;br /&gt;
      total += array[i]&lt;br /&gt;
   }&lt;br /&gt;
   return total&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, there is a &amp;lt;tt&amp;gt;SetNativeArray&amp;lt;/tt&amp;gt;, which is used to alter array contents.&lt;br /&gt;
&lt;br /&gt;
==Variable Arguments==&lt;br /&gt;
Variable arguments are usually used when dealing with [[Format Class Functions (SourceMod Scripting)|format class functions]], however it is also possible to use them for general functionality.  The only trick is that unlike normal parameters, every variable argument parameter is passed by-reference.  This adds no change for arrays and strings, but for floats, handles, numbers, or anything else that fits in a cell, &amp;lt;tt&amp;gt;GetNativeCellRef&amp;lt;/tt&amp;gt; must be used instead.&lt;br /&gt;
&lt;br /&gt;
As an example, let's convert our function from above to use variable arguments:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Sums a list of numbers.&lt;br /&gt;
 *&lt;br /&gt;
 * @param num    First number to use as a base.&lt;br /&gt;
 * @param ...    Any number of additional numbers to add.&lt;br /&gt;
 * @return       Sum of all numbers passed.&lt;br /&gt;
 */&lt;br /&gt;
native SumParams(num, ...);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An implementation of this would look like:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Native_SumParams(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   new base = GetNativeCell(1)&lt;br /&gt;
   for (new i=2; i&amp;lt;=numParams; i++)&lt;br /&gt;
   {&lt;br /&gt;
      base += GetNativeCellRef(i)&lt;br /&gt;
   }&lt;br /&gt;
   return base&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Format Functions==&lt;br /&gt;
It is also possible to create your own [[Format Class Functions (SourceMod Scripting)|format class functions]].  This topic is much more complicated than the previous ones, as the native string formatter allows for many different configurations.  This is mainly for optimization.  Note that a formatting routine deals with two buffers: the input format string, and the output buffer.  &amp;lt;tt&amp;gt;FormatNativeString&amp;lt;/tt&amp;gt;, by default, uses parameter indexes directly so you don't have to copy or locally store any of these buffers.&lt;br /&gt;
&lt;br /&gt;
The most common usage of this is to accept a user-formatted string and to not&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Prints a message with a [DEBUG] prefix to the server.&lt;br /&gt;
 *&lt;br /&gt;
 * @param fmt         Format string.&lt;br /&gt;
 * @param ...         Format arguments.&lt;br /&gt;
 */&lt;br /&gt;
native DebugPrint(const String:fmt[], any:...);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This could be easily implemented as:&lt;br /&gt;
&amp;lt;pawn&amp;gt;native DebugPrint(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   decl String:buffer[1024], written&lt;br /&gt;
&lt;br /&gt;
   FormatNativeString(0, /* Use an output buffer */&lt;br /&gt;
      1, /* Format param */&lt;br /&gt;
      2, /* Format argument #1 */&lt;br /&gt;
      sizeof(buffer), /* Size of output buffer */&lt;br /&gt;
      written, /* Store # of written bytes */&lt;br /&gt;
      buffer /* Use our buffer */&lt;br /&gt;
      )&lt;br /&gt;
   &lt;br /&gt;
   PrintToServer(&amp;quot;[DEBUG] %s&amp;quot;, buffer)&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Throwing Errors==&lt;br /&gt;
Often, your native will encounter an unrecoverable error, and you wish to trigger a fatal exception.  This is equivalent to &amp;lt;tt&amp;gt;IPluginContext::ThrowNativeError&amp;lt;/tt&amp;gt;, and will halt the current function execution in the plugin.  The debugger will be invoked and a backtrace will be printed out (if the plugin is in debug mode).  Although the current function is cancelled, the plugin will continue to operate normally afterward.&lt;br /&gt;
&lt;br /&gt;
For example, let's say we have a native that operates on clients.  We want to throw an error if we get a client index that is invalid or disconnected.  We could do this like so:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public MyFunction(Handle:plugin, numParams)&lt;br /&gt;
{&lt;br /&gt;
   new client = GetNativeCell(1)&lt;br /&gt;
   if (client &amp;lt; 1 || client &amp;gt; GetMaxClients())&lt;br /&gt;
   {&lt;br /&gt;
      return ThrowNativeError(SP_ERROR_NATIVE, &amp;quot;Invalid client index (%d)&amp;quot;, client)&lt;br /&gt;
   }&lt;br /&gt;
   if (!IsClientConnected(client))&lt;br /&gt;
   {&lt;br /&gt;
      return ThrowNativeError(SP_ERROR_NATIVE, &amp;quot;Client %d is not connected&amp;quot;, client)&lt;br /&gt;
   }&lt;br /&gt;
   /* Code */&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Scripting]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Installing_SourceMod&amp;diff=7479</id>
		<title>Installing SourceMod</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Installing_SourceMod&amp;diff=7479"/>
		<updated>2010-01-02T15:58:28Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: Spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing SourceMod is very simple, and it can be added with almost no configuration changes.&lt;br /&gt;
&lt;br /&gt;
=Prerequisites=&lt;br /&gt;
A GUI Web Browser to retrieve Metamod and SourceMod compressed archives.&lt;br /&gt;
A tool to copy archive to your dedicated server host.&lt;br /&gt;
&lt;br /&gt;
SourceMod requires [[Metamod:Source]] 1.4.3 or higher. [http://www.metamodsource.net/ Click here] to visit the Metamod:Source homepage. Instructions to install SourceMM manually can be found [http://wiki.alliedmods.net/index.php/Installing_Metamod:Source here].&lt;br /&gt;
&lt;br /&gt;
SourceMod will run on any mod built using the Source SDK.  It also supports &amp;quot;The Ship,&amp;quot; which uses the Source engine.&lt;br /&gt;
&lt;br /&gt;
=Uploading/Installing=&lt;br /&gt;
==Local Server==&lt;br /&gt;
To install SourceMod locally, simply extract the &amp;lt;tt&amp;gt;.zip&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;.tar.gz&amp;lt;/tt&amp;gt; (Linux) package to your mod folder (i.e. &amp;lt;tt&amp;gt;cstrike&amp;lt;/tt&amp;gt; for Counter-Strike, &amp;lt;tt&amp;gt;dod&amp;lt;/tt&amp;gt; for Day of Defeat, et cetera).&lt;br /&gt;
[http://www.sourcemod.net/downloads.php Download Here]&lt;br /&gt;
&lt;br /&gt;
==Remote Server==&lt;br /&gt;
To install SourceMod remotely, first extract the &amp;lt;tt&amp;gt;.zip&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;.tar.gz&amp;lt;/tt&amp;gt; (Linux) package to your local computer (for example, your Desktop).  You will see an &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder.  &lt;br /&gt;
&lt;br /&gt;
Using a tool such as [http://www.google.com/search?q=FTP FTP], locate your mod folder (i.e. &amp;lt;tt&amp;gt;cstrike&amp;lt;/tt&amp;gt; for Counter-Strike:Source, &amp;lt;tt&amp;gt;dod&amp;lt;/tt&amp;gt; for Day of Defeat:Source, et cetera).  Underneath this folder, you should have an &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder (if not, Metamod:Source is probably not installed).  From your local &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder, upload the entire contents to your remote &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder.  When done, your remote &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder should have a &amp;lt;tt&amp;gt;sourcemod&amp;lt;/tt&amp;gt; folder.&lt;br /&gt;
&lt;br /&gt;
If you have trouble with these steps, you need to get acquainted with FTP and server management.  However, you can also ask your server provider for help.  Some providers also have web interfaces for managing your server.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if you copied the tar.gz to your srcds directory, execute the following from the cstrike sub directory:&lt;br /&gt;
tar -xzf ../sourcemod-1.1.0.tar.gz&lt;br /&gt;
&lt;br /&gt;
=Checking the Install=&lt;br /&gt;
Your folder layout should look like:&lt;br /&gt;
*&amp;lt;tt&amp;gt;[mod]&amp;lt;/tt&amp;gt; - Your mod's folder&lt;br /&gt;
**&amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt;&lt;br /&gt;
***&amp;lt;tt&amp;gt;metamod&amp;lt;/tt&amp;gt; - Metamod:Source&lt;br /&gt;
***&amp;lt;tt&amp;gt;sourcemod&amp;lt;/tt&amp;gt; - SourceMod&lt;br /&gt;
&lt;br /&gt;
Once SourceMod is uploaded/copied and configured with Metamod:Source, restart your server completely.  If it is local, shut it down and restart it.  If it is remote, you may need to ask your server provider for help.  However, it is often safe to issue a &amp;quot;quit&amp;quot; command via [[rcon]], since most providers will automatically restart your server.&lt;br /&gt;
&lt;br /&gt;
First, in your [[server console]] (not client console), type:&lt;br /&gt;
&amp;lt;pre&amp;gt;meta list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the install worked, you will see something like:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
Listing 1 plugin:&lt;br /&gt;
    [01] SourceMod (1.1.0.2489) by AlliedModders LLC&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should then be able to use the SourceMod root console command, which can be invoked with simply:&lt;br /&gt;
&amp;lt;pre&amp;gt;sm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;] sm version&lt;br /&gt;
 SourceMod Version Information:&lt;br /&gt;
    SourceMod Version: 1.1.0.2489&lt;br /&gt;
    SourcePawn Engine: SourcePawn 1.1, jit-x86 (build 1.1.0-svn)&lt;br /&gt;
    SourcePawn API: v1 = 4, v2 = 2&lt;br /&gt;
    Compiled on: Sep  5 2008 02:02:12&lt;br /&gt;
    http://www.sourcemod.net/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lastly, assuming you have already setup your administration user, you can test the in game menu by joining the server, and in the client console type the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;sm_admin&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a menu popup with all you options.&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If the install failed, you will generally see one of four symptoms.  &lt;br /&gt;
&lt;br /&gt;
==Metamod reports NOFILE or FAILED==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; replies with something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
-Id- Name                  Version     Author           Status  &lt;br /&gt;
[01] -                     -           -                NOFILE  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most likely, either the files are not located in the correct place, or the file could not be loaded.  For more information, use the following command (except use the correct list number):&lt;br /&gt;
&amp;lt;pre&amp;gt;meta list 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Metamod lists no plugins==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; replies with something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
-Id- Name                  Version     Author           Status  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You forgot to add SourceMod to the &amp;lt;tt&amp;gt;addons/metamod/metaplugins.ini&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
Or if that doesn't fix your problem, make sure you are using the correct build of Sourcemod (zip = windows, tar = linux).&lt;br /&gt;
&lt;br /&gt;
==Metamod says nothing==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; has no reply at all, Metamod:Source is not properly installed. [http://wiki.alliedmods.net/index.php/Installing_SourceMM This wiki page] may provide you with clues on how to solve this problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Documentation]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Installing_SourceMod&amp;diff=7478</id>
		<title>Installing SourceMod</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Installing_SourceMod&amp;diff=7478"/>
		<updated>2010-01-02T15:57:13Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing SourceMod is very simple, and it can be added with almost no configuration changes.&lt;br /&gt;
&lt;br /&gt;
=Prerequisites=&lt;br /&gt;
A GUI Web Browser to retrieve Metamod and SourceMod compressed archives.&lt;br /&gt;
A tool to copy archive to your dedicated server host.&lt;br /&gt;
&lt;br /&gt;
SourceMod requires [[Metamod:Source]] 1.4.3 or higher. [http://www.metamodsource.net/ Click here] to visit the Metamod:Source homepage. Instructions to install SourceMM manually can be found [http://wiki.alliedmods.net/index.php/Installing_Metamod:Source here].&lt;br /&gt;
&lt;br /&gt;
SourceMod will run on any mod built using the Source SDK.  It also supports &amp;quot;The Ship,&amp;quot; which uses the Source engine.&lt;br /&gt;
&lt;br /&gt;
=Uploading/Installing=&lt;br /&gt;
==Local Server==&lt;br /&gt;
To install SourceMod locally, simply extract the &amp;lt;tt&amp;gt;.zip&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;.tar.gz&amp;lt;/tt&amp;gt; (Linux) package to your mod folder (i.e. &amp;lt;tt&amp;gt;cstrike&amp;lt;/tt&amp;gt; for Counter-Strike, &amp;lt;tt&amp;gt;dod&amp;lt;/tt&amp;gt; for Day of Defeat, et cetera).&lt;br /&gt;
[http://www.sourcemod.net/downloads.php Download Here]&lt;br /&gt;
&lt;br /&gt;
==Remote Server==&lt;br /&gt;
To install SourceMod remotely, first extract the &amp;lt;tt&amp;gt;.zip&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;.tar.gz&amp;lt;/tt&amp;gt; (Linux) package to your local computer (for example, your Desktop).  You will see an &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder.  &lt;br /&gt;
&lt;br /&gt;
Using a tool such as [http://www.google.com/search?q=FTP FTP], locate your mod folder (i.e. &amp;lt;tt&amp;gt;cstrike&amp;lt;/tt&amp;gt; for Counter-Strike:Source, &amp;lt;tt&amp;gt;dod&amp;lt;/tt&amp;gt; for Day of Defeat:Source, et cetera).  Underneath this folder, you should have an &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder (if not, Metamod:Source is probably not installed).  From your local &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder, upload the entire contents to your remote &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder.  When done, your remote &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder should have a &amp;lt;tt&amp;gt;sourcemod&amp;lt;/tt&amp;gt; folder.&lt;br /&gt;
&lt;br /&gt;
If you have trouble with these steps, you need to get acquainted with FTP and server management.  However, you can also ask your server provider for help.  Some providers also have web interfaces for managing your server.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if you copied the tar.gz to your srcds directory, execute the following from the cstrike sub directory:&lt;br /&gt;
tar -xzf ../sourcemod-1.1.0.tar.gz&lt;br /&gt;
&lt;br /&gt;
=Checking the Install=&lt;br /&gt;
Your folder layout should look like:&lt;br /&gt;
*&amp;lt;tt&amp;gt;[mod]&amp;lt;/tt&amp;gt; - Your mod's folder&lt;br /&gt;
**&amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt;&lt;br /&gt;
***&amp;lt;tt&amp;gt;metamod&amp;lt;/tt&amp;gt; - Metamod:Source&lt;br /&gt;
***&amp;lt;tt&amp;gt;sourcemod&amp;lt;/tt&amp;gt; - SourceMod&lt;br /&gt;
&lt;br /&gt;
Once SourceMod is uploaded/copied and configured with Metamod:Source, restart your server completely.  If it is local, shut it down and restart it.  If it is remote, you may need to ask your server provider for help.  However, it is often safe to issue a &amp;quot;quit&amp;quot; command via [[rcon]], and most providers will automatically restart your server.&lt;br /&gt;
&lt;br /&gt;
First, in your [[server console]] (not client console), type:&lt;br /&gt;
&amp;lt;pre&amp;gt;meta list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the install worked, you will see something like:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
Listing 1 plugin:&lt;br /&gt;
    [01] SourceMod (1.1.0.2489) by AlliedModders LLC&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should then be able to use the SourceMod root console command, which can be invoked with simply:&lt;br /&gt;
&amp;lt;pre&amp;gt;sm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;] sm version&lt;br /&gt;
 SourceMod Version Information:&lt;br /&gt;
    SourceMod Version: 1.1.0.2489&lt;br /&gt;
    SourcePawn Engine: SourcePawn 1.1, jit-x86 (build 1.1.0-svn)&lt;br /&gt;
    SourcePawn API: v1 = 4, v2 = 2&lt;br /&gt;
    Compiled on: Sep  5 2008 02:02:12&lt;br /&gt;
    http://www.sourcemod.net/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lastly, assuming you have already setup your administration user, you can test the in game menu by joining the server, and in the client console type the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;sm_admin&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a menu popup with all you options.&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If the install failed, you will generally see one of four symptoms.  &lt;br /&gt;
&lt;br /&gt;
==Metamod reports NOFILE or FAILED==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; replies with something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
-Id- Name                  Version     Author           Status  &lt;br /&gt;
[01] -                     -           -                NOFILE  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most likely, either the files are not located in the correct place, or the file could not be loaded.  For more information, use the following command (except use the correct list number):&lt;br /&gt;
&amp;lt;pre&amp;gt;meta list 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Metamod lists no plugins==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; replies with something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
-Id- Name                  Version     Author           Status  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You forgot to add SourceMod to the &amp;lt;tt&amp;gt;addons/metamod/metaplugins.ini&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
Or if that doesn't fix your problem, make sure you are using the correct build of Sourcemod (zip = windows, tar = linux).&lt;br /&gt;
&lt;br /&gt;
==Metamod says nothing==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; has no reply at all, Metamod:Source is not properly installed. [http://wiki.alliedmods.net/index.php/Installing_SourceMM This wiki page] may provide you with clues on how to solve this problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Documentation]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Installing_SourceMod&amp;diff=7477</id>
		<title>Installing SourceMod</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Installing_SourceMod&amp;diff=7477"/>
		<updated>2010-01-02T15:56:21Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing SourceMod is very simple, and it can be added with almost no configuration changes.&lt;br /&gt;
&lt;br /&gt;
=Prerequisites=&lt;br /&gt;
A GUI Web Browser to retrieve Metamod and SourceMod compressed archives.&lt;br /&gt;
A tool to copy archive to your dedicated server host.&lt;br /&gt;
&lt;br /&gt;
SourceMod requires [[Metamod:Source]] 1.4.3 or higher. [http://www.metamodsource.net/ Click here] to visit the Metamod:Source homepage. Instructions to install SourceMM muanually can be found [http://wiki.alliedmods.net/index.php/Installing_Metamod:Source here].&lt;br /&gt;
&lt;br /&gt;
SourceMod will run on any mod built using the Source SDK.  It also supports &amp;quot;The Ship,&amp;quot; which uses the Source engine.&lt;br /&gt;
&lt;br /&gt;
=Uploading/Installing=&lt;br /&gt;
==Local Server==&lt;br /&gt;
To install SourceMod locally, simply extract the &amp;lt;tt&amp;gt;.zip&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;.tar.gz&amp;lt;/tt&amp;gt; (Linux) package to your mod folder (i.e. &amp;lt;tt&amp;gt;cstrike&amp;lt;/tt&amp;gt; for Counter-Strike, &amp;lt;tt&amp;gt;dod&amp;lt;/tt&amp;gt; for Day of Defeat, et cetera).&lt;br /&gt;
[http://www.sourcemod.net/downloads.php Download Here]&lt;br /&gt;
&lt;br /&gt;
==Remote Server==&lt;br /&gt;
To install SourceMod remotely, first extract the &amp;lt;tt&amp;gt;.zip&amp;lt;/tt&amp;gt; (Windows) or &amp;lt;tt&amp;gt;.tar.gz&amp;lt;/tt&amp;gt; (Linux) package to your local computer (for example, your Desktop).  You will see an &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder.  &lt;br /&gt;
&lt;br /&gt;
Using a tool such as [http://www.google.com/search?q=FTP FTP], locate your mod folder (i.e. &amp;lt;tt&amp;gt;cstrike&amp;lt;/tt&amp;gt; for Counter-Strike:Source, &amp;lt;tt&amp;gt;dod&amp;lt;/tt&amp;gt; for Day of Defeat:Source, et cetera).  Underneath this folder, you should have an &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder (if not, Metamod:Source is probably not installed).  From your local &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder, upload the entire contents to your remote &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder.  When done, your remote &amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt; folder should have a &amp;lt;tt&amp;gt;sourcemod&amp;lt;/tt&amp;gt; folder.&lt;br /&gt;
&lt;br /&gt;
If you have trouble with these steps, you need to get acquainted with FTP and server management.  However, you can also ask your server provider for help.  Some providers also have web interfaces for managing your server.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if you copied the tar.gz to your srcds directory, execute the following from the cstrike sub directory:&lt;br /&gt;
tar -xzf ../sourcemod-1.1.0.tar.gz&lt;br /&gt;
&lt;br /&gt;
=Checking the Install=&lt;br /&gt;
Your folder layout should look like:&lt;br /&gt;
*&amp;lt;tt&amp;gt;[mod]&amp;lt;/tt&amp;gt; - Your mod's folder&lt;br /&gt;
**&amp;lt;tt&amp;gt;addons&amp;lt;/tt&amp;gt;&lt;br /&gt;
***&amp;lt;tt&amp;gt;metamod&amp;lt;/tt&amp;gt; - Metamod:Source&lt;br /&gt;
***&amp;lt;tt&amp;gt;sourcemod&amp;lt;/tt&amp;gt; - SourceMod&lt;br /&gt;
&lt;br /&gt;
Once SourceMod is uploaded/copied and configured with Metamod:Source, restart your server completely.  If it is local, shut it down and restart it.  If it is remote, you may need to ask your server provider for help.  However, it is often safe to issue a &amp;quot;quit&amp;quot; command via [[rcon]], and most providers will automatically restart your server.&lt;br /&gt;
&lt;br /&gt;
First, in your [[server console]] (not client console), type:&lt;br /&gt;
&amp;lt;pre&amp;gt;meta list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the install worked, you will see something like:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
Listing 1 plugin:&lt;br /&gt;
    [01] SourceMod (1.1.0.2489) by AlliedModders LLC&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should then be able to use the SourceMod root console command, which can be invoked with simply:&lt;br /&gt;
&amp;lt;pre&amp;gt;sm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;] sm version&lt;br /&gt;
 SourceMod Version Information:&lt;br /&gt;
    SourceMod Version: 1.1.0.2489&lt;br /&gt;
    SourcePawn Engine: SourcePawn 1.1, jit-x86 (build 1.1.0-svn)&lt;br /&gt;
    SourcePawn API: v1 = 4, v2 = 2&lt;br /&gt;
    Compiled on: Sep  5 2008 02:02:12&lt;br /&gt;
    http://www.sourcemod.net/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lastly, assuming you have already setup your administration user, you can test the in game menu by joining the server, and in the client console type the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;sm_admin&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a menu popup with all you options.&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If the install failed, you will generally see one of four symptoms.  &lt;br /&gt;
&lt;br /&gt;
==Metamod reports NOFILE or FAILED==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; replies with something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
-Id- Name                  Version     Author           Status  &lt;br /&gt;
[01] -                     -           -                NOFILE  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most likely, either the files are not located in the correct place, or the file could not be loaded.  For more information, use the following command (except use the correct list number):&lt;br /&gt;
&amp;lt;pre&amp;gt;meta list 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Metamod lists no plugins==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; replies with something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;] meta list&lt;br /&gt;
-Id- Name                  Version     Author           Status  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You forgot to add SourceMod to the &amp;lt;tt&amp;gt;addons/metamod/metaplugins.ini&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
Or if that doesn't fix your problem, make sure you are using the correct build of Sourcemod (zip = windows, tar = linux).&lt;br /&gt;
&lt;br /&gt;
==Metamod says nothing==&lt;br /&gt;
If &amp;quot;meta list&amp;quot; has no reply at all, Metamod:Source is not properly installed. [http://wiki.alliedmods.net/index.php/Installing_SourceMM This wiki page] may provide you with clues on how to solve this problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Documentation]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Menu_API_(SourceMod)&amp;diff=7386</id>
		<title>Menu API (SourceMod)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Menu_API_(SourceMod)&amp;diff=7386"/>
		<updated>2009-08-25T07:42:06Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: Fixed a typo in the example code.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SourceMod has an extensive API for building and displaying menus to clients.  Unlike AMX Mod X, this API is highly state driven.  Menus are based on callbacks which are guaranteed to be fired.&lt;br /&gt;
&lt;br /&gt;
For C++, the Menu API can be found in &amp;lt;tt&amp;gt;public/IMenuManager.h&amp;lt;/tt&amp;gt;.  For SourcePawn, it is in &amp;lt;tt&amp;gt;plugins/include/menus.inc&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Objects=&lt;br /&gt;
The SourceMod Menu System is based on an object oriented hierarchy.  Understanding this hierarchy, even for scripting, is critical to using menus effectively.&lt;br /&gt;
&lt;br /&gt;
==Styles==&lt;br /&gt;
The top level object is a ''MenuStyle'' (&amp;lt;tt&amp;gt;IMenuStyle&amp;lt;/tt&amp;gt; in C++).  Styles describe a unique menu system.  There are two such styles built into SourceMod:&lt;br /&gt;
*Valve Style, also called &amp;quot;ESC&amp;quot; menus; 8 items per page, no raw/disabled text can be rendered&lt;br /&gt;
*Radio Style, also called &amp;quot;AMX&amp;quot; menus; 10 items per page, raw/disabled text can be rendered&lt;br /&gt;
&lt;br /&gt;
Each MenuStyle has its own rules and properties.  You can think of them as existing on separate &amp;quot;channels.&amp;quot;  For example, two different menus can exist on a player's screen as both a Valve menu and a Radio menu at the same time, and SourceMod will be able to manage both without any problems.  This is because each style keeps track of its own menus separately.&lt;br /&gt;
&lt;br /&gt;
==Panels==&lt;br /&gt;
Menu displays are drawn with a lower level interface called ''Panels'' (&amp;lt;tt&amp;gt;IMenuPanel&amp;lt;/tt&amp;gt; in C++).  Panels describe exactly one chunk of display text.  Both selectable items and raw text can be added to a panel as long as its parent style supports the contents you're trying to draw.  For example, the Valve style does not support drawing raw text or disabled items.  But with a Radio-style Panel, you can display a large amount of on-screen data in your own format.&lt;br /&gt;
&lt;br /&gt;
Panels are considered temporary objects.  They are created, rendered, displayed, and destroyed.  Although they can be saved indefinitely, it is not necessary to do so.&lt;br /&gt;
&lt;br /&gt;
Valve Style drawing rules/limitations:&lt;br /&gt;
*Max items per page is 8.&lt;br /&gt;
*Disabled items cannot be drawn.&lt;br /&gt;
*Raw text cannot be drawn.&lt;br /&gt;
*Spacers do not add a space/newline, giving a &amp;quot;cramped&amp;quot; feel.&lt;br /&gt;
*Users must press &amp;quot;ESC&amp;quot; or be at their console to view the menu.&lt;br /&gt;
&lt;br /&gt;
Radio Style drawing rules/limitations:&lt;br /&gt;
*Max items per page is 10.&lt;br /&gt;
*Titles appear white; items appear yellow, unless disabled, in which case they are white.&lt;br /&gt;
*The 0th item is always white.  For consistency, this means navigational controls explained in the next section are always white, and simply not drawn if disabled.&lt;br /&gt;
&lt;br /&gt;
==Menus==&lt;br /&gt;
Lastly, there are plain ''Menus'' (&amp;lt;tt&amp;gt;IBaseMenu&amp;lt;/tt&amp;gt; in C++).  These are helper objects designed for storing a menu based on selectable items.  Unlike low-level panels, menus are containers for '''items''', and can only contain items which are selectable (i.e., do not contain raw text).  They fall into two categories:&lt;br /&gt;
*Non-paginated: The menu can only have a certain number of items on it, and no control/navigation options will be added, except for an &amp;quot;Exit&amp;quot; button which will always be in the last position supported by the style.&lt;br /&gt;
**Valve Style maximum items: 8&lt;br /&gt;
**Radio Style maximum items: 10&lt;br /&gt;
*Paginated: The menu can have any number of items.  When displayed, only a certain number of items will be drawn at a time.  Automatic navigation controls are added so players can easily move back and forth to different &amp;quot;pages&amp;quot; of items in the menu.&lt;br /&gt;
**&amp;quot;Previous&amp;quot; is always drawn as the first navigation item, third from the last supported position.  This will not be drawn if the menu only contains one page.  If there are no previous pages, the text will not be drawn on either style; if possible, the menu will be padded so spacing is consistent.&lt;br /&gt;
***Valve Style position: 6&lt;br /&gt;
***Radio Style position: 8&lt;br /&gt;
**&amp;quot;Next&amp;quot; is always drawn as the second navigation item, second from the last supported position.  This will not be drawn if the menu only contains one page.  If there are no further pages, the text will not be drawn on either style; if possible, the menu will be padded so spacing is consistent.&lt;br /&gt;
***Valve Style position: 7&lt;br /&gt;
***Radio Style position: 9&lt;br /&gt;
**&amp;quot;Exit&amp;quot; is drawn if the menu has the exit button property set.  It is always the last supported item position.&lt;br /&gt;
***Valve Style position: 8&lt;br /&gt;
***Radio Style position: 10&lt;br /&gt;
&lt;br /&gt;
The purpose of Menus is to simplify the procedure of storing, drawing, and calculating the selection of items.  Thus, menus do not allow for adding raw text, as that would considerably complicate the drawing algorithm.  ''Note: The C++ API supports hooking &amp;lt;tt&amp;gt;IBaseMenu&amp;lt;/tt&amp;gt; drawing procedures and adding raw text; this will be added to the scripting API soon.''&lt;br /&gt;
&lt;br /&gt;
Internally, Menus are drawn via a ''RenderMenu'' algorithm.  This algorithm creates a temporary panel and fills it with items from menus.  This panel is then displayed to a client.  The algorithm attempts to create a consistent feel across all menus, and across all styles.  Thus any menu displayed via the &amp;lt;tt&amp;gt;IBaseMenu&amp;lt;/tt&amp;gt; class, or &amp;lt;tt&amp;gt;Menu&amp;lt;/tt&amp;gt; Handles, will look and act the same, and the Menu API is based off the Panel API.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Callbacks=&lt;br /&gt;
==Overview==&lt;br /&gt;
Menus are a callback based system.  Each callback represents an action that occurs during a ''menu display cycle''.  A cycle consists of a number of notifications:&lt;br /&gt;
*Start notification.&lt;br /&gt;
**Display notification if the menu can be displayed to the client.&lt;br /&gt;
**Either an item select or menu cancel notification.&lt;br /&gt;
*End notification.&lt;br /&gt;
&lt;br /&gt;
Since ''End'' signifies the end of a full display cycle, it is usually used to destroy temporary menus.&lt;br /&gt;
&lt;br /&gt;
==Specification==&lt;br /&gt;
A detailed explanation of these events is below.  For C++, an &amp;lt;tt&amp;gt;IBaseMenu&amp;lt;/tt&amp;gt; pointer is always available.  For SourcePawn, a &amp;lt;tt&amp;gt;Menu&amp;lt;/tt&amp;gt; Handle and a &amp;lt;tt&amp;gt;MenuAction&amp;lt;/tt&amp;gt; are always set in the &amp;lt;tt&amp;gt;MenuHandler&amp;lt;/tt&amp;gt; callback.  Unlike C++, the SourcePawn API allows certain actions to only be called if they are requested at menu creation time.  This is an optimization.  However, certain actions cannot be prevented from being called.&lt;br /&gt;
&lt;br /&gt;
*'''Start'''.  The menu has been acknowledged.  This does not mean it will be displayed; however, it guarantees that &amp;quot;OnMenuEnd&amp;quot; will be called.&lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuStart()&amp;lt;/tt&amp;gt; in C++.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_Start&amp;lt;/tt&amp;gt; in SourcePawn.  This action is not triggered unless requested.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: Ignored (always 0).&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: Ignored (always 0).&lt;br /&gt;
*'''Display'''.  The menu is being displayed to a client.&lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuDisplay()&amp;lt;/tt&amp;gt; in C++.  An &amp;lt;tt&amp;gt;IMenuPanel&amp;lt;/tt&amp;gt; pointer and client index are available.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_Display&amp;lt;/tt&amp;gt; in SourcePawn.  This action is not triggered unless requested.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: A client index.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: A Handle to a menu panel.&lt;br /&gt;
*'''Select'''.  An item on the menu has been selected.  The item position given will be the position in the menu, rather than the key pressed (unless the menu is a raw panel).  &lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuSelect()&amp;lt;/tt&amp;gt; in C++.  A client index and item position are passed.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_Select&amp;lt;/tt&amp;gt; in SourcePawn.  This action is always triggerable, whether requested or not.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: A client index.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: An item position.&lt;br /&gt;
*'''Cancel'''.  The menu's display to one client has been cancelled.&lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuCancel()&amp;lt;/tt&amp;gt; in C++.  A reason for cancellation is provided.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_Cancel&amp;lt;/tt&amp;gt; in SourcePawn.  This action is always triggerable, whether requested or not.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: A client index.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: A menu cancellation reason code.&lt;br /&gt;
*'''End'''.  The menu's display cycle has finished; this means that the &amp;quot;Start&amp;quot; action has occurred, and either &amp;quot;Select&amp;quot; or &amp;quot;Cancel&amp;quot; has occurred thereafter.  This is typically where menu resources are removed/deleted.&lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuEnd()&amp;lt;/tt&amp;gt; in C++.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt; in SourcePawn.  This action is always triggered, whether requested or not.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: A menu end reason code.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: If param1 was MenuEnd_Cancelled, this contains a menu cancellation reason code.&lt;br /&gt;
&lt;br /&gt;
==Panels==&lt;br /&gt;
For panels, the callback rules change.  Panels only receive two of the above callbacks, and it is guaranteed that only one of them will be called for a given display cycle.  For C++, the &amp;lt;tt&amp;gt;IBaseMenu&amp;lt;/tt&amp;gt; pointer will always be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;.  For SourcePawn, the menu Handle will always be &amp;lt;tt&amp;gt;INVALID_HANDLE&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
*'''Select'''.  A key has been pressed.  This can be any number and should not be considered as reliably in bounds.  For example, even if you only had 2 items in your panel, a client could trigger a key press of &amp;quot;43.&amp;quot;&lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuSelect()&amp;lt;/tt&amp;gt; in C++.  A client index and key number pressed are passed.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_Select&amp;lt;/tt&amp;gt; in SourcePawn.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: A client index.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: Number of the key pressed.&lt;br /&gt;
*'''Cancel'''.  The menu's display to one client has been cancelled.&lt;br /&gt;
**&amp;lt;tt&amp;gt;OnMenuCancel()&amp;lt;/tt&amp;gt; in C++.  A reason for cancellation is provided.&lt;br /&gt;
**&amp;lt;tt&amp;gt;MenuAction_Cancel&amp;lt;/tt&amp;gt; in SourcePawn.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;: A client index.&lt;br /&gt;
***&amp;lt;tt&amp;gt;param2&amp;lt;/tt&amp;gt;: A menu cancellation reason code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
First, let's start off with a very basic menu.  We want the menu to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Do you like apples?&lt;br /&gt;
1. Yes&lt;br /&gt;
2. No&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We'll draw this menu with both a basic Menu and a Panel to show the API differences.&lt;br /&gt;
&lt;br /&gt;
==Basic Menu==&lt;br /&gt;
First, let's write our example using the Menu building API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;public OnPluginStart()&lt;br /&gt;
{&lt;br /&gt;
	RegConsoleCmd(&amp;quot;menu_test1&amp;quot;, Menu_Test1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public MenuHandler1(Handle:menu, MenuAction:action, param1, param2)&lt;br /&gt;
{&lt;br /&gt;
	/* If an option was selected, tell the client about the item. */&lt;br /&gt;
	if (action == MenuAction_Select)&lt;br /&gt;
	{&lt;br /&gt;
		new String:info[32];&lt;br /&gt;
		new bool:found = GetMenuItem(menu, param2, info, sizeof(info));&lt;br /&gt;
		PrintToConsole(param1, &amp;quot;You selected item: %d (found? %d info: %s)&amp;quot;, param2, found, info);&lt;br /&gt;
	}&lt;br /&gt;
	/* If the menu was cancelled, print a message to the server about it. */&lt;br /&gt;
	else if (action == MenuAction_Cancel)&lt;br /&gt;
	{&lt;br /&gt;
		PrintToServer(&amp;quot;Client %d's menu was cancelled.  Reason: %d&amp;quot;, param1, param2);&lt;br /&gt;
	}&lt;br /&gt;
	/* If the menu has ended, destroy it */&lt;br /&gt;
	else if (action == MenuAction_End)&lt;br /&gt;
	{&lt;br /&gt;
		CloseHandle(menu);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Action:Menu_Test1(client, args)&lt;br /&gt;
{&lt;br /&gt;
	new Handle:menu = CreateMenu(MenuHandler1);&lt;br /&gt;
	SetMenuTitle(menu, &amp;quot;Do you like apples?&amp;quot;);&lt;br /&gt;
	AddMenuItem(menu, &amp;quot;yes&amp;quot;, &amp;quot;Yes&amp;quot;);&lt;br /&gt;
	AddMenuItem(menu, &amp;quot;no&amp;quot;, &amp;quot;No&amp;quot;);&lt;br /&gt;
	SetMenuExitButton(menu, false);&lt;br /&gt;
	DisplayMenu(menu, client, 20);&lt;br /&gt;
	&lt;br /&gt;
	return Plugin_Handled;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note a few very important points from this example:&lt;br /&gt;
*One of either &amp;lt;tt&amp;gt;Select&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;Cancel&amp;lt;/tt&amp;gt; will always be sent to the action handler.&lt;br /&gt;
*&amp;lt;tt&amp;gt;End&amp;lt;/tt&amp;gt; will always be sent to the action handler.&lt;br /&gt;
*We destroy our Menu in the &amp;lt;tt&amp;gt;End&amp;lt;/tt&amp;gt; action, because our Handle is no longer needed.  If we had destroyed the Menu after &amp;lt;tt&amp;gt;DisplayMenu&amp;lt;/tt&amp;gt;, it would have canceled the menu's display to the client.&lt;br /&gt;
*Menus, by default, have an exit button.  We disabled this in our example.&lt;br /&gt;
*Our menu is set to display for 20 seconds.  That means that if the client does not select an item within 20 seconds, the menu will be canceled.  This is usually desired for menus that are for voting.  Note that unlike AMX Mod X, you do not need to set a timer to make sure the menu will be ended.&lt;br /&gt;
*Although we created and destroyed a new Menu Handle, we didn't need to.  It is perfectly acceptable to create the Handle once for the lifetime of the plugin.&lt;br /&gt;
&lt;br /&gt;
Our finished menu and attached console output looks like this (I selected &amp;quot;Yes&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
[[Image:Basic_menu_1.PNG]]&lt;br /&gt;
&lt;br /&gt;
==Basic Panel==&lt;br /&gt;
Now, let's rewrite our example to use Panels instead.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;public OnPluginStart()&lt;br /&gt;
{&lt;br /&gt;
	RegConsoleCmd(&amp;quot;panel_test1&amp;quot;, Panel_Test1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public PanelHandler1(Handle:menu, MenuAction:action, param1, param2)&lt;br /&gt;
{&lt;br /&gt;
	if (action == MenuAction_Select)&lt;br /&gt;
	{&lt;br /&gt;
		PrintToConsole(param1, &amp;quot;You selected item: %d&amp;quot;, param2);&lt;br /&gt;
	} else if (action == MenuAction_Cancel) {&lt;br /&gt;
		PrintToServer(&amp;quot;Client %d's menu was cancelled.  Reason: %d&amp;quot;, param1, param2);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Action:Panel_Test1(client, args)&lt;br /&gt;
{&lt;br /&gt;
	new Handle:panel = CreatePanel();&lt;br /&gt;
	SetPanelTitle(panel, &amp;quot;Do you like apples?&amp;quot;);&lt;br /&gt;
	DrawPanelItem(panel, &amp;quot;Yes&amp;quot;);&lt;br /&gt;
	DrawPanelItem(panel, &amp;quot;No&amp;quot;);&lt;br /&gt;
		&lt;br /&gt;
	SendPanelToClient(panel, client, PanelHandler1, 20);&lt;br /&gt;
&lt;br /&gt;
	CloseHandle(panel);&lt;br /&gt;
	&lt;br /&gt;
	return Plugin_Handled;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, Panels are significantly different.&lt;br /&gt;
*We can destroy the Panel as soon as we're done displaying it.  We can create the Panel once and keep re-using it, but we can destroy it at any time without interrupting client menus.&lt;br /&gt;
*The Handler function gets much less data.  Since panels are designed as a raw display, no &amp;quot;item&amp;quot; information is saved internally.  Thus, the handler function only knows whether the display was canceled or whether (and what) numerical key was pressed.&lt;br /&gt;
*There is no automation.  You cannot add more than a certain amount of selectable items to a Panel and get pagination.  Automated control functionality requires using the heftier Menu object API.&lt;br /&gt;
&lt;br /&gt;
Our finished display and console output looks like this (I selected &amp;quot;Yes&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
[[Image:Basic_panel_1.PNG]]&lt;br /&gt;
&lt;br /&gt;
==Basic Paginated Menu==&lt;br /&gt;
Now, let's take a more advanced example -- pagination. Let's say we want to build a menu for changing the map.  An easy way to do this is to read the &amp;lt;tt&amp;gt;maplist.txt&amp;lt;/tt&amp;gt; file at the start of a plugin and build a menu out of it.&lt;br /&gt;
&lt;br /&gt;
Since reading and parsing a file is an expensive operation, we only want to do this once per map.  Thus we'll build the menu in &amp;lt;tt&amp;gt;OnMapStart&amp;lt;/tt&amp;gt;, and we won't call &amp;lt;tt&amp;gt;CloseHandle&amp;lt;/tt&amp;gt; until &amp;lt;tt&amp;gt;OnMapEnd&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Source code:&lt;br /&gt;
&amp;lt;pawn&amp;gt;new Handle:g_MapMenu = INVALID_HANDLE&lt;br /&gt;
&lt;br /&gt;
public OnPluginStart()&lt;br /&gt;
{&lt;br /&gt;
	RegConsoleCmd(&amp;quot;menu_changemap&amp;quot;, Command_ChangeMap);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public OnMapStart()&lt;br /&gt;
{&lt;br /&gt;
	g_MapMenu = BuildMapMenu();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public OnMapEnd()&lt;br /&gt;
{&lt;br /&gt;
	if (g_MapMenu != INVALID_HANDLE)&lt;br /&gt;
	{&lt;br /&gt;
		CloseHandle(g_MapMenu);&lt;br /&gt;
		g_MapMenu = INVALID_HANDLE;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Handle:BuildMapMenu()&lt;br /&gt;
{&lt;br /&gt;
	/* Open the file */&lt;br /&gt;
	new Handle:file = OpenFile(&amp;quot;maplist.txt&amp;quot;, &amp;quot;rt&amp;quot;);&lt;br /&gt;
	if (file == INVALID_HANDLE)&lt;br /&gt;
	{&lt;br /&gt;
		return INVALID_HANDLE;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	/* Create the menu Handle */&lt;br /&gt;
	new Handle:menu = CreateMenu(Menu_ChangeMap);&lt;br /&gt;
	new String:mapname[255];&lt;br /&gt;
	while (!IsEndOfFile(file) &amp;amp;&amp;amp; ReadFileLine(file, mapname, sizeof(mapname)))&lt;br /&gt;
	{&lt;br /&gt;
		if (mapname[0] == ';' || !IsCharAlpha(mapname[0]))&lt;br /&gt;
		{&lt;br /&gt;
			continue;&lt;br /&gt;
		}&lt;br /&gt;
		/* Cut off the name at any whitespace */&lt;br /&gt;
		new len = strlen(mapname);&lt;br /&gt;
		for (new i=0; i&amp;lt;len; i++)&lt;br /&gt;
		{&lt;br /&gt;
			if (IsCharSpace(mapname[i]))&lt;br /&gt;
			{&lt;br /&gt;
				mapname[i] = '\0';&lt;br /&gt;
				break;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		/* Check if the map is valid */&lt;br /&gt;
		if (!IsMapValid(mapname))&lt;br /&gt;
		{&lt;br /&gt;
			continue;&lt;br /&gt;
		}&lt;br /&gt;
		/* Add it to the menu */&lt;br /&gt;
		AddMenuItem(menu, mapname, mapname);&lt;br /&gt;
	}&lt;br /&gt;
	/* Make sure we close the file! */&lt;br /&gt;
	CloseHandle(file);&lt;br /&gt;
	&lt;br /&gt;
	/* Finally, set the title */&lt;br /&gt;
	SetMenuTitle(menu, &amp;quot;Please select a map:&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	return menu;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Menu_ChangeMap(Handle:menu, MenuAction:action, param1, param2)&lt;br /&gt;
{&lt;br /&gt;
	if (action == MenuAction_Select)&lt;br /&gt;
	{&lt;br /&gt;
		new String:info[32];&lt;br /&gt;
&lt;br /&gt;
		/* Get item info */&lt;br /&gt;
		new bool:found = GetMenuItem(menu, param2, info, sizeof(info));&lt;br /&gt;
&lt;br /&gt;
		/* Tell the client */&lt;br /&gt;
		PrintToConsole(param1, &amp;quot;You selected item: %d (found? %d info: %s)&amp;quot;, param2, found, info);&lt;br /&gt;
&lt;br /&gt;
		/* Change the map */&lt;br /&gt;
		ServerCommand(&amp;quot;changelevel %s&amp;quot;, info);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Action:Command_ChangeMap(client, args)&lt;br /&gt;
{&lt;br /&gt;
	if (g_MapMenu == INVALID_HANDLE)&lt;br /&gt;
	{&lt;br /&gt;
		PrintToConsole(client, &amp;quot;The maplist.txt file was not found!&amp;quot;);&lt;br /&gt;
		return Plugin_Handled;&lt;br /&gt;
	}	&lt;br /&gt;
	&lt;br /&gt;
	DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER);&lt;br /&gt;
	&lt;br /&gt;
	return Plugin_Handled;&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This menu results in many selections (my &amp;lt;tt&amp;gt;maplist.txt&amp;lt;/tt&amp;gt; file had around 18 maps).  So, our final menu has 3 pages, which side by side, look like:&lt;br /&gt;
&lt;br /&gt;
[[Image:Basic_menu_2_page1.PNG]]&lt;br /&gt;
[[Image:Basic_menu_2_page2.PNG]]&lt;br /&gt;
[[Image:Basic_menu_2_page3.PNG]]&lt;br /&gt;
&lt;br /&gt;
Finally, the console output printed this before the map changed to my selection, &amp;lt;tt&amp;gt;cs_office&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;You selected item: 8 (found? 1 info: cs_office)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Displaying and designing this Menu with a raw &amp;lt;tt&amp;gt;ShowMenu&amp;lt;/tt&amp;gt; message or &amp;lt;tt&amp;gt;Panel&amp;lt;/tt&amp;gt; API would be very time consuming and difficult.  We would have to keep track of all the items in an array of hardcoded size, pages which the user is viewing, and write a function which calculated item selection based on current page and key press.  The Menu system, thankfully, handles all of this for you.&lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
*Control options which are not available are not drawn.  For example, in the first page, you cannot go &amp;quot;back,&amp;quot; and in the last page, you cannot go &amp;quot;next.&amp;quot;  Despite this, the menu API tries to keep each the interface as consistent as possible.  Thus, visually, each navigational control is always in the same position.  &lt;br /&gt;
*Although we specified no time out for our menu, if we had placed a timeout, flipping through pages does not affect the overall time.  For example, if we had a timeout of 20, each successive page flip would continue to detract from the overall display time, rather than restart the allowed hold time back to 20.&lt;br /&gt;
*If we had disabled the Exit button, options 8 and 9 would still be &amp;quot;Back&amp;quot; and &amp;quot;Next,&amp;quot; respectively.&lt;br /&gt;
*Again, we did not free the Menu Handle in &amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt;.  This is because our menu is global/static, and we don't want to rebuild it every time.&lt;br /&gt;
*These images show &amp;quot;Back.&amp;quot;  In SourceMod revisions 1011 and higher, &amp;quot;Back&amp;quot; is changed to &amp;quot;Previous,&amp;quot; and &amp;quot;Back&amp;quot; is reserved for the special &amp;quot;ExitBack&amp;quot; functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Voting=&lt;br /&gt;
SourceMod also has API for displaying menus as votable choices to more than one client.  SourceMod automatically handles selecting an item and randomly picking a tie-breaker.  The voting API adds two new &amp;lt;tt&amp;gt;MenuAction&amp;lt;/tt&amp;gt; values, which for vote displays, are '''always''' passed:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;tt&amp;gt;MenuAction_VoteStart&amp;lt;/tt&amp;gt;: Fired after &amp;lt;tt&amp;gt;MenuAction_Start&amp;lt;/tt&amp;gt; when the voting has officially started.&lt;br /&gt;
*&amp;lt;tt&amp;gt;MenuAction_VoteEnd&amp;lt;/tt&amp;gt;: Fired when all clients have either voted or cancelled their vote menu.  The chosen item is passed through &amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;.  This is fired '''before''' &amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt;.  It is important to note that it does not supercede &amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt;, nor is it the same thing.  Menus should never be destroyed in &amp;lt;tt&amp;gt;MenuAction_VoteEnd&amp;lt;/tt&amp;gt;.  '''Note:''' This is not called if &amp;lt;tt&amp;gt;SetVoteResultCallback&amp;lt;/tt&amp;gt;() is used.&lt;br /&gt;
*&amp;lt;tt&amp;gt;MenuAction_VoteCancel&amp;lt;/tt&amp;gt;: Fired if the menu is cancelled while the vote is in progress.  If this is called, &amp;lt;tt&amp;gt;MenuAction_VoteEnd&amp;lt;/tt&amp;gt; or the result callback will not be called, but &amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt; will be afterwards.  A vote cancellation reason is passed in &amp;lt;tt&amp;gt;param1&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The voting system extends overall menus with two additional properties:&lt;br /&gt;
*Only one vote can be active at a time.  You must call &amp;lt;tt&amp;gt;IsVoteInProgress&amp;lt;/tt&amp;gt;() or else &amp;lt;tt&amp;gt;VoteMenu&amp;lt;/tt&amp;gt;() will fail.&lt;br /&gt;
*If a client votes and then disconnects while the vote is still active, the client's vote will be invalidated.&lt;br /&gt;
&lt;br /&gt;
The example below shows has to create a function called &amp;lt;tt&amp;gt;DoVoteMenu()&amp;lt;/tt&amp;gt; which will ask all clients whether or not they would like to change to the given map.&lt;br /&gt;
&lt;br /&gt;
==Simple Vote==&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Handle_VoteMenu(Handle:menu, MenuAction:action, param1, param2)&lt;br /&gt;
{&lt;br /&gt;
	if (action == MenuAction_End)&lt;br /&gt;
	{&lt;br /&gt;
		/* This is called after VoteEnd */&lt;br /&gt;
		CloseHandle(menu);&lt;br /&gt;
	} else if (action == MenuAction_VoteEnd) {&lt;br /&gt;
		/* 0=yes, 1=no */&lt;br /&gt;
		if (param1 == 0)&lt;br /&gt;
		{&lt;br /&gt;
			new String:map[64];&lt;br /&gt;
			GetMenuItem(menu, param1, map, sizeof(map));&lt;br /&gt;
			ServerCommand(&amp;quot;changelevel %s&amp;quot;, map);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
DoVoteMenu(const String:map[])&lt;br /&gt;
{&lt;br /&gt;
	if (IsVoteInProgress())&lt;br /&gt;
	{&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	new Handle:menu = CreateMenu(Handle_VoteMenu);&lt;br /&gt;
	SetMenuTitle(menu, &amp;quot;Change map to: %s?&amp;quot;, map);&lt;br /&gt;
	AddMenuItem(menu, map, &amp;quot;Yes&amp;quot;);&lt;br /&gt;
	AddMenuItem(menu, &amp;quot;no&amp;quot;, &amp;quot;No&amp;quot;);&lt;br /&gt;
	SetMenuExitButton(menu, false);&lt;br /&gt;
	VoteMenuToAll(menu, 20);&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Advanced Voting==&lt;br /&gt;
If you need more information about voting results than &amp;lt;tt&amp;gt;MenuAction_VoteEnd&amp;lt;/tt&amp;gt; gives you, you can choose to have a different callback invoked.  The new callback will provide much more information, but at a price: &amp;lt;tt&amp;gt;MenuAction_VoteEnd&amp;lt;/tt&amp;gt; will not be called, and you will have to decide how to interpret the results.  This is done via &amp;lt;tt&amp;gt;SetVoteResultCallback&amp;lt;/tt&amp;gt;().&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Handle_VoteMenu(Handle:menu, MenuAction:action, param1, param2)&lt;br /&gt;
{&lt;br /&gt;
	if (action == MenuAction_End)&lt;br /&gt;
	{&lt;br /&gt;
		/* This is called after VoteEnd */&lt;br /&gt;
		CloseHandle(menu);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Handle_VoteResults(Handle:menu, &lt;br /&gt;
			num_votes, &lt;br /&gt;
			num_clients, &lt;br /&gt;
			const client_info[][2], &lt;br /&gt;
			num_items, &lt;br /&gt;
			const item_info[][2])&lt;br /&gt;
{&lt;br /&gt;
	/* See if there were multiple winners */&lt;br /&gt;
	new winner = 0;&lt;br /&gt;
	if (num_items &amp;gt; 1&lt;br /&gt;
	    &amp;amp;&amp;amp; (item_info[0][VOTEINFO_ITEM_VOTES] == item_info[1][VOTEINFO_ITEM_VOTES]))&lt;br /&gt;
	{&lt;br /&gt;
		winner = GetRandomInt(0, 1);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	new String:map[64];&lt;br /&gt;
	GetMenuItem(menu, item_info[winner][VOTEINFO_ITEM_INDEX], map, sizeof(map));&lt;br /&gt;
	ServerCommand(&amp;quot;changelevel %s&amp;quot;, map);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
DoVoteMenu(const String:map[])&lt;br /&gt;
{&lt;br /&gt;
	if (IsVoteInProgress())&lt;br /&gt;
	{&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	new Handle:menu = CreateMenu(Handle_VoteMenu);&lt;br /&gt;
	SetVoteResultCallback(menu, Handle_VoteResults);&lt;br /&gt;
	SetMenuTitle(menu, &amp;quot;Change map to: %s?&amp;quot;, map);&lt;br /&gt;
	AddMenuItem(menu, map, &amp;quot;Yes&amp;quot;);&lt;br /&gt;
	AddMenuItem(menu, &amp;quot;no&amp;quot;, &amp;quot;No&amp;quot;);&lt;br /&gt;
	SetMenuExitButton(menu, false);&lt;br /&gt;
	VoteMenuToAll(menu, 20);&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=ExitBack=&lt;br /&gt;
ExitBack is a special term to refer to the &amp;quot;ExitBack Button.&amp;quot;  This button is disabled by default.  Normally, paginated menus have no &amp;quot;Previous&amp;quot; item for the first page.  If the &amp;quot;ExitBack&amp;quot; button is enabled, the &amp;quot;Previous&amp;quot; item will show up as &amp;quot;Back.&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
Selecting the &amp;quot;ExitBack&amp;quot; option will exit the menu with &amp;lt;tt&amp;gt;MenuCancel_ExitBack&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MenuEnd_ExitBack&amp;lt;/tt&amp;gt;.  The functionality of this is the same as a normal menu exit internally; extra functionality must be defined through the callbacks.&lt;br /&gt;
&lt;br /&gt;
=Closing Menu Handles=&lt;br /&gt;
It is only necessary to close a menu handle on &amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt;.  The &amp;lt;tt&amp;gt;MenuAction_End&amp;lt;/tt&amp;gt; is done every time a menu is closed and no longer needed.&lt;br /&gt;
&lt;br /&gt;
=Translations=&lt;br /&gt;
It is possible to dynamically translate menus to each player through the &amp;lt;tt&amp;gt;MenuAction_DisplayItem&amp;lt;/tt&amp;gt; callback.  A special native, &amp;lt;tt&amp;gt;RedrawMenuItem&amp;lt;/tt&amp;gt;, is used to transform the text while inside the callback.  Let's redo the vote example from earlier to be translated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;public Handle_VoteMenu(Handle:menu, MenuAction:action, param1, param2)&lt;br /&gt;
{&lt;br /&gt;
	if (action == MenuAction_End)&lt;br /&gt;
	{&lt;br /&gt;
		/* This is called after VoteEnd */&lt;br /&gt;
		CloseHandle(menu);&lt;br /&gt;
	} else if (action == MenuAction_VoteEnd) {&lt;br /&gt;
		/* 0=yes, 1=no */&lt;br /&gt;
		if (param1 == 0)&lt;br /&gt;
		{&lt;br /&gt;
			new String:map[64];&lt;br /&gt;
			GetMenuItem(menu, param1, map, sizeof(map));&lt;br /&gt;
			ServerCommand(&amp;quot;changelevel %s&amp;quot;, map);&lt;br /&gt;
		}&lt;br /&gt;
	} else if (action == MenuAction_DisplayItem) {&lt;br /&gt;
		/* Get the display string, we'll use it as a translation phrase */&lt;br /&gt;
		decl String:display[64];&lt;br /&gt;
		GetMenuItem(menu, param2, &amp;quot;&amp;quot;, 0, _, display, sizeof(display));&lt;br /&gt;
&lt;br /&gt;
		/* Translate the string to the client's language */&lt;br /&gt;
		decl String:buffer[255];&lt;br /&gt;
		Format(buffer, sizeof(buffer), &amp;quot;%T&amp;quot;, display, param1);&lt;br /&gt;
&lt;br /&gt;
		/* Override the text */&lt;br /&gt;
		return RedrawMenuItem(buffer);&lt;br /&gt;
	} else if (action == MenuAction_Display) {&lt;br /&gt;
		/* Panel Handle is the second parameter */&lt;br /&gt;
		new Handle:panel = Handle:param2;&lt;br /&gt;
		&lt;br /&gt;
		/* Get the map name we're changing to from the first item */&lt;br /&gt;
		decl String:map[64];&lt;br /&gt;
		GetMenuItem(menu, 0, map, sizeof(map));&lt;br /&gt;
		&lt;br /&gt;
		/* Translate to our phrase */&lt;br /&gt;
		decl String:buffer[255];&lt;br /&gt;
		Format(buffer, sizeof(buffer), &amp;quot;%T&amp;quot;, &amp;quot;Change map to?&amp;quot;, client, map);&lt;br /&gt;
&lt;br /&gt;
		SetPanelTitle(panel, buffer);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
DoVoteMenu(const String:map[])&lt;br /&gt;
{&lt;br /&gt;
	if (IsVoteInProgress())&lt;br /&gt;
	{&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	new Handle:menu = CreateMenu(Handle_VoteMenu, MenuAction_DisplayItem|MenuAction_Display);&lt;br /&gt;
	SetMenuTitle(menu, &amp;quot;Change map to: %s?&amp;quot;, map);&lt;br /&gt;
	AddMenuItem(menu, map, &amp;quot;Yes&amp;quot;);&lt;br /&gt;
	AddMenuItem(menu, &amp;quot;no&amp;quot;, &amp;quot;No&amp;quot;);&lt;br /&gt;
	SetMenuExitButton(menu, false);&lt;br /&gt;
	VoteMenuToAll(menu, 20);&lt;br /&gt;
}&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Development]]&lt;br /&gt;
[[Category:SourceMod Scripting]]&lt;br /&gt;
&lt;br /&gt;
{{LanguageSwitch}}&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Writing_Extensions&amp;diff=7073</id>
		<title>Writing Extensions</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Writing_Extensions&amp;diff=7073"/>
		<updated>2009-03-27T12:41:25Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: /* Compiler Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;SourceMod's Extension System is a powerful way to greatly enhance the flexibility of your SourceMod plugins.  You can take full advantage of SourceMod's Core, using the interfaces it provides, to create C++ plugins, plugin events, plugin native functions, and shared interfaces.  Extensions can also hook into Metamod:Source.&lt;br /&gt;
&lt;br /&gt;
This article goes into the details of creating a SourceMod Extension.  Knowledge of C++ is required.&lt;br /&gt;
&lt;br /&gt;
=SDK Structure=&lt;br /&gt;
First, download the [[SourceMod SDK]] from the [[SourceMod]] website.  The directory structure looks like this:&lt;br /&gt;
*&amp;lt;tt&amp;gt;extensions&amp;lt;/tt&amp;gt;&lt;br /&gt;
**&amp;lt;tt&amp;gt;geoip/&amp;lt;/tt&amp;gt; - Source code to the GeoIP extension&lt;br /&gt;
**&amp;lt;tt&amp;gt;mysql/&amp;lt;/tt&amp;gt; - Source code to the MySQL extension&lt;br /&gt;
**&amp;lt;tt&amp;gt;threader/&amp;lt;/tt&amp;gt; - Source code to the Threader extension&lt;br /&gt;
*&amp;lt;tt&amp;gt;plugins/&amp;lt;/tt&amp;gt; - Source code to all of SourceMod's plugins&lt;br /&gt;
**&amp;lt;tt&amp;gt;include/&amp;lt;/tt&amp;gt; - The include files which document plugin API&lt;br /&gt;
*&amp;lt;tt&amp;gt;public/&amp;lt;/tt&amp;gt; - Interface files for SourceMod's Core Interfaces&lt;br /&gt;
**&amp;lt;tt&amp;gt;extensions/&amp;lt;/tt&amp;gt; - Interfaces that are provided by extensions&lt;br /&gt;
**&amp;lt;tt&amp;gt;sample_ext/&amp;lt;/tt&amp;gt; - The Sample Extension SDK&lt;br /&gt;
**&amp;lt;tt&amp;gt;sourcepawn&amp;lt;/tt&amp;gt; - The include/interface files for SourcePawn&lt;br /&gt;
*&amp;lt;tt&amp;gt;sourcepawn/&amp;lt;/tt&amp;gt;&lt;br /&gt;
**&amp;lt;tt&amp;gt;compiler/&amp;lt;/tt&amp;gt; - The SourcePawn Compiler&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Starting an Extension=&lt;br /&gt;
For simplicity, this article will assume you are using the SDK base files.  These are:&lt;br /&gt;
*&amp;lt;tt&amp;gt;sdk/smsdk_config.h&amp;lt;/tt&amp;gt; - Configuration settings (we will be editing this)&lt;br /&gt;
*&amp;lt;tt&amp;gt;sdk/smsdk_ext.h&amp;lt;/tt&amp;gt; - Header for SDK wrappers (usually never needs to be edited)&lt;br /&gt;
**''Note: Sometimes, this may be updated by the SourceMod Dev Team.  Using a newest version is recommended.'&lt;br /&gt;
*&amp;lt;tt&amp;gt;sdk/smsdk_ext.cpp&amp;lt;/tt&amp;gt; - Source for SDK wrappers (usually never needs to be edited)&lt;br /&gt;
**''Note: Sometimes, this may be updated by the SourceMod Dev Team.  Using a newest version is recommended.'&lt;br /&gt;
*&amp;lt;tt&amp;gt;extension.h&amp;lt;/tt&amp;gt; - User file for main extension header&lt;br /&gt;
*&amp;lt;tt&amp;gt;extension.cpp&amp;lt;/tt&amp;gt; - User file for main extension code&lt;br /&gt;
&lt;br /&gt;
''The &amp;lt;tt&amp;gt;extension.*&amp;lt;/tt&amp;gt; files are not technically part of the SDK.  However, they are provided to give users a starting point and some documentation.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For help setting up Visual Studio, please see [[#Setting up Visual Studio|Setting up Visual Studio]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first step of creating your extension is to configure it.  Open the &amp;lt;tt&amp;gt;smsdk_config.h&amp;lt;/tt&amp;gt; file and edit each of the following defines.  Use the information below to guide you.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_NAME&amp;lt;/tt&amp;gt; - The general name for your Extension (should be short).&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_DESCRIPTION&amp;lt;/tt&amp;gt; - A short description of what your extension does.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_VERSION&amp;lt;/tt&amp;gt; - A version number string.  By convention, SourceMod uses the four set build number notation.  I.e. for 1.2.3.4:&lt;br /&gt;
**&amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt; is the &amp;quot;Major&amp;quot; release version.&lt;br /&gt;
**&amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt; is the &amp;quot;Minor&amp;quot; release version.&lt;br /&gt;
**&amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; is the &amp;quot;Maintenance&amp;quot; or &amp;quot;Revision&amp;quot; version.&lt;br /&gt;
**&amp;lt;tt&amp;gt;4&amp;lt;/tt&amp;gt; is the &amp;quot;Build,&amp;quot; usually an internal source control number.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_AUTHOR&amp;lt;/tt&amp;gt; - Your name (or whoever/whatever authored the plugin).&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_URL&amp;lt;/tt&amp;gt; - The URL/homepage of this extension.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_LOGTAG&amp;lt;/tt&amp;gt; - The logtag your extension will use for SourceMod logging.  By convention, try to keep this under ten characters or so, and to make it all caps.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_LICENSE&amp;lt;/tt&amp;gt; - Right now, the SourceMod Dev Team mandates that 3rd party extensions must be under an Open Source license.  Putting a license abbreviation or very short message here is appropriate.  For more information, see [[SourceMod License]].&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_DATESTRING&amp;lt;/tt&amp;gt; - You do not need to modify this.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_CONF_METAMOD&amp;lt;/tt&amp;gt; - If your plugin requires using SourceHook or Metamod:Source, uncomment this line.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, you may want to change the name of the default class that &amp;lt;tt&amp;gt;extension.h&amp;lt;/tt&amp;gt; declares.  To do this...&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Open &amp;lt;tt&amp;gt;extension.h&amp;lt;/tt&amp;gt; and change &amp;quot;Sample&amp;quot; in this line:&lt;br /&gt;
&amp;lt;cpp&amp;gt;class Sample : public SDKExtension&amp;lt;/cpp&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open &amp;lt;tt&amp;gt;extension.cpp&amp;lt;/tt&amp;gt; and change the two lines to correspond to your new class name.  You can also change the global singleton that's declared, although you cannot remove the &amp;lt;tt&amp;gt;SMEXT_LINK&amp;lt;/tt&amp;gt; line (this lets SourceMod load your extension).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Visual Studio Users==&lt;br /&gt;
Make sure you change the name of your &amp;lt;tt&amp;gt;.dll&amp;lt;/tt&amp;gt; file.  The naming convention for SourceMod extensions is &amp;lt;tt&amp;gt;name.ext.dll&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; is a short name for your extension.  You are free to change this, but it is highly recommended that you keep the &amp;lt;tt&amp;gt;.ext.dll&amp;lt;/tt&amp;gt; intact.&lt;br /&gt;
&lt;br /&gt;
You can do this by going to &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;Properties&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;Configuration Properties&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;Linker&amp;lt;/tt&amp;gt; -&amp;gt; &amp;lt;tt&amp;gt;General&amp;lt;/tt&amp;gt;.  Set the &amp;lt;tt&amp;gt;Output File&amp;lt;/tt&amp;gt; option appropriately.&lt;br /&gt;
&lt;br /&gt;
==Linux Users==&lt;br /&gt;
Simply edit the &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt; and change the &amp;lt;tt&amp;gt;BINARY&amp;lt;/tt&amp;gt; line near the top.  Make sure you do not add any trailing spaces at the end of the name, or the build won't come out right.&lt;br /&gt;
&lt;br /&gt;
You should now be able to compile a blank extension!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Creating Native Functions=&lt;br /&gt;
''Main article: [[Natives (SourceMod Development)]]''&lt;br /&gt;
&lt;br /&gt;
Most of the time, an extension exists to add &amp;quot;native functions&amp;quot; to the plugin system.  Native functions are simply the functions that plugins can use in SourceMod.  They are coded in C++ and have a short prototype declaration in an include file.&lt;br /&gt;
&lt;br /&gt;
==Prototyping==&lt;br /&gt;
The first step to creating a native is to &amp;lt;tt&amp;gt;spec it&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;prototype&amp;lt;/tt&amp;gt; it.  This is a simple but often time consuming process, but if you get in the habit of it, your documentation will be much better.  Let's first create a very simply native.  Here is a prototype for it, which we will place in &amp;lt;tt&amp;gt;sample.inc&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Returns the square of a number.&lt;br /&gt;
 *&lt;br /&gt;
 * @param num	Number to square.&lt;br /&gt;
 * @return	The square of num.&lt;br /&gt;
 */&lt;br /&gt;
native SquareNumber(num);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;native&amp;lt;/tt&amp;gt; keyword tells the compiler that this function exists in an outside source.  The comment style is similar to [http://www.stack.nl/~dimitri/doxygen/ doxygen] or [http://java.sun.com/j2se/javadoc/ Javadoc], and is preferred by the SourceMod Development Team.&lt;br /&gt;
&lt;br /&gt;
==Implementing==&lt;br /&gt;
Now that our function is documented, it's time to create it!  Each native function is bound to a C++ function.  The prototype for this function looks like:&lt;br /&gt;
&amp;lt;cpp&amp;gt;cell_t Function(IPluginContext *pContext, const cell_t *params);&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A quick explanation of these types:&lt;br /&gt;
*&amp;lt;tt&amp;gt;cell_t&amp;lt;/tt&amp;gt; - This is a 32bit signed integer, the generic data type for Pawn.&lt;br /&gt;
*&amp;lt;tt&amp;gt;IPluginContext&amp;lt;/tt&amp;gt; - This interface provides Virtual Machine functions for retrieving or modifying memory in the plugin.&lt;br /&gt;
*&amp;lt;tt&amp;gt;params&amp;lt;/tt&amp;gt; - This is the &amp;quot;stack&amp;quot; of parameters that the plugin passed.  It is an array from [0..N] where 0 contains N.  &lt;br /&gt;
**For example, if one parameter was passed, and the parameter is 25:&lt;br /&gt;
***&amp;lt;tt&amp;gt;params[0]&amp;lt;/tt&amp;gt; == 1&lt;br /&gt;
***&amp;lt;tt&amp;gt;params[1]&amp;lt;/tt&amp;gt; == 25&lt;br /&gt;
**Even though it tells you how many parameters are passed, you do not need to verify this number.  The compiler will always pass the correct number of parameters in.  The only time you need to verify it is for backwards compatibility or variable parameter lists, which will be discussed later.&lt;br /&gt;
&lt;br /&gt;
Now, let's write our native function:&lt;br /&gt;
&amp;lt;cpp&amp;gt;cell_t SquareNumber(IPluginContext *pContext, const cell_t *params)&lt;br /&gt;
{&lt;br /&gt;
	cell_t number = params[1];&lt;br /&gt;
	return number * number;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Binding==&lt;br /&gt;
Now, the final step is to bind our native.  Natives are bound in ''native lists''.  Each list must be terminated by a &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt; bind.  Example:&lt;br /&gt;
&amp;lt;cpp&amp;gt;const sp_nativeinfo_t MyNatives[] = &lt;br /&gt;
{&lt;br /&gt;
	{&amp;quot;SquareNumber&amp;quot;,	SquareNumber},&lt;br /&gt;
	{NULL,			NULL},&lt;br /&gt;
};&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column/member is a string containing the name you've assigned to the native.  The second column/member is the C++ function you're binding to.  Here, both contain the same name, but it is certainly possible to bind a function to any valid Pawn function name, and likewise, you can bind one function to more than one name.&lt;br /&gt;
&lt;br /&gt;
Lastly, you must tell Core about your native list.  There are two places that are good to do this.  Whichever you choose, you must uncomment the function in &amp;lt;tt&amp;gt;extension.h&amp;lt;/tt&amp;gt; and implement it in &amp;lt;tt&amp;gt;extension.cpp&amp;lt;/tt&amp;gt;.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SDK_OnLoad&amp;lt;/tt&amp;gt; - This is called when your extension is first loaded.  If you do not require any outside interfaces, it is safe to add natives here.&lt;br /&gt;
*&amp;lt;tt&amp;gt;SDK_OnAllLoaded&amp;lt;/tt&amp;gt; - This is called when all extensions have been loaded.  This is generally a better place to add natives.&lt;br /&gt;
&lt;br /&gt;
Let's say we choose &amp;lt;tt&amp;gt;SDK_OnAllLoaded&amp;lt;/tt&amp;gt;, we'd then have code like this:&lt;br /&gt;
&amp;lt;cpp&amp;gt;void Sample::SDK_OnAllLoaded()&lt;br /&gt;
{&lt;br /&gt;
	sharesys-&amp;gt;AddNatives(myself, MyNatives);&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
''Note: &amp;lt;tt&amp;gt;myself&amp;lt;/tt&amp;gt; is a global variable declared in the SDK.  It is a pointer that identifies your extension.''&lt;br /&gt;
&lt;br /&gt;
For more information on writing natives, see [[Natives (SourceMod Development)]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Creating Events/Forwards=&lt;br /&gt;
Events are an integral part to SourceMod.  An Event is formally called a ''Forward''.  Forwards are functions inside a plugin which are not called by the plugin itself, but are triggered from an external source.  For example, &amp;lt;tt&amp;gt;OnClientConnect&amp;lt;/tt&amp;gt; is a forward which is triggered when a player connects to a server.&lt;br /&gt;
&lt;br /&gt;
There are two major types of forwards:&lt;br /&gt;
*'''Managed''': This forward is global and has a name.  To use this forward, the function must be declared as &amp;lt;tt&amp;gt;public&amp;lt;/tt&amp;gt; inside the user's script.  Any plugin having this public function will receive the event.&lt;br /&gt;
*'''Unmanaged''': This forward is private in nature.  For example, the &amp;lt;tt&amp;gt;HookUserMessage&amp;lt;/tt&amp;gt; native lets users specify a function to be called when a specific user message is sent.  This is done with an unmanaged forward, and adding functions to this forward is not automatic.  In general, function calls for unmanaged forwards are not public, although they can be.&lt;br /&gt;
&lt;br /&gt;
==Managed Forwards==&lt;br /&gt;
Let's say we want to create a forward that will be called when a player uses say chat.  For simplicity, let's assume you already have a function that tells you when a player says say chat.  We will just be creating the forward for it.&lt;br /&gt;
&lt;br /&gt;
As we did before, first let's prototype our global forward.  In our include file, we add this:&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * @brief Called whenever a client says something in chat.&lt;br /&gt;
 *&lt;br /&gt;
 * @param client	Index of the client.&lt;br /&gt;
 * @param text		String containing the say text.&lt;br /&gt;
 * @return 		Pl_Handled to block text from printing, Pl_Continue otherwise.&lt;br /&gt;
 */&lt;br /&gt;
forward ResultType:OnPlayerSayChat(client, const String:text[]);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;forward&amp;lt;/tt&amp;gt; keyword tells the compiler that any function having this name must be declared exactly the same.  In a plugin, this would&lt;br /&gt;
&lt;br /&gt;
The next step is to declare your forward somewhere at the top of your &amp;lt;tt&amp;gt;extension.cpp&amp;lt;/tt&amp;gt; file.  This will look like:&lt;br /&gt;
&amp;lt;cpp&amp;gt;IForward *g_pSayChat = NULL&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, re-using our code from above, let's create this forward in &amp;lt;tt&amp;gt;SDK_OnAllLoaded&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;cpp&amp;gt;void Sample::SDK_OnAllLoaded()&lt;br /&gt;
{&lt;br /&gt;
	sharesys-&amp;gt;AddNatives(myself, MyNatives);&lt;br /&gt;
	g_pSayChat = forwards-&amp;gt;CreateForward(&amp;quot;OnPlayerSayChat&amp;quot;, ET_Event, 2, NULL, Param_Cell, Param_String);&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explanation of parameters:&lt;br /&gt;
*&amp;lt;tt&amp;gt;&amp;quot;OnPlayerSayChat&amp;quot;&amp;lt;/tt&amp;gt; - The name of our forward.&lt;br /&gt;
*&amp;lt;tt&amp;gt;ET_Event&amp;lt;/tt&amp;gt; - Since forwards can execute multiple functions in multiple scripts, this is one of the ways of specifying what to do with the return value of each function.  &amp;lt;tt&amp;gt;ET_Event&amp;lt;/tt&amp;gt; means &amp;quot;return the highest value, do not allow stops.&amp;quot;  A stop refers to &amp;lt;tt&amp;gt;Pl_Stop&amp;lt;/tt&amp;gt;, which lets a plugin block the rest of the event chain.&lt;br /&gt;
*&amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt; - This is the number of parameters our forward will have.&lt;br /&gt;
*&amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt; - Not used in our example.  This lets you pass parameters by array rather than variable arguments.&lt;br /&gt;
*&amp;lt;tt&amp;gt;Param_Cell&amp;lt;/tt&amp;gt; - The first parameter is a cell (integer).&lt;br /&gt;
*&amp;lt;tt&amp;gt;Param_String&amp;lt;/tt&amp;gt; - The second parameter is a string.&lt;br /&gt;
&lt;br /&gt;
Now, we write a quick function in our module to call this forward:&lt;br /&gt;
&amp;lt;cpp&amp;gt;/** Fires the say chat event in plugins.  Returns true to allow the text, false to block. */&lt;br /&gt;
bool FireChatEvent(int client, const char *text)&lt;br /&gt;
{&lt;br /&gt;
	if (!g_pSayChat)&lt;br /&gt;
	{&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	cell_t result = 0;&lt;br /&gt;
	g_pSayChat-&amp;gt;PushCell(client);&lt;br /&gt;
	g_pSayChat-&amp;gt;PushString(text);&lt;br /&gt;
	g_pSayChat-&amp;gt;Execute(&amp;amp;result);&lt;br /&gt;
	&lt;br /&gt;
	if (result == Pl_Handled)&lt;br /&gt;
	{&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return true;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, this was pretty simple.  Each parameter is &amp;quot;pushed&amp;quot; one at a time, in ascending order.  First we push the client index as a cell, then the text as a string.  Once done, we execute, and the value will be returned by reference.&lt;br /&gt;
&lt;br /&gt;
Lastly, there is a caveat.  Unlike natives, SourceMod does not automatically clean up forwards for us when are done.  We have to make sure we destroy them.  Uncomment &amp;lt;tt&amp;gt;SDK_OnUnload&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;extension.h&amp;lt;/tt&amp;gt; and implement it like so:&lt;br /&gt;
&amp;lt;cpp&amp;gt;void Sample::SDK_OnUnload()&lt;br /&gt;
{&lt;br /&gt;
	forwards-&amp;gt;ReleaseForward(g_pSayChat);&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Unmanaged Forwards==&lt;br /&gt;
Now things get a bit more complicated.  However, unmanaged forwards are essentially the same -- they just give you more flexibility.  Let's consider the managed example with a new twist.  We want to let users add and remove hooks from their plugins, rather than having one global forward.  The standard way to do this is with ''function IDs''.  &lt;br /&gt;
&lt;br /&gt;
Example prototype:&lt;br /&gt;
&amp;lt;pawn&amp;gt;funcenum SayChatHook&lt;br /&gt;
{&lt;br /&gt;
	forward(client, const String:text[]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
native AddSayChatHook(SayChatHook:hook);&lt;br /&gt;
native RemoveSayChatHook(SayChatHook:hook);&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;funcenum&amp;lt;/tt&amp;gt; syntax lets you define all the valid prototypes for your hook.  In this example, the only valid method is a function declared like this (only MyHook can be changed):&lt;br /&gt;
&amp;lt;pawn&amp;gt;MyHook(client, const String:text[])&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How do we make such a beast?  The first step is setting up our forward.&lt;br /&gt;
&amp;lt;cpp&amp;gt;IChangeableForward *g_pSayChat = NULL;&lt;br /&gt;
/* ... */&lt;br /&gt;
void Sample::SDK_OnAllLoaded()&lt;br /&gt;
{&lt;br /&gt;
	g_pSayChat = forwards-&amp;gt;CreateForwardEx(NULL, ET_Hook, 2, NULL, Param_Cell, Param_String); &lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice two big differences.  We now use &amp;lt;tt&amp;gt;IChangeableForward&amp;lt;/tt&amp;gt; instead of &amp;lt;tt&amp;gt;IForward&amp;lt;/tt&amp;gt;, and we use &amp;lt;tt&amp;gt;CreateForwardEx&amp;lt;/tt&amp;gt; instead.  The initial first parameter specifies a name for our forward - we're going to ignore this.&lt;br /&gt;
&lt;br /&gt;
Now, we need to create our natives.  These will be fairly simple:&lt;br /&gt;
&amp;lt;cpp&amp;gt;cell_t AddSayChatHook(IPluginContext *pContext, const cell_t *params)&lt;br /&gt;
{&lt;br /&gt;
	g_pSayChat-&amp;gt;AddFunction(pContext, static_cast&amp;lt;funcid_t&amp;gt;(params[1]));&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
cell_t RemoveSayChatHook(IPluginContext *pContext, const cell_t *params)&lt;br /&gt;
{&lt;br /&gt;
	IPluginFunction *pFunction = pContext-&amp;gt;GetFunctionById(static_cast&amp;lt;funcid_t&amp;gt;(params[1]));&lt;br /&gt;
	g_pSayChat-&amp;gt;RemoveFunction(pFunction);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
''Note: These natives must be added -- that step is removed here and explained earlier.''&lt;br /&gt;
&lt;br /&gt;
You do not need to worry about a plugin unloading - Core will automatically remove the functions for you.  Since an &amp;lt;tt&amp;gt;IChangeableForward&amp;lt;/tt&amp;gt; is also an &amp;lt;tt&amp;gt;IForward&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;FireChatEvent&amp;lt;/tt&amp;gt; function from earlier does not need to change.  We're done!&lt;br /&gt;
&lt;br /&gt;
==Creating Interfaces==&lt;br /&gt;
Do you want your extension to share an interface?  If so, first you should create an ''interface file''.  This file should contain everything your interface needs - this way other authors can easily reference it.  Your interface must inherit the &amp;lt;tt&amp;gt;SMInterface&amp;lt;/tt&amp;gt; class.  It must also declare two global macros that uniquely identify your interface.  It must also implement two functions: &amp;lt;tt&amp;gt;GetInterfaceName&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;GetInterfaceVersion&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The two defines must start with &amp;lt;tt&amp;gt;SMINTERFACE_&amp;lt;/tt&amp;gt; and end with &amp;lt;tt&amp;gt;_NAME&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;_VERSION&amp;lt;/tt&amp;gt; respectively.  The first must be a string and the second must be an unsigned integer.  This integer represents your interface's version number.  While you are free to use it however you please, by default it should be linearly increased.  If you make breaking changes or change the versioning scheme, you must overload the &amp;lt;tt&amp;gt;IsVersionCompat&amp;lt;/tt&amp;gt; function in &amp;lt;tt&amp;gt;SMInterface&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;cpp&amp;gt;#ifndef _INCLUDE_MYINTERFACE_FILE_H_&lt;br /&gt;
#define _INCLUDE_MYINTERFACE_FILE_H_&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;IShareSys.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define SMINTERFACE_MYINTERFACE_NAME	&amp;quot;IMyInterface&amp;quot;&lt;br /&gt;
#define SMINTERFACE_MYINTERFACE_VERSION	1&lt;br /&gt;
&lt;br /&gt;
class IMyInterface : public SourceMod::SMInterface&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
	virtual const char *GetInterfaceName()&lt;br /&gt;
	{&lt;br /&gt;
		return SMINTERFACE_MYINTERFACE_NAME;&lt;br /&gt;
	}&lt;br /&gt;
	virtual unsigned int GetInterfaceVersion()&lt;br /&gt;
	{&lt;br /&gt;
		return SMINTERFACE_MYINTERFACE_VERSION;&lt;br /&gt;
	}&lt;br /&gt;
public:&lt;br /&gt;
	/**&lt;br /&gt;
	 * @brief This function does nothing.&lt;br /&gt;
	 */&lt;br /&gt;
	virtual void DoNothingAtAll() =0;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif //_INCLUDE_MYINTERFACE_FILE_H_&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice, of course, that our interface is ''pure virtual''.  This means it must be implemented in the extension.  Assuming you know C++, this should be fairly straight forward, so let's skip right to how to add this interface to the SourceMod shared system:&lt;br /&gt;
&amp;lt;cpp&amp;gt;bool Sample::SDK_OnLoad(char *error, size_t err_max, bool late)&lt;br /&gt;
{&lt;br /&gt;
	sharesys-&amp;gt;AddInterface(myself, &amp;amp;g_MyInterface);&lt;br /&gt;
	return true;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
''Note: We do this in &amp;lt;tt&amp;gt;SDK_OnLoad()&amp;lt;/tT&amp;gt; instead of &amp;lt;tt&amp;gt;SDK_OnAllLoaded()&amp;lt;/tt&amp;gt;.  Otherwise, an extension might try to search for your interface during &amp;lt;tt&amp;gt;SDK_OnAllLoaded()&amp;lt;/tt&amp;gt;, and it might fail depending on the load order.''&lt;br /&gt;
&lt;br /&gt;
That simple?  Yup!  Now other extensions can use your interface.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Using Interfaces/Other Extensions=&lt;br /&gt;
There are a variety of interfaces that are available, but not loaded by default in the Extension SDK.  These interfaces can be retrieved and used in your extension.&lt;br /&gt;
&lt;br /&gt;
==Core Interfaces==&lt;br /&gt;
If they are provided by Core, getting them is very simple.  Many interfaces can simply be uncommented in &amp;lt;tt&amp;gt;smsdk_config.h&amp;lt;/tt&amp;gt; and they will become usable.  See the &amp;quot;Available Interfaces&amp;quot; list below for the exposure list.&lt;br /&gt;
&lt;br /&gt;
Otherwise, most of the &amp;lt;tt&amp;gt;.h&amp;lt;/tt&amp;gt; interface files in the root of the &amp;lt;tt&amp;gt;public&amp;lt;/tt&amp;gt; folder in the SDK are Core interfaces.  For example, code to use the IPluginManager interface might look like this:&lt;br /&gt;
&amp;lt;cpp&amp;gt;#include &amp;lt;IPluginSys.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IPluginManager *g_pPlugins = NULL;&lt;br /&gt;
&lt;br /&gt;
bool Sample::SDK_OnLoad(char *error, size_t err_max, bool late)&lt;br /&gt;
{&lt;br /&gt;
	SM_GET_IFACE(PLUGINSYSTEM, g_pPlugins);&lt;br /&gt;
	return true;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where did we get &amp;lt;tt&amp;gt;PLUGINSYSTEM&amp;lt;/tt&amp;gt; from?  Observe the two lines in &amp;lt;tt&amp;gt;IPluginSys.h&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;cpp&amp;gt;#define SMINTERFACE_PLUGINSYSTEM_NAME		&amp;quot;IPluginManager&amp;quot;&lt;br /&gt;
#define SMINTERFACE_PLUGINSYSTEM_VERSION	1&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;SM_GET_IFACE&amp;lt;/tt&amp;gt; macro uses the text in between the &amp;lt;tt&amp;gt;SMINTERFACE_&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;_NAME&amp;lt;/tt&amp;gt; characters.  It also uses the version for compatibility checking.  If it can't find the interface, it automatically prints to the error buffer and returns false.&lt;br /&gt;
&lt;br /&gt;
===Default Interfaces===&lt;br /&gt;
There are interfaces which are grabbed by the Extension SDK by default.  You do not need to query for them on load, or even check if they are valid or not.  They are:&lt;br /&gt;
*&amp;lt;tt&amp;gt;IShareSys&amp;lt;/tt&amp;gt; - Exposed as &amp;lt;tt&amp;gt;sharesys&amp;lt;/tt&amp;gt;, found in &amp;lt;tt&amp;gt;IShareSys.h&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;HANDLESYSTEM&amp;lt;/tt&amp;gt; - Exposed as &amp;lt;tt&amp;gt;handlesys&amp;lt;/tt&amp;gt;, found in &amp;lt;tt&amp;gt;IHandleSys.h&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SOURCEMOD&amp;lt;/tt&amp;gt; - Exposed as &amp;lt;tt&amp;gt;g_pSM&amp;lt;/tt&amp;gt;, found in &amp;lt;tt&amp;gt;ISourceMod.h&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;FORWARDMANAGER&amp;lt;/tt&amp;gt; - Exposed as &amp;lt;tt&amp;gt;forwards&amp;lt;/tt&amp;gt;, found in &amp;lt;tt&amp;gt;IForwardSys.h&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Available Interfaces===&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_FORWARDSYS&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;forwards&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_HANDLESYS&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;handlesys&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_PLAYERHELPERS&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;playerhelpers&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_DBMANAGER&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;dbi&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_GAMECONF&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;gameconfs&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_MEMUTILS&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;memutils&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_GAMEHELPERS&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;gamehelpers&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_TIMERSYS&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;timersys&amp;lt;/tt&amp;gt;&lt;br /&gt;
*&amp;lt;tt&amp;gt;SMEXT_ENABLE_THREADER&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;threader&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==External Interfaces==&lt;br /&gt;
The situation changes if your extension requires ''another extension'', since extensions may load in a completely random order.  The first step is to mark the other extension as a dependency.  Let's say you want to use the &amp;lt;tt&amp;gt;IThreader.h&amp;lt;/tt&amp;gt; interfaces from &amp;lt;tt&amp;gt;threader.ext.dll&amp;lt;/tt&amp;gt;.  First, we declare it as such:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cpp&amp;gt;bool Sample::SDK_OnLoad(char *error, size_t err_max, bool late)&lt;br /&gt;
{&lt;br /&gt;
	sharesys-&amp;gt;AddDependency(myself, &amp;quot;thread.ext&amp;quot;, true, true);&lt;br /&gt;
	return true;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two boolean parameters to &amp;lt;tt&amp;gt;AddDependency&amp;lt;/tt&amp;gt; mean, respectively: &amp;quot;try to automatically load this extension&amp;quot; and &amp;quot;this extension cannot work without the dependency.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Second, we query for the interface in &amp;lt;tt&amp;gt;SDK_OnAllLoaded&amp;lt;/tt&amp;gt;.  Since we don't know when &amp;lt;tt&amp;gt;thread.ext&amp;lt;/tt&amp;gt; will actually be loaded, we have to wait until everything is definitely loaded.&lt;br /&gt;
&amp;lt;cpp&amp;gt;IThreader *g_pThreader = NULL;&lt;br /&gt;
/* ... */&lt;br /&gt;
void Sample::SDK_OnAllLoaded()&lt;br /&gt;
{&lt;br /&gt;
	SM_GET_LATE_IFACE(THREADER, g_pThreader);&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Third, we need to find a way to fail if this interface was never found.  The way to do this is by uncommenting &amp;lt;tt&amp;gt;QueryRunning&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;extension.h&amp;lt;/tt&amp;gt; and implementing it:&lt;br /&gt;
&amp;lt;cpp&amp;gt;bool Sample::QueryRunning(char *error, size_t err_max)&lt;br /&gt;
{&lt;br /&gt;
	SM_CHECK_IFACE(THREADER, g_pThreader);&lt;br /&gt;
	return true;&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When SourceMod queries your extension, the macro above will either validate the pointer or return false.  If it returns false, SourceMod marks your extension as failed.&lt;br /&gt;
&lt;br /&gt;
==Caveats==&lt;br /&gt;
===NULL Interfaces===&lt;br /&gt;
There are a few ways that external interfaces can make your code complicated.  The first is simple but a common oversight.  Don't assume interfaces will be okay.  For example, say we want to create a thread once we get the &amp;lt;tt&amp;gt;IThreader&amp;lt;/tt&amp;gt; interface.  Our code should something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cpp&amp;gt;void Sample::SDK_OnAllLoaded()&lt;br /&gt;
{&lt;br /&gt;
	SM_GET_IFACE(THREADER, g_pThreader);&lt;br /&gt;
	&lt;br /&gt;
	if (QueryRunning(NULL, 0))&lt;br /&gt;
	{&lt;br /&gt;
		g_pThreader-&amp;gt;MakeThread(/* stuff */);&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we ''query ourself'' in order to find if it's safe to continue executing code.  We could also have simply checked if &amp;lt;tt&amp;gt;g_pThreader&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, but self-querying has a bonus: if your extension continues to do things like hook events or add listeners, you will be preventing your extension from entirely initializing itself while one interface is bad.  Always make sure you have sanity checks like this where needed.&lt;br /&gt;
&lt;br /&gt;
===Dynamic Unloading===&lt;br /&gt;
The second major caveat is that extensions can be dynamically unloaded.  If you specified yourself as having a dependency and that each dependency is required, you will have no problem.  Your extension will be unloaded before the interface is removed, and you can clean up memory/hooks in your &amp;lt;tt&amp;gt;SDK_OnUnload()&amp;lt;/tt&amp;gt; code.  There are two situations where this is a different story.&lt;br /&gt;
&lt;br /&gt;
====Optional Interfaces====&lt;br /&gt;
The first situation is if you are not requiring an extension that contains an interface.  Now, when the extension unloads, your extension will not be unloaded first.  This creates a small problem, as you must clean up without being unloaded.  There are two functions you can implement in your extension class to resolve this, both documented in &amp;lt;tt&amp;gt;IExtensionSys.h&amp;lt;/tt&amp;gt;:&lt;br /&gt;
*&amp;lt;tt&amp;gt;QueryInterfaceDrop&amp;lt;/tt&amp;gt; - Allows you to request unloading when a specific interface is unloaded.  This is the default behavior for all interfaces.  If you want to block this functionality, continue reading.&lt;br /&gt;
*&amp;lt;tt&amp;gt;NotifyInterfaceDrop&amp;lt;/tt&amp;gt; - This is called when an interface is dropped.  If your plugin will not be unloaded, you can use this to clean up any resources on a specific interface being removed.&lt;br /&gt;
&lt;br /&gt;
====Circular Dependencies====&lt;br /&gt;
The second situation is a bit more complicated.  It is possible for two extensions to have circular dependencies.  For example:&lt;br /&gt;
*Extension &amp;quot;A&amp;quot; requires extension &amp;quot;B.&amp;quot;&lt;br /&gt;
*Extension &amp;quot;B&amp;quot; requires extension &amp;quot;A.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If either extension is unloaded, the opposite extension is unloaded normally.  The first extension then receives the interface drop callbacks.  In this situation, it is essential that the &amp;lt;tt&amp;gt;NotifyInterfaceDrop&amp;lt;/tt&amp;gt; function be implemented and used with the circular interface.  Otherwise, you risk crashing when your extension unloads (or at the very least, leaking memory).  Since the actual drop order is undefined, it means both extensions must implement this function to be safe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Automatic Loading=&lt;br /&gt;
There are two types of automatic loading: Dynamic and Global.  Dynamic loading means your extension is only loaded when a plugin requires it.  Global loading means your extension loads no matter what.&lt;br /&gt;
&lt;br /&gt;
==Dynamic Autoloading==&lt;br /&gt;
Dynamic loading requires that you create an include file for plugins.  Plugins that include your file will automatically load your extension.  This requires implementing the &amp;lt;tt&amp;gt;Extension&amp;lt;/tt&amp;gt; structure found in &amp;lt;tt&amp;gt;core.inc&amp;lt;/tt&amp;gt;.  You must expose the structure as &amp;lt;tt&amp;gt;public&amp;lt;/tt&amp;gt;, and the name must start with &amp;quot;&amp;lt;tt&amp;gt;__ext_&amp;lt;/tt&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pawn&amp;gt;/**&lt;br /&gt;
 * Do not edit below this line!&lt;br /&gt;
 */&lt;br /&gt;
public Extension:__ext_geoip = &lt;br /&gt;
{&lt;br /&gt;
	name = &amp;quot;GeoIP&amp;quot;,&lt;br /&gt;
	file = &amp;quot;geoip.ext&amp;quot;,&lt;br /&gt;
#if defined AUTOLOAD_EXTENSIONS&lt;br /&gt;
	autoload = 1,&lt;br /&gt;
#else&lt;br /&gt;
	autoload = 0,&lt;br /&gt;
#endif&lt;br /&gt;
#if defined REQUIRE_EXTENSIONS&lt;br /&gt;
	required = 1,&lt;br /&gt;
#else&lt;br /&gt;
	required = 0,&lt;br /&gt;
#endif&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pawn&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explanations:&lt;br /&gt;
*&amp;lt;b&amp;gt;name&amp;lt;/b&amp;gt;: The name of your module as written in &amp;lt;tt&amp;gt;SMEXT_CONF_NAME&amp;lt;/tt&amp;gt;.&lt;br /&gt;
*&amp;lt;b&amp;gt;file&amp;lt;/b&amp;gt;: The platform-inspecific portion of your extension's file name.&lt;br /&gt;
*&amp;lt;b&amp;gt;autoload&amp;lt;/b&amp;gt;: Specifies that your module should always dynamically autoload by default.  You can tweak this to either never autoload or always autoload (without letting the user toggle).&lt;br /&gt;
*&amp;lt;b&amp;gt;required&amp;lt;/b&amp;gt;: Specifies whether or not this extension is '''required''' by your plugin.  If for some reason your extension fails to load (or is not found), the plugin will also fail to load.  This is changeable if you wish to override the default behavior.&lt;br /&gt;
&lt;br /&gt;
You can copy and paste this example, but remember to modify the following portions:&lt;br /&gt;
*&amp;lt;b&amp;gt;__ext_geoip&amp;lt;/b&amp;gt;: Change the &amp;quot;geoip&amp;quot; portion to your own unique variable name.&lt;br /&gt;
*&amp;lt;b&amp;gt;&amp;quot;GeoIP&amp;lt;/b&amp;gt;: Change the GeoIP portion to your extension's name.  This should match the name you chose as &amp;lt;tt&amp;gt;SMEXT_CONF_NAME&amp;lt;/tt&amp;gt;.&lt;br /&gt;
*&amp;lt;b&amp;gt;&amp;quot;geoip.ext&amp;quot;&amp;lt;/b&amp;gt;: Change this to your extension's file name, without the .dll/.so portion.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Global Autoloading==&lt;br /&gt;
To have your extension always autoload, you must create a ''.autoload'' file in the &amp;lt;tt&amp;gt;extensions&amp;lt;/tt&amp;gt; folder.  For example, to have the &amp;lt;tt&amp;gt;threader.ext.dll&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;threader.ext.so&amp;lt;/tt&amp;gt; extensions autoload, you'd create the following file in &amp;lt;tt&amp;gt;extensions&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;threader.autoload&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
*This only works for extensions using the .ext.&amp;lt;platform&amp;gt; convention.  SourceMod cuts off the &amp;quot;.autoload&amp;quot; portion of the file, then adds on &amp;quot;.ext.dll&amp;quot; or &amp;quot;.ext.so&amp;quot; which will not work on custom files.&lt;br /&gt;
*The file does not need to contain anything, it simply needs to exist.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conventions=&lt;br /&gt;
&lt;br /&gt;
==Designing API/Natives==&lt;br /&gt;
*Start interface names with the capital letter 'I'.&lt;br /&gt;
*Use a consistent naming convention.  SourceMod uses [http://msdn2.microsoft.com/en-us/library/ms229002.aspx Microsoft/Pascal] naming.  Avoid Java/Camel casing for both API and natives.&lt;br /&gt;
*When exposing interfaces, make sure your exposure defines start with &amp;lt;tt&amp;gt;SMINTERFACE_&amp;lt;/tt&amp;gt; and end with &amp;lt;tt&amp;gt;_NAME&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;_VERSION&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==External Naming==&lt;br /&gt;
*Logtags (&amp;lt;tt&amp;gt;SMEXT_CONF_LOGTAG&amp;lt;/tt&amp;gt;) should be short names (under 10 characters or so) in all capital letters.&lt;br /&gt;
*Your extension file name should never have &amp;lt;tt&amp;gt;_i486&amp;lt;/tt&amp;gt; or other unnecessary platform-specific notations in its name.&lt;br /&gt;
*Your extension file name should always end in &amp;lt;tt&amp;gt;.ext.so&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;.ext.dll&amp;lt;/tt&amp;gt; depending on the platform.  The &amp;lt;tt&amp;gt;.ext.&amp;lt;/tt&amp;gt; is SourceMod convention.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Setting up Visual Studio=&lt;br /&gt;
==Paths==&lt;br /&gt;
'''Visual Studio 2003''': Tools -&amp;gt; Options -&amp;gt; Projects, VC++ Directories&lt;br /&gt;
&lt;br /&gt;
'''Visual Studio 2005''': Tools -&amp;gt; Options -&amp;gt; Projects and Solutions -&amp;gt; VC++ Directories&lt;br /&gt;
&lt;br /&gt;
===Include Paths===&lt;br /&gt;
*SourceMod only:&lt;br /&gt;
**sdk\public\extensions&lt;br /&gt;
**sdk\public\sourcepawn&lt;br /&gt;
**sdk\public&lt;br /&gt;
*SourceMM (Note that sourcemm might be 'trunk' for you):&lt;br /&gt;
**sourcemm\sourcemm&lt;br /&gt;
**sourcemm\sourcehook&lt;br /&gt;
**sourcemm&lt;br /&gt;
*HL2SDK:&lt;br /&gt;
**game_shared&lt;br /&gt;
**public\vstdlib&lt;br /&gt;
**public\tier1&lt;br /&gt;
**public\tier0&lt;br /&gt;
**public\engine&lt;br /&gt;
**public\dlls&lt;br /&gt;
**public&lt;br /&gt;
**dlls&lt;br /&gt;
&lt;br /&gt;
===Link Paths===&lt;br /&gt;
*HL2SDK:&lt;br /&gt;
**lib\public for version 2005&lt;br /&gt;
**lib-vc7\public for version 2003&lt;br /&gt;
&lt;br /&gt;
==Compiler Options==&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; These options are set by default in the sample Extension SDK.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; These options should be set for every build (Release/Debug/others).&lt;br /&gt;
&lt;br /&gt;
For VS 2005, goto Project-&amp;gt;Properties.&lt;br /&gt;
&lt;br /&gt;
*General&lt;br /&gt;
**&amp;lt;tt&amp;gt;Character Set&amp;lt;/tt&amp;gt;: '''Use Multi-Byte Character Set'''&lt;br /&gt;
*C/C++&lt;br /&gt;
**General&lt;br /&gt;
***&amp;lt;tt&amp;gt;Detect 64-bit Portability Issues&amp;lt;/tt&amp;gt;: '''No'''&lt;br /&gt;
**Preprocessor&lt;br /&gt;
***&amp;lt;tt&amp;gt;Preprocessor Defines&amp;lt;/tt&amp;gt;: Add &amp;lt;tt&amp;gt;_CRT_SECURE_NO_DEPRECATE&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;_CRT_NONSTDC_NO_DEPRECATE&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;SOURCEMOD_BUILD&amp;lt;/tt&amp;gt;  and &amp;lt;tt&amp;gt;WIN32&amp;lt;/tt&amp;gt;&lt;br /&gt;
**Code Generation&lt;br /&gt;
***&amp;lt;tt&amp;gt;Runtime Library&amp;lt;/tt&amp;gt;: Multi-threaded or /MT (for Release), Multi-threaded Debug or /MTd (for Debug)&lt;br /&gt;
*Linker&lt;br /&gt;
**General&lt;br /&gt;
***&amp;lt;tt&amp;gt;Output File&amp;lt;/tt&amp;gt;: Change &amp;lt;tt&amp;gt;$(ProjectName)&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;$(ProjectName).ext&amp;lt;/tt&amp;gt;, or use your own custom string.&lt;br /&gt;
**Input&lt;br /&gt;
***&amp;lt;tt&amp;gt;Additional Dependencies&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;tier0.lib tier1.lib vstdlib.lib&amp;lt;/tt&amp;gt; (for SourceMM attached extensions only)&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod]]&lt;br /&gt;
[[Category:SourceMod Development]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Supported_Games_(Metamod:Source)&amp;diff=7010</id>
		<title>Supported Games (Metamod:Source)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Supported_Games_(Metamod:Source)&amp;diff=7010"/>
		<updated>2009-03-08T20:48:52Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: Changed support for &amp;quot;Dark Messiah&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Metamod:Source]] generally tries to support all Source engine based games. However, some API features may only be supported by some games. This does not mean these features will not work on games not listed here, but that games listed here are specifically known and tested to work.&lt;br /&gt;
&lt;br /&gt;
*'''[[Introduction to SourceMM Coding#User_Message_Enumeration|User Message API Functions]]''' - &amp;lt;tt&amp;gt;GetUserMessageCount()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;FindUserMessage()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;GetUserMessage()&amp;lt;/tt&amp;gt;&lt;br /&gt;
**Battle Grounds 2&lt;br /&gt;
**Counter-Strike: Source&lt;br /&gt;
**Day of Defeat: Source&lt;br /&gt;
**Dystopia&lt;br /&gt;
**Garry's Mod 10&lt;br /&gt;
**Goldeneye: Source&lt;br /&gt;
**Half-Life 2: Capture the Flag&lt;br /&gt;
**Half-Life 2: Deathmatch&lt;br /&gt;
**The Hidden: Source&lt;br /&gt;
**Insects Infestation&lt;br /&gt;
**Jailbreak!&lt;br /&gt;
**Kreedz Climbing&lt;br /&gt;
**Pirates, Vikings, and Knights II&lt;br /&gt;
**Team Fortress 2&lt;br /&gt;
**The Ship&lt;br /&gt;
**SourceForts&lt;br /&gt;
**Zombie Master&lt;br /&gt;
**Dark Messiah&lt;br /&gt;
&lt;br /&gt;
[[Category:Metamod:Source Documentation]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=Supported_Games_(Metamod:Source)&amp;diff=7009</id>
		<title>Supported Games (Metamod:Source)</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=Supported_Games_(Metamod:Source)&amp;diff=7009"/>
		<updated>2009-03-08T20:47:55Z</updated>

		<summary type="html">&lt;p&gt;Matthias Vance: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Metamod:Source]] generally tries to support all Source engine based games. However, some API features may only be supported by some games. This does not mean these features will not work on games not listed here, but that games listed here are specifically known and tested to work.&lt;br /&gt;
&lt;br /&gt;
The only Source-based game completely unsupported by [[Metamod:Source]] is Dark Messiah.&lt;br /&gt;
&lt;br /&gt;
*'''[[Introduction to SourceMM Coding#User_Message_Enumeration|User Message API Functions]]''' - &amp;lt;tt&amp;gt;GetUserMessageCount()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;FindUserMessage()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;GetUserMessage()&amp;lt;/tt&amp;gt;&lt;br /&gt;
**Battle Grounds 2&lt;br /&gt;
**Counter-Strike: Source&lt;br /&gt;
**Day of Defeat: Source&lt;br /&gt;
**Dystopia&lt;br /&gt;
**Garry's Mod 10&lt;br /&gt;
**Goldeneye: Source&lt;br /&gt;
**Half-Life 2: Capture the Flag&lt;br /&gt;
**Half-Life 2: Deathmatch&lt;br /&gt;
**The Hidden: Source&lt;br /&gt;
**Insects Infestation&lt;br /&gt;
**Jailbreak!&lt;br /&gt;
**Kreedz Climbing&lt;br /&gt;
**Pirates, Vikings, and Knights II&lt;br /&gt;
**Team Fortress 2&lt;br /&gt;
**The Ship&lt;br /&gt;
**SourceForts&lt;br /&gt;
**Zombie Master&lt;br /&gt;
**Dark Messiah&lt;br /&gt;
&lt;br /&gt;
[[Category:Metamod:Source Documentation]]&lt;/div&gt;</summary>
		<author><name>Matthias Vance</name></author>
		
	</entry>
</feed>