Pawn (scripting language)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
PAWN
Pawn logo.png
Developer ITB CompuPhase
Appeared in 1998
Stable release 4.0.4733 / 22 June 2012[1]
Typing discipline dynamic
Influenced by Small-C[2]
OS Cross-platform
License Apache License 2.0 with linking exception
Website www.compuphase.com/pawn/pawn.htm

Pawn, formerly known as Small, is an open source scripting language primarily intended as an embeddable scripting language. It is maintained by the Dutch company CompuPhase, which released the first version in 1998.[3] The language was known as Small until version 3 was released in March 2005.[3]

Pawn is a dynamically typed language influenced by Small-C. and has C-like syntax.[4]

Pawn is used in the San Andreas Multiplayer mod, Half-Life mod, AMX Mod X and Source Engine based SourceMod as well as other projects.[5]

Design[edit]

Pawn is a compiled language. Its regular extension is '.p' or '.pwn'.

The Pawn compiler compiles to P-code (or bytecode) that will be written to a file with a '.amx' extension.

Features[edit]

  • Pawn is a C-like Scripting Language
  • Files can be included; neat structures of Pawn code can be arranged
  • Its compiler performs static checks, and its abstract machine performs (static) P-code verification and dynamic checks.
  • For porting purposes, Pawn is written in ANSI C as much as possible; Endian issues are handled.
  • Pawn supports Unicode/UCS-4 and UTF-8, as well as codepages. The compiler can convert source code entered in a particular codepage to Unicode; it also supports source code files in UTF-8 format.
  • It has been implemented on the Atmel ATmega128 microcontroller, Philips LPC2138 and LPC2106 microcontrollers (ARM7TDMI core with 32 kiB RAM), and on Texas Instrument's MSP430F1611 (MSP430 core with 10 kiB RAM and 48 kiB Flash ROM). Using code overlays that are loaded on demand, Pawn can run large scripts in little memory.
  • Documenting the source code can be done with "documentation comments;" the pawn compiler extracts those comments, combines them with information it deduces from the source code and writes an XML file that is immediately viewable (and printable) with a web browser.
  • Pawn supports states and automatons in the language, including state-local variables.

Uses[edit]

Grand Theft Auto: San Andreas Multiplayer[edit]

A common use for Pawn is in the popular unofficial Grand Theft Auto: San Andreas modification "San Andreas Multiplayer". This allows server hosts to enable their scripts to perform all the tasks available to players of the single player version of "Grand Theft Auto: San Andreas". This is made possible by the ability for server hosts to create their own "game modes" with the PAWN compiler. The implementation of the PAWN language also allows users to interact with the game in ways previously not possible in the single player environment.

SourceMod & AMX Mod X[edit]

Another usage of Pawn is in the SourceMod and AMX Mod X platforms, which are used in Source engine games such as Counter Strike: Source, Counter Strike: Global Offensive, Team Fortress 2, Left 4 Dead, Left 4 Dead 2, etc.

SourceMod in particular utilizes an off-shoot of Pawn called SourcePawn, allowing modders to create things from basic commands to entirely new gamemodes (like VS Saxton Hale in Team Fortress 2, for example). The plugin system in SourceMod is completely modular, allowing server hosts to run a large number of plugins at the same time without affecting gameplay (provided the plugins in use have been coded correctly and do not cause errors).

Side-script design[edit]

PAWN is designed to be used as a side-script with code from other languages. PAWN does not ship with native functions which can be used for developing, instead Pawn's functions come from "include" files.

Code Examples[edit]

Example of code that prints random number 4 times:

#include <core>
main()
{
    for(new i=1; i<=4; i++) //Will loop 4 times.
    {
        printf("Number %d's value is %d.", i, random(5000)); //Prints the number's number and the random (in between 0 and 5000) number's value on screen.
    }
}

Here is an example of code that prints 4 random numbers in one line.

#include <core>
main()
{
    new array[4]; //Declares a new array that can store 4 integers.
    for(new i=0; i<4; i++) //Will loop 4 times.
    {
        array[i] = random(5000); //Saves random (in between 0 and 5000) number to array's slot of given value.
    }
    printf("The numbers are: %d, %d, %d, %d.", array[0], array[1], array[2], array[3]); //Prints the numbers by accessing all array's slots.
}

'Hello World!' example:

#include <core>
main() {
    print("Hello World!");
}

"Hello World" example using the SourcePawn language which is used for creating plugins for Source engine games that use the SourceMod addon system. In this example, a command is created that can be used from the ingame console to display a hello world message to the client that used the command. The command can also be used from ingame by using "!helloworld" or "/helloworld" in chat.

#include <sourcemod>
#pragma semicolon 1
 
public OnPluginStart() {
    RegConsoleCmd("sm_helloworld", Command_HelloWorld, "Displays a greeting message");
}
 
public Action:Command_HelloWorld(client, args) {
    PrintToChat(client, "Hello world!");
    return Plugin_Handled;
}

See also[edit]

References[edit]

  1. ^ "The Pawn Language". Compuphase. Retrieved 2011-07-19. 
  2. ^ "The Pawn Booklet: 1. Language Guide". Compuphase. 2008-03-04. 
  3. ^ a b history.txt, distributed with the source code. Compuphase.com
  4. ^ "The Pawn language". Compuphase. Retrieved 2008-03-08. 
  5. ^ "The Pawn language - projects". Compuphase. 

External links[edit]