• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic SA-MP & Pawn Guide
#1
Lightbulb 
BASIC SA-MP? & PAWN GUIDE

[Image: YPOK9Or.png]

INTRO:

This guide is based on other tutorials and on my own experience. It is created specially for new scripters and people who want to learn SA-MP Pawn scripting, it explains just basic scripting and how to start.

* Note: this guide is based on the one I made for?SA-MP forum?in the first months of 2015; if you read this later, some elements may have changed or updated.

Based on:

Nicholas tutorial
Kwarde tutorial
Wiki SA-MP

Own knowledge.



INDEX:

STARTING
? ?
Explaining each file (basic ones)

scriptfiles
plugins
pawno
npcmodes
include
gamemodes
filterscripts
announce.exe
samp-npc.exe
samp-server.exe
server.cfg

CONFIGURATION

PAWN SCRIPTING
? ?
Publics

public OnGameModeInit()
public OnGameModeExit()
public OnPlayerRequestClass(playerid, classid)
public OnPlayerConnect(playerid)
public OnPlayerSpawn(playerid)
public OnPlayerDeath(playerid)
public OnPlayerDisconnect(playerid, reason)
public OnPlayerText(playerid)
public OnPlayerUpdate(playerid)

Functions

SetPlayerPos(playerid, X, Y, Z);
TextDrawCreate(X, Y, text[])

Dialog Function (menus & others)

ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[]);
Message box style (sends a message to the player)
Input style (allows players to input text into the dialog)
List style (menu, show the player a list of options)
Password style (allows players to input text into the dialog without revealing it)

CREATING AND REMOVING OBJECTS

Map editor (1 & 2)

Start using it
Creating objects
Removing objects

MTA map editor

Start using it
Delux GTA Map Converter v2

Creating Objects

Streamer installation



START PRACTICING



STARTING:

First we must download the SA-MP Windows Server from SA-MP.com

After doing this we will open the files contained in the download and after decompressing it, we will see our server files & folders...

Basic files & folders:

scriptfiles, plugins, pawno, npcmodes, include, gamemodes, filterscripts, announce.exe, samp-npc.exe, samp-server.exe & server.cfg

Other files:

Text files that include terms & a configuration guide (samp-license.txt & server-readme.txt respectively).


Explaining each file (basic ones):

scriptfiles: this folder contains information called inside your script or logs created by your script, usually used as a database.

plugins: this folder contains additional codes that give more options in SA-MP programming, usually programmed in other languages. This guide will not give detailed information about plugins as they are more advanced.

pawno: contains the basic program to start scripting in SA-MP; also has the "include" folder that contains basic includes to start our script (SA-MP basic functions). We can also add our own includes and add them to our script.

npcmodes: this contains information about NPCs (script & rec); this guide will not give detailed information about NPCs as they are more advanced.

include: this contains codes that can be included inside your script.

gamemodes: contains basic gamemodes and we must place our gamemode if we create one.

filterscripts: contains additional codes apart from your gamemode, not included in it and can be called by using rcon commands.

announce.exe: this will allow us to show our server on Masterlist.

samp-npc.exe: this will allow us to use NPCs.

samp-server.exe: we start our server with this.

server.cfg: our server configuration.




CONFIGURATION:

First we must open the file "server.cfg" and edit our server configuration.

After opening it, you will find:

Code:
echo Executing Server Config...
lanmode 0
rcon_password changeme
maxplayers 50
port 7777
hostname SA-MP 0.3 Server
gamemode0 grandlarc 1
filterscripts gl_actions gl_realtime gl_property gl_mapicon ls_mall ls_elevator attachments skinchanger vspawner
announce 0
query 1
chatlogging 0
weburl www.sa-mp.com
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
maxnpc 0
logtimeformat [%H:%M:%S]

You can edit your configuration based on this:

Code:
echo Executing Server Config...
lanmode 0?(lan mode on "1" or off "0")
rcon_password changeme?(the rcon password you will use "/Rcon login"; you must edit this)?
maxplayers 50?(amount of slots available for players)
port 7777?(the port you will use, for example: 127.0.0.1:7777)
hostname SA-MP 0.3 server?(the name of your server)
gamemode0 grandlarc1?(name of the gamemode you will use, you can add a gamemode if you create/download one)
filterscripts gl_actions gl_realtime gl_property gl_mapicon ls_mall ls_elevator attachments skinchanger vspawner?(filterscripts that will be used)
announce 0 (server visible on Masterlist; "1" to show it and "0" to hide it)
query 1 (information of the server visible "1", "0" will disable your server information to other players)
chatlogging 0 (save chat logs in server_log.txt "1", not saving it "0")
weburl www.sa-mp.com (website of your server)
onfoot_rate 40 (we will not explain this in this tutorial, advanced)
incar_rate 40 (we will not explain this in this tutorial, advanced)
weapon_rate 40 (we will not explain this in this tutorial, advanced)
stream_distance 300.0 (we will not explain this in this tutorial, advanced)
stream_rate 1000 (we will not explain this in this tutorial, advanced)
maxnpc 0 (number of NPCs that can join your server)
logtimeformat [%H:%M:%S]

You can also read more information about server.cfg?configuration.

Configuration example (this guide is based on this configuration):

Code:
echo Executing Server Config...
lanmode 0
rcon_password Pawn
maxplayers 100
port 7777
hostname SA-MP Server [0.3z]
gamemode0 Basic 1
filterscripts gl_actions gl_realtime gl_property gl_mapicon ls_mall ls_elevator attachments skinchanger vspawner
announce 1
query 1
chatlogging 1
weburl www.sa-mp.com
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
maxnpc 0
logtimeformat [%H:%M:%S]



PAWN SCRIPTING:

After changing our configuration we will start scripting our gamemode.

In this case we will use a basic mode you can download here.

Put it inside the "gamemodes" folder.

After doing this open the pawno folder inside your server and open the file "pawno.exe".

Press "File/Open" (or just press CTRL O) and open our basic mode, placed inside the gamemodes folder.

Inside we have this:

Code:
#include <a_samp>

This is the basic SA-MP include, it will be included in every script you create in SA-MP.

This message will be shown in console when we open our server with samp-server.exe:

Code:
main()
{
print("Blank mode developed by Ygzeb.");
}

The blue text is the message that will be shown.

You can edit the text that you want to be shown in console when your gamemode starts, just editing the blue text; for example:

Code:
main()
{
print("My first mode!");
}

* Note: Every code must have opening and closing braces to start and end the function (all codes).

Example:

Opening braces = Red
Closing braces = Green

main()
{
print("My first mode!");
}


* Note: It is very important to press F5 after editing or creating a script! This will update the AMX file and all changes will be saved ("if there is not mistake", but in special cases may happen programming mistakes that will not figure in the compilation and will affect your server). If everything is okay you will see something like:

[Image: Gobeslv.jpg]

If not there is a mistake and you need to fix it.


Publics:

Publics are basic functions called while your server is running. SA-MP counts with basic publics called in most gamemodes. Most basic public names describe when the public is executed.

Some basic publics are called in special moments, for example while spawning; you can add a function to that moment.

Example; if we want to set players health to 50 when spawning it would be something like:

Code:
public OnPlayerSpawn(playerid)
{
? ?SetPlayerHealth(playerid, 50);
? ?return 1;
}

* Note: we can not use identical publics in the same script; for example two OnPlayerSpawn publics; if we want to add an extra function we must add it inside the same public or inside a filterscript. Base on the last example, we will add a message while spawning:

Code:
public OnPlayerSpawn(playerid)
{
? ?SetPlayerHealth(playerid, 50);
? ?SendClientMessage(playerid, -1, "You spawned!"); // Function added.
? ?return 1;
}

Here are some basic publics that are mostly used by scripters:

public OnGameModeInit() - Called when your mode starts.

Additional information: https://sampwiki.blast.hk/wiki/OnGameModeInit

Basic structure:

