[Tutorial] Scripting in PAWN for SA-MP Modification
#1

SCRIPTING IN PAWN FOR SA-MP MODIFICATION
Variable

What is a variable? A variable is basically a bit of memory that stores a value and can be changed on runtime (runtime is when the server is running)

Quoted from Wikipedia:

In computer programming, a variable or scalar is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value.

Quick notes:

1. A value is a piece of stored information that can be manipulated by the computer.
2. A symbolic name or identifier is just a name for a variable which stores a value.
3. When creating a variable you give it a name (a symbolic name or identifier) and a value.

Data type

What is a data type? A data type is a type of variable.

Quoted from Wikipedia:

In computer science and computer programming, a data type or simply is type a classification identifying one of various types of data, such as real, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.

Data types in PAWN:

- "Boolean"
pawn Код:
new boolean:myBoolean  = true;
- "Integer"
pawn Код:
new myInteger = 17;
- "Float"
pawn Код:
new Float:myFloat = 85.567;
- "String"
pawn Код:
new playername[24] = “Bertie”;
- "Array"
pawn Код:
new myArray[4];
Quick notes:

1. A boolean stores two values which are denoted as true and false.
2. An integer stores integral values which are whole numbers.
3. A float stores floating-point values which have potential decimal places
4. A string stores a text.
5. An array stores a collection of values using one variable name.

Function

What is a function? A function is a structure of instructions that perform a specific task when called by the server.

Quoted from Wikipedia:

In computer programming, a subroutine is a sequence of program instructions that perform a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.
In different programming languages a subroutine may be called a procedure, a function, a routine, a method, or a subprogram. The generic term callable unit is sometimes used.


Example of scripting a function:

pawn Код:
forward pName(playerid); // Forwarding the function
public pName(playerid)
{
    new playername[24]; // We create a string for storing the text (player's name)
    GetPlayerName(playerid, playername, sizeof(playername)); // We use a native function for getting the player's name
    return playername;
}

// We created that function to easier get a player name anywhere in the script when called, for example:

public OnPlayerConnect(playerid) // Callback
{
    new string[128]; // We create a string for storing the text (message)
    format(string, sizeof(string), "%s has connected to the server", pName(playerid)); // We format the string to include another string
    SendClientMessageToAll(string, -1); // We use a native to send the message to all players
    return 1;
}
Native function

What is a native function? A native function is a function that is already implemented into the script by another scripter(s).

Quoted from Wikipedia:

The "native" adjective refers to software or data formats supported by a certain system with minimal computation overhead and additional components.

Example of a native function:

pawn Код:
native SendClientMessage(playerid, color, const message[]);
Click here to redirect to all native functions





To be continued.....
Please only give your opinion on what is written so far
Reply
#2

That's actually useful for newbies who have zero idea about sa-mp scripting and all.
Nice Job!
I'd keep track of this tutorial and I'd give you a rep if you complete it!
Reply
#3

The quoted text appears very sophisticated; I don't think the majority of the people here understand anything at all. Use layman's terms instead.
Reply
#4

Quote:
Originally Posted by iReacheR
Посмотреть сообщение
That's actually useful for newbies who have zero idea about sa-mp scripting and all.
Nice Job!
I'd keep track of this tutorial and I'd give you a rep if you complete it!
Thank you, I will be continuing it next week.

Quote:
Originally Posted by Vince
Посмотреть сообщение
The quoted text appears very sophisticated; I don't think the majority of the people here understand anything at all. Use layman's terms instead.
Actually, I did used layman's terms before I quoted Wikipedia definitions.
Reply
#5

new playername[24] = “Bertie”

";"

native SendClientMessage(playerid, color, constmessage[]);

"const message[]"
Reply
#6

Quote:
Originally Posted by Kar
Посмотреть сообщение
new playername[24] = “Bertie”

";"

native SendClientMessage(playerid, color, constmessage[]);

"const message[]"
Thank you for identifying those errors, edited.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)