Return to site

Scripts For Samp Server

broken image


  • FiveM is a modification for Grand Theft Auto V enabling you to play multiplayer on customized dedicated servers, powered by Cfx.re. FiveM Scripts, MLO, YMAP, Reviews, Tutorials, Installation Guides. All what your Server and Players need.
  • Discussion on SA-MP Release von Server Script's within the Grand Theft Auto forum part of the Other Online Games category., 16:18 #1.

San Andreas Multiplayer Zombie Servers list, find the best SAMP servers of zombie type / gamemode. Ranked by status, players online & players votes.

2019-08-02, 08:02 PM (This post was last modified: 2019-08-04, 06:30 PM by Ygzeb.)


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:
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:
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):
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:
#include

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:
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:
main()
{
print('My first mode!');
}

* Note: Every code must have opening and closing brackets to start and end the function (all codes).
Example:
Opening brackets = Red
Closing brackets = 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:
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:
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:
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: http://wiki.sa-mp.com/wiki/OnGameModeInit
Basic structure:
public OnGameModeInit()
{
// Code here.
return 1;
}

Example 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:

Free Samp Server

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: http://wiki.sa-mp.com/wiki/OnGameModeExit
Basic structure:
public OnGameModeExit()
{
// Code here.
return 1;
}

Example 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: http://wiki.sa-mp.com/wiki/OnPlayerRequestClass
Basic structure:
public OnPlayerRequestClass(playerid, classid)
{
// Code here.
return 1;
}

Example 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:
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: http://wiki.sa-mp.com/wiki/OnPlayerConnect
Basic structure:
public OnPlayerConnect(playerid)
{
// Code here.
return 1;
}

Example 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:
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: http://wiki.sa-mp.com/wiki/OnPlayerSpawn
Basic structure:
public OnPlayerSpawn(playerid)
{
// Code here.
return 1;
}

Example 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:
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: http://wiki.sa-mp.com/wiki/OnPlayerDeath
Basic structure:
public OnPlayerDeath(playerid)
{
// Code here.
return 1;
}

Example 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:
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: http://wiki.sa-mp.com/wiki/OnPlayerDisconnect
Basic structure:
public OnPlayerDisconnect(playerid, reason)
{
// Code here.
return 1;
}

Example 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: http://wiki.sa-mp.com/wiki/OnPlayerText
Basic structure:
public OnPlayerText(playerid, text[])
{
// Code here.
return 1;
}

Example 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:
format(String, sizeof(String), '%s [%d]: {FFFFFF}%s', Name, playerid, text);

%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).

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: http://wiki.sa-mp.com/wiki/OnPlayerUpdate
Basic structure:
public OnPlayerUpdate(playerid)
{
// Code here.
return 1; // If it returns 0 the client will not be updated to others (like paused).
}

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

'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:
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: http://wiki.sa-mp.com/wiki/SetPlayerPos
Example 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 FilesSAMP' and then open the file 'savedpositions.txt'. There you will find something like:
AddPlayerClass(270, 700, 700, 5, 0, 0, 0, 0, 0, 0, 0);

Then just copy the red values:
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:

Script Samp Server


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: http://wiki.sa-mp.com/wiki/TextDrawCreate
Example of textdraw:
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):
public OnPlayerConnect(playerid)
{
TextDrawShowForPlayer(playerid, Textdraw0);
}

To hide a textdraw to a player you must use the function TextDrawHideForPlayer.
Example:
public OnPlayerDisconnect(playerid, reason)
{
TextDrawHideForPlayer(playerid, Textdraw0);
return 1;
}

And to destroy a textdraw you use the function TextDrawDestroy.
Example:
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: http://wiki.sa-mp.com/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:

Scripts For Samp Servers


Message box style (sends a message to the player):
Example code (with cancel button):
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 anothern', 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 addn', 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):
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 anothern', 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 addn', 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:
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 anothern', 77);
strcat(Menu, 'line using the symbol shown in the upper line (n). You do not need to addn', 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:
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 anothern', 77);
strcat(Menu, 'line using the symbol shown in the upper line (n). You do not need to addn', 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:
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:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, 'Dialog Help', Menu, 'Accept', ');
return 1;
}

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

Samp Roleplay Scripts


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:
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.
}

Script samp server

'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:
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: http://wiki.sa-mp.com/wiki/SetPlayerPos
Example 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 FilesSAMP' and then open the file 'savedpositions.txt'. There you will find something like:
AddPlayerClass(270, 700, 700, 5, 0, 0, 0, 0, 0, 0, 0);

Then just copy the red values:
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:

Script Samp Server


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: http://wiki.sa-mp.com/wiki/TextDrawCreate
Example of textdraw:
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):
public OnPlayerConnect(playerid)
{
TextDrawShowForPlayer(playerid, Textdraw0);
}

To hide a textdraw to a player you must use the function TextDrawHideForPlayer.
Example:
public OnPlayerDisconnect(playerid, reason)
{
TextDrawHideForPlayer(playerid, Textdraw0);
return 1;
}

And to destroy a textdraw you use the function TextDrawDestroy.
Example:
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: http://wiki.sa-mp.com/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:

Scripts For Samp Servers


Message box style (sends a message to the player):
Example code (with cancel button):
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 anothern', 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 addn', 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):
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 anothern', 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 addn', 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:
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 anothern', 77);
strcat(Menu, 'line using the symbol shown in the upper line (n). You do not need to addn', 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:
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 anothern', 77);
strcat(Menu, 'line using the symbol shown in the upper line (n). You do not need to addn', 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:
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:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, 'Dialog Help', Menu, 'Accept', ');
return 1;
}

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

Samp Roleplay Scripts


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:
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):
Example code (creating a weapon menu):
if(!strcmp(cmdtext, '/Weapon', true))
{
ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, 'Weapons', 'Desert Eaglen AK-47n Combat Shotgun', 'Select', 'Close');
return 1;
}

'Weapons' = Title of the list.
'Desert Eaglen AK-47n 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:
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:
GivePlayerWeapon(playerid, weaponid, ammo);

Additional information about this function: http://wiki.sa-mp.com/wiki/GivePlayerWeapon
Password style (allows players to input text into the dialog without revealing it):
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: http://wiki.sa-mp.com/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:
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: http://wiki.sa-mp.com/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:
public OnPlayerConnect(playerid)
{
RemoveBuildingForPlayer(playerid, 3782, 1803.0859, -1294.2031, 34.3438, 0.25);
return 1;
}

Additional information: http://wiki.sa-mp.com/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):
- 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:
- 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 modsdeathmatchresources.
- 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:
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:
plugins streamer.dll

If you are using Linux add:
plugins streamer.so

- Copy this code down all the includes (include example: #include ), inside every script that uses streamer:
#include
#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...
public OnGameModeInit()
{
CreateObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0);
return 1;
}

Samp Servers English


Use this:
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:

Samp Rp Servers

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)



broken image