Code:
public OnGameModeInit()
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnGameModeInit()
{
? ? UsePlayerPedAnims(); // Allow players to run like CJ.
? ? SetGameModeText("Blank"); // Name of your mode; will be show in SA-MP list.
? ? AddPlayerClass(115, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
? ? AddPlayerClass(122, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
? ? AddPlayerClass(166, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
? ? AddPlayerClass(270, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
? ? return 1;
}

AddPlayerClass is a function that adds skin options to class selection; for example if we want to add Sweet's Skin we should add this to our code:

Code:
AddPlayerClass(270, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);

The number "270" is the skin ID of Sweet.

public OnGameModeExit() - Called when your mode ends; it is not necessary in all scripts (optional in most cases).

Additional information: https://sampwiki.blast.hk/wiki/OnGameModeExit

Basic structure:

Code:
public OnGameModeExit()
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnGameModeExit()
{
? ? print("Mode ended."); // Message to console (blue text).
? ? return 1;
}

public OnPlayerRequestClass(playerid, classid) - Called when you choose your skin.

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerRequestClass

Basic structure:

Code:
public OnPlayerRequestClass(playerid, classid)
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnPlayerRequestClass(playerid, classid)
{
? ? SetPlayerPos(playerid, 2294.2810, 558.2053, 7.7813); // Skin position.
? ? SetPlayerCameraPos(playerid, 2294.3071, 560.6948, 8.7324); // Position of the camera.
? ? SetPlayerCameraLookAt(playerid, 2294.2810, 558.2053, 7.7813); // Position where the camera is looking at.
? ? SetPlayerFacingAngle(playerid, 0);
? ? return 1;
}

SetPlayerFacingAngle sets the angle where the player is looking; it's structure is:

Code:
playerid = ID of the player
0 = angle (in this case north).

? ? north (0)
? ? ? ? ? ?|
(90) west-? ?-east (270)
? ? ? ? ? ?|
? ? ? ? south (180)

More information about SetPlayerFacingAngle.

public OnPlayerConnect(playerid) - Called when a player connects.

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerConnect

Basic structure:

Code:
public OnPlayerConnect(playerid)
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnPlayerConnect(playerid)
{
? ? PlayAudioStreamForPlayer(playerid, "http://s1.radio.ge/Music/AcDc/1980_Back_In_Black/06_Back_In_Black.mp3"); // Will play Back in Black, AC/DC.
? ? return 1;
}

PlayAudioStreamForPlayer is a function that plays an audio stream for a player. It's basic structure is:

Code:
playerid = ID of the player
"http://s1.radio.ge/Music/AcDc/1980_Back_In_Black/06_Back_In_Black.mp3" = audio link

* Note: audio links must be in a specific format to be played; for example thislink.

You can find music in many websites. For example in this website.

public OnPlayerSpawn(playerid) - Used after class selection, while spawning. This are the functions that will affect you when spawning.

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerSpawn

Basic structure:

Code:
public OnPlayerSpawn(playerid)
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnPlayerSpawn(playerid)
{
? ?SendClientMessage(playerid, -1, "You spawned!"); // Sends a message.
? ?return 1;
}

SendClientMessage is a function that sends a message to the player; it's structure is:

Code:
playerid = ID of the player
-1 = Color, -1 is white
"You spawned!" = message

More information about SendClientMessage.

public OnPlayerDeath(playerid) - Called when you die. This function will affect you when you die.

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerDeath

Basic structure:

Code:
public OnPlayerDeath(playerid)
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnPlayerDeath(playerid)
{
? ?GameTextForPlayer(playerid, "Wasted", 5000, 2); // Screen message for player.
? ?return 1;
}

GameTextForPlayer is a function that sends a screen message to the player; it's structure is:

Code:
playerid = ID of the player
"Wasted" = message
5000 = time in milliseconds; in this case 5 seconds
2 = type of message

More information about GameTextForPlayer.

public OnPlayerDisconnect(playerid, reason) - Called when a player disconnects.

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerDisconnect

Basic structure:

Code:
public OnPlayerDisconnect(playerid, reason)
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnPlayerDisconnect(playerid, reason)
{
? ? // Sending a message to all players that a player disconnected.
? ? new String[64], // Variable assigned to a message. 64 is the number of characters that will be used in our message (maybe more).
? ? Name[MAX_PLAYER_NAME];? // Variable assigned to the player's name; usually defined as MAX_PLAYER_NAME.
? ? GetPlayerName(playerid, Name, MAX_PLAYER_NAME); // Getting the name of the player (Name) and it's length? ? ?which is MAX_PLAYER_NAME (default by SA-MP).
? ? format(String, sizeof String, "%s left the server.", Name); // Applying a format to our message.
? ? SendClientMessageToAll(-1, String); // Sending the message to all players; String is the format we used for this message.
? ? return 1;
}

public OnPlayerText(playerid) - Called when a player sends a message (chat).

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerText

Basic structure:

Code:
public OnPlayerText(playerid, text[])
{
? ? // Code here.
? ? return 1;
}

Example code:

Code:
public OnPlayerText(playerid, text[])
{
? ? new Name[MAX_PLAYER_NAME], String[175];
? ? GetPlayerName(playerid, Name, sizeof(Name));
? ? format(String, sizeof(String), "%s [%d]: {FFFFFF}%s", Name, playerid, text); // Assigning a format.
? ? SendClientMessageToAll(GetPlayerColor(playerid), String); // Sending the message with GetPlayerColor, that is the actual color of the player.
? ? return 0; // Ignoring the default text, ending the function.
}

This function is the format assigned to SendClientMessageToAll. When it is send, it will follow that format:

Code:
format(String, sizeof(String), "%s [%d]: {FFFFFF}%s", Name, playerid, text);?

Code:
%s and %d are values assigned depending on the player.
%s is a letter value (in this case the player's name and the text).
%d is a numerical value (ID of the player).

Code:
format(String, sizeof(String), "%s [%d]: {FFFFFF}%s", Name, playerid, text);?

Name, playerid & text are the values assigned to %s, %d and %s.

public OnPlayerUpdate(playerid) - Called everytime a client/player updates the server with their status.

Additional information: https://sampwiki.blast.hk/wiki/OnPlayerUpdate

Basic structure:

Code:
public OnPlayerUpdate(playerid)
{
? ? // Code here.
? ? return 1; // If it returns 0 the client will not be updated to others (like paused).
}

Example code:

Code:
public OnPlayerUpdate(playerid)
{
? ? if(GetPlayerWeapon(playerid) == 38) return Kick(playerid); // Kicking the player if he is using minigun.
? ? return 1;
}

"if" is used to determine that if something is happening, the server will execute that function.

It would mean something like:

If he is using minigun, kick him!

* Note: using "if" in OnPlayerUpdate may cause lag, this is just an example.

Using return means that the function ends there, with "Kick(playerid);". If you have other code down that function, it will not be executed.

For example:

Code:
public OnPlayerUpdate(playerid)
{
? ? if(GetPlayerWeapon(playerid) == 38) return Kick(playerid);
? ? SendClientMessage(playerid, -1, "Updated!"); // Will not be executed if the player is using a minigun.
? ? return 1;
}


Functions:

Basically, most functions names (native functions) describe what the function does; you can find many of them here.

Some basic functions that might be used in a basic gamemode:

SetPlayerPos(playerid, X, Y, Z); - Sets a player position (X, Y & Z are the place where the player will be moved).

Additional information: https://sampwiki.blast.hk/wiki/SetPlayerPos

Example code:

Code:
SetPlayerPos(playerid, 0.0, 0.0, 3.0); // Changes player's position to a farm.

You can save your current position by using the command /Save inside the game (default command by SA-MP). After using this you must go to "\GTA San Andreas User Files\SAMP" and then open the file "savedpositions.txt". There you will find something like:

Code:
AddPlayerClass(270, 700, 700, 5, 0, 0, 0, 0, 0, 0, 0);

Then just copy the red values:

Code:
AddPlayerClass(270, 700, 700, 5, 0, 0, 0, 0, 0, 0, 0);

* Note: obviously our values are not red, it is just for the example.

Then paste those values inside your SetPlayerPos function; like this:

Code:
SetPlayerPos(playerid, 700, 700, 5);

You can also use this system that will do it for you.

TextDrawCreate(X, Y, text[]) - Creates a textdraw (X & Y are the coords in the screen and "text" is the text that will be shown).

Additional information: https://sampwiki.blast.hk/wiki/TextDrawCreate

Example of textdraw:

Code:
new Text:Textdraw0;

public OnGameModeInit()
{
? ? Textdraw0 = TextDrawCreate(240.0, 580.0, "SA-MP 0.3z"); // This creates a textdraw without any modification.
? ? return 1;
}

An easy way to use this function is using a Textdraw Creator.

To show a textdraw to a player you should use the function TextDrawShowForPlayer.

Example of use (based on the last example):

Code:
public OnPlayerConnect(playerid)
{
? ? TextDrawShowForPlayer(playerid, Textdraw0);
}

To hide a textdraw to a player you must use the function TextDrawHideForPlayer.

Example:

Code:
public OnPlayerDisconnect(playerid, reason)
{
? ? TextDrawHideForPlayer(playerid, Textdraw0);
? ? return 1;
}

And to destroy a textdraw you use the function TextDrawDestroy.

Example:

Code:
public OnGameModeInit()
{
? ? TextDrawDestroy(Textdraw0);
? ? return 1;
}


Dialog Function (menus & others):

ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[]); - Shows the player a dialog box.

Additional information: https://sampwiki.blast.hk/wiki/ShowPlayerDialog

* Note: Every dialog needs a unique "dialogid"; unless you do not use that ID inside the public OnDialogResponse (filterscripts and include dialogs must also use a unique dialogid).

There are 4 types of dialog:

Message box style (sends a message to the player):

[Image: Dialog_style_msgbox.png]

Example code (with cancel button):

Code:
if(!strcmp(cmdtext, "/Help", true))
{
? ? new Menu[202]; // This is the number of characters you are using inside your dialog (all characters).
? ? Menu[0]='\0'; // Variable of the dialog, defined before.
? ? strcat(Menu, "This is the text that will be shown inside your dialog. You can add another\n", 77); // 77 is the number of characters in this line.
? ? strcat(Menu, "line using the symbol shown in the upper line (n). You do not need to add\n", 153); // 153 is the number of characters in the other lines plus this line.
? ? strcat(Menu, "that symbol in the last line of your dialog box.", 202); // This are all the characters in your dialog box (202).
? ? ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Dialog Help", Menu, "Accept", "Cancel");
? ? return 1;
}

Every lines has characters; the first line has 77 characters, so we put 77 at the end.

In the second line we have to count the characters in that line plus the characters in all the lines before that line. In this case is 153; so we put 153 at the end.

Example code (without cancel button):

Code:
if(!strcmp(cmdtext, "/Help", true))
{
? ? new Menu[202];
? ? Menu[0]='\0';
? ? strcat(Menu, "This is the text that will be shown inside your dialog. You can add another\n", 77); // strcat? concatenates (joins together) our Menu string and our text.
? ? strcat(Menu, "line using the symbol shown in the upper line (n). You do not need to add\n", 153); // Every line uses strcat.
? ? strcat(Menu, "that symbol in the last line of your dialog box.", 202);
? ? ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Dialog Help", Menu, "Accept", ""); // We leave the second botton just with "".
? ? return 1;
}

The function "strcat"? concatenates (joins together) our Menu string and our text.

* Note: You can use special websites to count characters.

When counting characters you just count the characters inside the ""; for example:

Code:
if(!strcmp(cmdtext, "/Help", true))
{
? ? new Menu[202];
? ? Menu[0]='\0';
? ? strcat(Menu, "This is the text that will be shown inside your dialog. You can add another\n", 77);
? ? strcat(Menu, "line using the symbol shown in the upper line (n). You do not need to add\n", 153);
? ? strcat(Menu, "that symbol in the last line of your dialog box.", 202);
? ? ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Dialog Help", Menu, "Accept", "");
? ? return 1;
}

The \n character also counts.

We can also add a function when we press "Accept" or "Cancel" inside the public OnDialogResponse.

For example:

Code:
if(!strcmp(cmdtext, "/Help", true))
{
? ? new Menu[202];
? ? Menu[0]='\0';
? ? strcat(Menu, "This is the text that will be shown inside your dialog. You can add another\n", 77);
? ? strcat(Menu, "line using the symbol shown in the upper line (n). You do not need to add\n", 153);
? ? strcat(Menu, "that symbol in the last line of your dialog box.", 202);
? ? ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Dialog Help", Menu, "Accept", "");
? ? return 1;
}

We add a message function inside the public OnDialogResponse:

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
? ? if(dialogid == 1) // Number 1 is the number of our dialog.
? ? {
? ? ? ? if(response) // If they clicked 'Accept'.?
? ? ? ? {
? ? ? ? ? ? SendClientMessage(playerid, -1, "Thanks for reading!");
? ? ? ? }
? ? return 1; // Closing dialog response from dialog # 1!
? ? }
return 1; // Closing the public.
}

* Note: When using OnDialogResponse every dialog needs a number. In this case we used number 1:

Code:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Dialog Help", Menu, "Accept", "");
? ? return 1;
}

Input style (allows players to input text into the dialog):

[Image: Dialog_style_input.png]

Example code:

Code:
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Text", "Write a text for all players!", "Accept", "Cancel");

After creating our code we must create a function to that code; so we will use the public OnDialogResponse:

Example code:

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
? ? if(dialogid == 2)
? ? {
? ? ? ? if(!response) // If they clicked 'Cancel'.?
? ? ? ? {
? ? ? ? ? ? SendClientMessage(playerid, -1, "Message canceled!");
? ? ? ? }
? ? ? ? else // If they pressed 'Accept'.
? ? ? ? {
? ? ? ? ? ? new String[200], Name[MAX_PLAYER_NAME]; // Defining variables.
? ? ? ? ? ? GetPlayerName(playerid, Name, MAX_PLAYER_NAME); // Getting player's name.
? ? ? ? ? ? format(String, sizeof(String), "[<!>] Announce from %s: %s", Name, inputtext); // Using a format for the message.
? ? ? ? ? ? SendClientMessageToAll(-1, String);
? ? ? ? }
? ? return 1; // Closing dialog response from dialog # 2!
? ? }
return 1; // Closing the public.
}

List style (menu, show the player a list of options):

[Image: Dialog_style_list.png]

Example code (creating a weapon menu):

Code:
if(!strcmp(cmdtext, "/Weapon", true))
{
? ? ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\n AK-47\n Combat Shotgun", "Select", "Close");
? ? return 1;
}

Code:
"Weapons" = Title of the list.
"Desert Eagle\n AK-47\n Combat Shotgun" = List.
"Select" = Choose a weapon.
"Close" = Close the list.

The \n symbol is used to separate the elements of the list.

To give the weapon we use the public OnDialogResponse:

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
? ? if(dialogid == 3)
? ? {
? ? ? ? if(response) // If they clicked 'Select' or double-clicked a weapon.
? ? ? ? {
? ? ? ? ? ? switch(listitem) // We create a switch to list all the items; each case is a item from our dialog.
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? GivePlayerWeapon(playerid, 24, 14); // Give them a desert eagle with 14 bullets.
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? GivePlayerWeapon(playerid, 30, 120); // Give them an AK-47 with 120 bullets.
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? GivePlayerWeapon(playerid, 27, 28); // Give them a Combat Shotgun with 28 bullets.
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return 1; // Ending the dialog #3.
? ? }
? ? return 1;
}

Structure of the function GivePlayerWeapon:

Code:
GivePlayerWeapon(playerid, weaponid, ammo);

Additional information about this function: https://sampwiki.blast.hk/wiki/GivePlayerWeapon

Password style (allows players to input text into the dialog without revealing it):

[Image: Dialog_style_password.png]

It has the same structure of "Input style"; mostly used in account systems (it is a bit advanced for this tutorial).

If you want to create an account system you can read this tutorials:

Kush account system guide (Y_INI).
Lorenc_ account system guide (SQLite using rBits).





CREATING AND REMOVING OBJECTS:

There are many programs to create maps for your server; the most known are:

Map editor 1
Map editor 2
MTA map editor

Game Object ID List: https://sampwiki.blast.hk/wiki/Model_ID


Map editor (1 & 2):

Both have the same structure; so this is an explanation for both.

Start using it:

- After dowloading it, you must open the file "editor.exe" and press the button "LOAD".

- It will load the game map (GTA-SA); you can move your camera by moving your mouse while clicking the right mouse button. You can move around the map with the mouse scroll or with the keys "W, A, S & D" while pressing the right mouse button.

Creating objects:

- Move to the place where you want to add your mapping, then press the button "Objects" inside the menu (the menu on the right of the window).

- Press "Add" and search the object you want to add (ID or name); then press double click on it and press the button "Add".

- After doing it press on the object shown on the right of the window and after doing it press "insert".

- You can move the object by using the "Movement" panel.

- After mapping you can get the code and add it to your GM by pressing "Show Code". Copy the code and paste it inside the public OnGameModeInit.

Example code:

Code:
public OnGameModeInit()
{
? ? CreateObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0); // Object will render at it's default distance.
? ? return 1;
}

