22.11.2014, 22:47
This guide is mainly devoted to those who actually have no scripting experience; which may mean that this is their entirely first programming language. If PAWN is your first language, and you don't even know that much about scripting in general, then things can really get confusing. This is aiming to be a step-by-step guide on getting started with scripting; mainly targeting the language SA-MP uses, which is PAWN.
Your first small leap into the world of scripting:
This is the hardest part, actually leaping into the scripting world. The first thing you're going to want to do is actually get the tools you'll need. The tools you'll need to get started scripting in PAWN can be found below:
SA-MP Server Package:
You can find these at sa-mp.com/download.php. In addition, I'd recommend downloading the latest one which is usually found in the News And Updates section.
Once you've downloaded it you'll need to open the file in a program such as winrar, or winzip, - which can open .zip files. Once opened, it should look something like this generally,
You'll want to extract it to a folder which can, generally, be anywhere. I'd recommend it being in a easy-to-access
location such as: Your... Desktop; Download, or Documents folder.
Once you've extracted the files it should look something like this,
Now, open the pawno folder, and run pawno.exe. Usually, it should come up with something that looks like this:
Just simply click the "ok" box. A application should come up looking like this,
Now to prevent the "Failed to set data for" box from popping up again, we'll need to adjust the settings. We can do this by clicking the options tab, and deselecting "Assosicate with .pwn files". This should repair the issue.
Now, that we've set everything up we can actually begin scripting! Press CTRL+N or go file-new. This should open a new pawno document. Now, - just delete everything. We'll be making our own short PAWN script which allows us to display detailed user information of every user online with the RCON command "playerdetails".
We need to start by including the "a_samp" file. This is usually in every .pwn file, and is extremely important. We can define files by doing the following:
#include a_samp
By default, there is no way to check if a file is included or not. How-ever, you shouldn't need to know about these kinds of things just yet.
The next thing we need to do is set up a function header. We do this by using the keyword "public", the name of the callback, and then it's params. In this case, it would be:
Now, we are going to need to put a opening bracket since our code isn't a single line. This tells the compiler what's inside the function, and whats not.
Now, we will need to use a function. In this case, it'll be "strcmp" which allows us to check the string, and compare it to another string.
In this case we'll be comparing it to "playerdetails", since that is going to be the command name.
Now, we'll need another bracket for this too indicating that the code is only going to be processed if the "if" statement is true to it's statement.
Then, we'll need to use a few more functions.
We'll need to declare a few things. In some languages such as PHP, definitions aren't needed, how-ever in PAWN they are. They can be declared using the keyword "new".
This might look like a lot, but it's not. Tags such as "Float" tell the compiler what kind of variable we are declaring. In this case, X which is going to be the player's coordinate is a float value, so we declare it as so.
Now, to get data of all connected players we need to loop. Looping is a way to call code for more than one thing, in simple terms.
This basically declares a temporary variable, and processes a code for each player. Now, to avoid un-needed code, we can check if the player's connected.
Then, we can actually start collecting the data for the player. We'll start by getting their: coordinates, health, name, and IP address.
Now, all these functions used something called "variables passed by reference". This basically passes the variable through, and any changes are sent through it, and into the variable, formatting the variable accordingly. In the end it will give us the information we need.
Now, we need to format this data into a string. A string is basically a collection of characters. We can format these using the format function.
Now, just because we format a string doesn't mean we're done. We have to show this data to the consle using the "print" function.
We can do this accordingly:
Now we have to tell the compiler we are done with the loop. We can do this simply by putting a closing bracket.
Now, we still have to close out the function. So we'll put another bracket the next line below it,
Now, we just have to compile our script. We can do this either by using CTRL+F5, or by going to "build" and hitting "compile". If everything goes well, you should see a screen looking like this,
And that's it! You've made your first script. You can find even more documentation on the PAWN language here:
http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf
Your first small leap into the world of scripting:
This is the hardest part, actually leaping into the scripting world. The first thing you're going to want to do is actually get the tools you'll need. The tools you'll need to get started scripting in PAWN can be found below:
SA-MP Server Package:
You can find these at sa-mp.com/download.php. In addition, I'd recommend downloading the latest one which is usually found in the News And Updates section.
Once you've downloaded it you'll need to open the file in a program such as winrar, or winzip, - which can open .zip files. Once opened, it should look something like this generally,
You'll want to extract it to a folder which can, generally, be anywhere. I'd recommend it being in a easy-to-access
location such as: Your... Desktop; Download, or Documents folder.
Once you've extracted the files it should look something like this,
Now, open the pawno folder, and run pawno.exe. Usually, it should come up with something that looks like this:
Just simply click the "ok" box. A application should come up looking like this,
Now to prevent the "Failed to set data for" box from popping up again, we'll need to adjust the settings. We can do this by clicking the options tab, and deselecting "Assosicate with .pwn files". This should repair the issue.
Now, that we've set everything up we can actually begin scripting! Press CTRL+N or go file-new. This should open a new pawno document. Now, - just delete everything. We'll be making our own short PAWN script which allows us to display detailed user information of every user online with the RCON command "playerdetails".
We need to start by including the "a_samp" file. This is usually in every .pwn file, and is extremely important. We can define files by doing the following:
#include a_samp
By default, there is no way to check if a file is included or not. How-ever, you shouldn't need to know about these kinds of things just yet.
The next thing we need to do is set up a function header. We do this by using the keyword "public", the name of the callback, and then it's params. In this case, it would be:
pawn Code:
public OnRconCommand(cmd[])
pawn Code:
{
In this case we'll be comparing it to "playerdetails", since that is going to be the command name.
pawn Code:
if(strcmp(cmd, "playerdetails", true) == 0)
pawn Code:
{
We'll need to declare a few things. In some languages such as PHP, definitions aren't needed, how-ever in PAWN they are. They can be declared using the keyword "new".
pawn Code:
new Float: X, Float: Y, Float: Z, string[], IP, name, Float: health, Float: armor
Now, to get data of all connected players we need to loop. Looping is a way to call code for more than one thing, in simple terms.
pawn Code:
for (new i = 0; i != MAX_PLAYERS; ++i)
{
pawn Code:
if(IsPlayerConnected(i))
{
pawn Code:
GetPlayerPos(playerid, X, Y, Z);
GetPlayerHealth(playerid, Health);
GetPlayerName(playerid, name, sizeof(name));
GetPlayerIp(playerid, ip, sizeof(ip));
Now, we need to format this data into a string. A string is basically a collection of characters. We can format these using the format function.
pawn Code:
format(string, sizeof(string), "%f %f %f - %f - %s - %s", X, Y, Z, Health, name, ip);
We can do this accordingly:
pawn Code:
print(string);
pawn Code:
}
pawn Code:
}
And that's it! You've made your first script. You can find even more documentation on the PAWN language here:
http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf