[Tutorial] How to get started as a new scripter(Mainly in PAWN)
#1

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:
pawn Code:
public OnRconCommand(cmd[])
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.
pawn Code:
{
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.
pawn Code:
if(strcmp(cmd, "playerdetails", true) == 0)
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.
pawn Code:
{
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".
pawn Code:
new Float: X, Float: Y, Float: Z, string[], IP, name, Float: health, Float: armor
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.

pawn Code:
for (new i = 0; i != MAX_PLAYERS; ++i)
{
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.
pawn Code:
if(IsPlayerConnected(i))
{
Then, we can actually start collecting the data for the player. We'll start by getting their: coordinates, health, name, and IP address.

pawn Code:
GetPlayerPos(playerid, X, Y, Z);
GetPlayerHealth(playerid, Health);
GetPlayerName(playerid, name, sizeof(name));
GetPlayerIp(playerid, ip, sizeof(ip));
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.

pawn Code:
format(string, sizeof(string), "%f %f %f - %f - %s - %s", X, Y, Z, Health, name, ip);
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:
pawn Code:
print(string);
Now we have to tell the compiler we are done with the loop. We can do this simply by putting a closing bracket.
pawn Code:
}
Now, we still have to close out the function. So we'll put another bracket the next line below it,
pawn Code:
}
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
Reply
#2

Nice tutorial.
Reply
#3

The will help many fast learners. Nice tut.
Reply
#4

Lol Actuallize (sorry for my bad english, I am Brazilian) You use strcmp for cmds? Actually use Cmds processor , very
fast, Who want learn no see this tutorial!
Reply
#5

Quote:
Originally Posted by Someone
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.
@PedexM - This is tutorial for new guys. Start from bottom and reach top. If you start from top you will end up studying bottom and everything till top again.
Reply
#6

Looks good, i didn't even know how to stop that "failed to set" box from opening
Reply
#7

Quote:
Originally Posted by LeXuZ
View Post
Looks good, i didn't even know how to stop that "failed to set" box from opening
Running it on administrator privilage can also fix that

BTW: Nice tut

i actually did that for opening the world of scripting to me
and further increase my learning capabilities in joining the SA_MP forums
Reply
#8

Thank you! And @PedexM, - It's an RCON Command. Strcmp was used to compare if the RCON command matched the phrase "playerdetails".
Reply
#9

I got underneath, but this tutorial only teaches How to Open, and is very outdated using useless things, it is better
to take a Handout on Logic Programming and implement, PAWN no future, it is useless!

#Edit

And Rcon Command:

pawn Code:
#include <zcmd>

CMD:gmx()//Simple Example of Rcon Command
{
    if(!IsPlayerAdmin) return SendClientMessage(playerid, -1, "Error : you dont have permissions for use the command");
    SendRconCommand("gmx");
    return 1;
}
There are easier ways, these ways you can teach is to harming a beginner!
Reply
#10

That's not an RCON Command. An RCON command is used with "/rcon (command)" or "command" in the console. And I don't find any mistakes, or any thing that can be considered harmful to a scripter's development.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)