Additional information: https://sampwiki.blast.hk/wiki/CreateObject

Removing objects:

- Move around the map and search the object you want to delete.

- Click on it and press "Supr".

- After deleting the object press "Show Code". Paste the code inside the public OnPlayerConnect.

Example code:

Code:
public OnPlayerConnect(playerid)
{
? ? RemoveBuildingForPlayer(playerid, 3782, 1803.0859, -1294.2031, 34.3438, 0.25);
? ? return 1;
}

Additional information: https://sampwiki.blast.hk/wiki/RemoveBuildingForPlayer


MTA map editor:

This program is easier than the other editor.

You can download it here.

* Note: It is able to create objects but not to delete them from the original map.

Start using it:

- After downloading it, open the file MTA.exe

- Click on the map editor.

- To move around the map use the camera and the keys "W, A, S & D".

- To create objects press "F" and click on the cube object (in the bottom):

[Image: uwz65v3.jpg]

- Search or select your object and place it on the map.

* Note: You can move it down and up by clicking on the object and using the keys "Page Down (pg dn)" and "Page Up (pg up)". To rotate it use "Shift Scroll". To change it's angle use "CTRL Page Down/Page Up" or "CTRL Arrow keys".

- To save your map press the save button:

[Image: bROE6FQ.jpg]

- To get the object code you can use a MTA converter:

Delux GTA Map Converter v2 (2015)

Delux GTA Map Converter v2:

- Instead of IPL file format choose PAWN Code for SA-MP. Search your map inside your MTA folder; it is usually inside \mods\deathmatch\resources.

- Copy your code.


Creating Objects:

After having the code of the object(s), you must add it inside the public OnGameModeInit or OnFilterScriptInit.

Example code:

Code:
public OnGameModeInit()
{
? ? CreateObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0); // Object will render at it's default distance.
? ? CreateObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0, 250.0); // Object will render at 250.0 units (visible at 250 units).
? ? return 1;
}

But SA-MP has an object limit of 1000 objects. If you want to optimize your script or you want to add more objects you should use the plugin Streamer.

Streamer installation:

- Dowload it from the streamer plugin thread.

- After downloading it, paste the file "streamer.so" or "streamer.dll" inside the plugins folder (or just paste the plugins folder, the download one, inside your server folder).

- Copy the include "streamer.inc" inside your pawno includes folder.

- Edit the file "server.cfg" inside your server folder and add this line if you are using Windows:

Code:
plugins streamer.dll

If you are using Linux add:

Code:
plugins streamer.so

- Copy this code down all the includes (include example: #include <a_samp>), inside every script that uses streamer:

Code:
#include <streamer>

#define STREAMER_TYPE_OBJECT (0)
#define STREAMER_TYPE_PICKUP (1)
#define STREAMER_TYPE_CP (2)
#define STREAMER_TYPE_RACE_CP (3)
#define STREAMER_TYPE_MAP_ICON (4)
#define STREAMER_TYPE_3D_TEXT_LABEL (5)
#define STREAMER_TYPE_AREA (6)

#define STREAMER_AREA_TYPE_CIRCLE (0)
#define STREAMER_AREA_TYPE_CYLINDER (1)
#define STREAMER_AREA_TYPE_SPHERE (2)
#define STREAMER_AREA_TYPE_RECTANGLE (3)
#define STREAMER_AREA_TYPE_CUBOID (4)
#define STREAMER_AREA_TYPE_POLYGON (5)

#define STREAMER_OBJECT_TYPE_GLOBAL (0)
#define STREAMER_OBJECT_TYPE_PLAYER (1)
#define STREAMER_OBJECT_TYPE_DYNAMIC (2)

enum
{
? ? E_STREAMER_ATTACHED_OBJECT,
? ? E_STREAMER_ATTACHED_PLAYER,
? ? E_STREAMER_ATTACHED_VEHICLE,
? ? E_STREAMER_ATTACH_OFFSET_X,
? ? E_STREAMER_ATTACH_OFFSET_Y,
? ? E_STREAMER_ATTACH_OFFSET_Z,
? ? E_STREAMER_ATTACH_R_X,
? ? E_STREAMER_ATTACH_R_Y,
? ? E_STREAMER_ATTACH_R_Z,
? ? E_STREAMER_ATTACH_X,
? ? E_STREAMER_ATTACH_Y,
? ? E_STREAMER_ATTACH_Z,
? ? E_STREAMER_COLOR,
? ? E_STREAMER_DRAW_DISTANCE,
? ? E_STREAMER_EXTRA_ID,
? ? E_STREAMER_INTERIOR_ID,
? ? E_STREAMER_MAX_X,
? ? E_STREAMER_MAX_Y,
? ? E_STREAMER_MAX_Z,
? ? E_STREAMER_MIN_X,
? ? E_STREAMER_MIN_Y,
? ? E_STREAMER_MIN_Z,
? ? E_STREAMER_MODEL_ID,
? ? E_STREAMER_MOVE_R_X,
? ? E_STREAMER_MOVE_R_Y,
? ? E_STREAMER_MOVE_R_Z,
? ? E_STREAMER_MOVE_SPEED,
? ? E_STREAMER_MOVE_X,
? ? E_STREAMER_MOVE_Y,
? ? E_STREAMER_MOVE_Z,
? ? E_STREAMER_NEXT_X,
? ? E_STREAMER_NEXT_Y,
? ? E_STREAMER_NEXT_Z,
? ? E_STREAMER_PLAYER_ID,
? ? E_STREAMER_R_X,
? ? E_STREAMER_R_Y,
? ? E_STREAMER_R_Z,
? ? E_STREAMER_SIZE,
? ? E_STREAMER_STREAM_DISTANCE,
? ? E_STREAMER_STYLE,
? ? E_STREAMER_TEST_LOS,
? ? E_STREAMER_TYPE,
? ? E_STREAMER_WORLD_ID,
? ? E_STREAMER_X,
? ? E_STREAMER_Y,
? ? E_STREAMER_Z
}

* Note: This code is based on the Streamer plugin update from 2015 (v2.7.4).

- After doing this edit the object code you have. Instead of using "CreateObject" use "CreateDynamicObject".

Example:

Instead of using a normal code...

Code:
public OnGameModeInit()
{
? ? CreateObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0);
? ? return 1;
}

Use this:

Code:
public OnGameModeInit()
{
? ? CreateDynamicObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0);
? ? return 1;
}

* Note: You can edit your "CreateObject" code faster by using a ".txt" file. Paste the code inside of it; press "CTRL R", search "CreateObject" and replace it with "CreateDynamicObject" (use this if your map is very big).

- After doing this open the PWN file where you want to add the objects (usually inside the gamemode) and paste your code.

Example code:

Code:
public OnGameModeInit()
{
? ? CreateDynamicObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0);
? ? return 1;
}

Additional information about Streamer plugin.




START PRACTICING:

Now you know this, you can practice by editing other scripts or you can try creating your own script.

A good way of starting is editing other gamemodes!

If there is any mistake in this guide or something should be added, just post it.

* Note: this is an small guide compared to all the basic information of SA-MP that a new scripter should know; this guide will be updated according to post suggestions on this thread.




Guide credits: Ygzeb (David Talledo)

Special thanks to:

Y_Less for a correction in some information presented in this guide and Kwarde that helped to update some links that were broken (2021) :)

Addon (2021) .- Some links or images may just not work now or in the future, they may be fixed or not. However, I hope this guide will still help people.
Away
  Reply
#2
This is a great starting guide. I'm glad you didn't try to push vscode or other IDE down a begginer's throat like many others do for some reason.
  Reply
#3
Good topic, i like it! Thank you very much
  Reply
#4
(2019-08-13, 06:51 PM)Markski Wrote: This is a great starting guide. I'm glad you didn't try to push vscode or other IDE down a begginer's throat like many others do for some reason.



Actually ides like vscode or even a complete vs installation makes your whole workflow easirr and fancier consider vscode combined with sampctl for example
  Reply
#5
Very nice, but with one common misconception:



() - these are brackets

{} - these are braces
  Reply
#6
(2021-05-09, 04:11 PM)Y_Less Wrote: Very nice, but with one common misconception:



() - these are brackets

{} - these are braces



Aren't () called parenthesis?
  Reply
#7
No. Parentheses are anything that enclose additional text. For example:

Quote:James, who just woke up, went to the shop.

"who just woke up" is additional information, and is enclosed by ","s. Thus they are parentheses. Brackets, dashes, semi-colons, and probably more, can all be used in this way; to parenthesise information. I actually only learnt this the other day as well.
  Reply
#8
(2021-05-15, 10:03 AM)Y_Less Wrote: "who just woke up" is additional information, and is enclosed by ","s.? Thus they are parentheses.? Brackets, dashes, semi-colons, and probably more, can all be used in this way; to parenthesise information.? I actually only learnt this the other day as well.



This is the most useful thing I ever learned from you



And to go a bit more on topic:

Quote:Based on:



Nicholas tutorial

Kwarde tutorial

Wiki SA-MP

Do you mean some kind of tutorial (or tutorials) I once wrote? I read it back some time ago and it wasn't that good at all (in fact, reading things I wrote as a kid is close to shamefull). Thanks though :-P



Also you might want to consider changing the URLs in this post, replacing "http://wiki.sa-mp.com/wiki/" with "https://sampwiki.blast.hk/wiki/". That would make it even more usefull ;-)
  Reply
#9
Big Grin 
(2019-08-13, 06:51 PM)Markski Wrote: This is a great starting guide. I'm glad you didn't try to push vscode or other IDE down a begginer's throat like many others do for some reason.

Thanks friend!

(2019-08-17, 09:27 AM)Tyson Wrote: Good topic, i like it! Thank you very much

Thanks to you, I'm happy you found it helpful ^^

(2021-05-07, 05:37 AM)Chakib Chemso Wrote:
(2019-08-13, 06:51 PM)Markski Wrote: This is a great starting guide. I'm glad you didn't try to push vscode or other IDE down a begginer's throat like many others do for some reason.

Actually ides like vscode or even a complete vs installation makes your whole workflow easirr and fancier consider vscode combined with sampctl for example

You are right friend; tho we didn't have them back (at least most of us)?in 2015, but yeah, if you have some experience with Pawn, VS sampctl is way better in my opinion. For starting and practicing I would still recommend using the classic.

(2021-05-09, 04:11 PM)Y_Less Wrote: Very nice, but with one common misconception:

() - these are brackets
{} - these are braces

Hey friend, thanks for appreciating this thread & for the additional information; I wasn't aware of that small mistake since 2015 till just now haha. We always learn something new when it's about programming.

"Brackets" changed to "Braces", thanks for the input! :)

(2021-05-21, 08:32 AM)Kwarde Wrote:
Quote:Based on:

Nicholas tutorial
Kwarde tutorial
Wiki SA-MP
Do you mean some kind of tutorial (or tutorials) I once wrote? I read it back some time ago and it wasn't that good at all (in fact, reading things I wrote as a kid is close to shamefull). Thanks though :-P

Also you might want to consider changing the URLs in this post, replacing "http://wiki.sa-mp.com/wiki/" with "https://sampwiki.blast.hk/wiki/". That would make it even more usefull ;-)

Yeah, probably one tutorial of yours; despite the mistakes you say you made, I probably found some useful information in them so... They weren't that bad, and credit where credit's due ^^

PD: Just updated the guide with your new link (https://sampwiki.blast.hk/wiki/), thanks!
Away
  Reply


Forum Jump: