[Tutorial] Scripting [BEGINNER]
#1

Greetings.

This is a basic tutorial made for beginners at SA:MP Scripting. Remember, This is not a professionally made tutorial. There are a lot of other good tutorials you can find on SA:MP forums. I have just decided to make one. So let's begin.

What is SA:MP?
San Andreas Multiplayer (SA:MP) is a modification for Grand Theft Auto: San Andreas which turns it into a multiplayer game. You can play over the internet with other people. You need the original Grand Theft Auto: San Andreas PC game to play San Andreas Multiplayer.

What is PAWN?
Pawn is a programming language that is embedded into other programs, in our case, SA-MP.

Recommendation.
To all beginners I would recommend completely reading SA-MP Wiki - Scripting basics. When scripting always have these pages opened on your internet browser. Click here.


Getting Started.

Setting up your server - Go to sa-mp.com, go into downloads and click on SA-MP 0.3d R2 Windows Server. After your download is complete, save the file to your computer. In this file you would find, filterscripts, gamemodes, include, npcmodes, pawno, plugins, scriptfiles, annouce, samp-license, samp-npc, samp-server, server and server-readme, files.

We'll start by setting up the server configs. We are going to open 'server' file.

You will see this:


Quote:

echo Executing Server Config...
lanmode 0
rcon_password changeme
maxplayers 32
port 7777
hostname SA-MP 0.3 Server
gamemode0 grandlarc 1
filterscripts baseaf gl_actions gl_property gl_realtime gl_mapicon ls_elevator
announce 0
query 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]

Now, We're going to change these default settings to your likings.

Hostname - This is what your server name will be when hosted on SA:MP client.
Rcon_password - This is the password to access your server.
Maxplayers - This is to change the amount of players to allow on the server.
gamemode - This is the server's running script.

So let's change the settings to our likings.


Quote:

echo Executing Server Config...
lanmode 0
rcon_password Server
maxplayers 50
port 7777
hostname SA-MP 0.3 server
gamemode0 Gamemode
filterscripts
announce 0
query 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]

After these are changed save the file.

Step 1 - Scripting.
Now, We're going to start by going into > pawno > pawno.exe.
Open the file, It will be blank. Create a new file by going into > File > New, in the top right-hand corner.

This will appear:


pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

This is a blank script. Now click F5 to compile, this will notify you if there's any errors.
If you're compiling your script for the first time you will have to save it also. Save it as the name you have for your gamemode0 settings in the server configs file so the server could run the script. For me I have 'Gamemode' so I'll save it as 'Gamemode'.


Now click samp-server to start the server. Add :7777 to your favorite list on your SA:MP client and your server will appear.


Step 2 - Scripting

So, let's begin by removing the first 3 lines.
Now what we're going to write some comments. Example, credits, version, developer etc.

So let's do this:


pawn Код:
/*******************************************************************************
*                SERVER NAME: Gamemode
*                SERVER VERSION: Mode v1.0
*                SERVER DEVELOPER: Nicholas
*
*   INFORMATION:
*
*******************************************************************************/
I would recommend compiling before continuing further with your scripting.

Now let's work on our function "main()"

So you'll have this:

pawn Код:
main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}
What is this? This is what is printed into your console (samp-server)
So this will basically display what script the server is running.

So let's do this:


pawn Код:
main()
{
    print("SERVER: Gamemoder");
    print("VERSION: Mode v1.0");
    print("DEVELOPER: Nicholas");
}
So let's now work on OnGameModeInit() function.

We have this:


pawn Код:
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}
Now, We're gong to set the 'SetGameModeText'. This will show the server's mode, example version.

So let's do this:


pawn Код:
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Party v2.0.0");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}
Now, We're going to work on our class selection, AddPlayerClass. Read more.
By default the coordinates are set for the High Roller casino in Las Venturas.

Now we're going to remove the default coordinates and add our own coordinates. To get coordinates you have to use this command on the server, /save, this command saves your OnFoot Position. Now the coordinates are save in your GTA San Andreas User file > SAMP > Savepositions.


These are the coordinates I have collected.

pawn Код:
AddPlayerClass(23,2038.5416,1342.3601,10.6719,270.0824,0,0,0,0,0,0);
AddPlayerClass(46,1831.0970,-1682.6102,13.5469,88.3051,0,0,0,0,0,0);
AddPlayerClass(45,1481.3297,-1748.6530,15.4453,359.7071,0,0,0,0,0,0);
AddPlayerClass(83,723.3815,-1494.9203,1.9343,359.2792,0,0,0,0,0,0);
AddPlayerClass(92,1126.6831,-1425.8101,15.7969,357.7497,0,0,0,0,0,0);
Now add your coordinates to your script.

Now, we have this:

pawn Код:
public OnGameModeInit()
{
    SetGameModeText("Party v2.0.0");
    //------------------------[PLAYER CLASS SELECTION]--------------------------
    AddPlayerClass(23,2038.5416,1342.3601,10.6719,270.0824,0,0,0,0,0,0);
    AddPlayerClass(46,1831.0970,-1682.6102,13.5469,88.3051,0,0,0,0,0,0);
    AddPlayerClass(45,1481.3297,-1748.6530,15.4453,359.7071,0,0,0,0,0,0);
    AddPlayerClass(83,723.3815,-1494.9203,1.9343,359.2792,0,0,0,0,0,0);
    AddPlayerClass(92,1126.6831,-1425.8101,15.7969,357.7497,0,0,0,0,0,0);
    return 1;
}

Let's add a vehicle to the script/server.
Read more.
We're going to use AddStaticVehicle. We're going to add this under the OnGameModeInit.
We're going to use the /save command to get our coordinates so the vehicle will spawn.


Here are my coordinates
pawn Код:
(0,1478.9257,-1737.8595,13.2929,270.0982,0,0);
The first 0 in the coordinate is the vehicle ID so let's change this to 402.

So we have this:

pawn Код:
public OnGameModeInit()
{
    SetGameModeText("Party v2.0.0");
    //------------------------[PLAYER CLASS SELECTION]--------------------------
    AddPlayerClass(23,2038.5416,1342.3601,10.6719,270.0824,0,0,0,0,0,0);
    AddPlayerClass(46,1831.0970,-1682.6102,13.5469,88.3051,0,0,0,0,0,0);
    AddPlayerClass(45,1481.3297,-1748.6530,15.4453,359.7071,0,0,0,0,0,0);
    AddPlayerClass(83,723.3815,-1494.9203,1.9343,359.2792,0,0,0,0,0,0);
    AddPlayerClass(92,1126.6831,-1425.8101,15.7969,357.7497,0,0,0,0,0,0);
    //---------------------------[SERVER VEHICLES]------------------------------
    AddStaticVehicle(402,1478.9257,-1737.8595,13.2929,270.0982,0,0);
    return 1;
}
So yeah, As I said this is basic tutorial. There are more advance tutorials on SA:MP forums. So I will end my tutorial by making a simple /help command.

This is what we have:


pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}
So let's work on this....
Let's do this:


pawn Код:
{
    if (strcmp("/help", cmdtext, true, 4) == 0)
Now let's add our SendClientMessage.
Let's do this:


pawn Код:
SendClientMessage(playerid,0xFFFFFF,"This is a Deathmatch Script.");
So we have this:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/help", cmdtext, true, 5) == 0)
    {
SendClientMessage(playerid,0xFFFFFF,"This is a Deathmatch Script.");
        }
    return 0;
}

End of Tutorial. This was a basic tutorial to get beginners started. Keep reading SA:MP Wiki about scripting.
Reply


Messages In This Thread
Scripting [BEGINNER] - by Nicholas. - 11.02.2012, 01:17
Re: Scripting [BEGINNER] - by 2KY - 11.02.2012, 01:32
Re: Scripting [BEGINNER] - by Nicholas. - 11.02.2012, 01:51
Re: Scripting [BEGINNER] - by 2KY - 11.02.2012, 02:07
Re: Scripting [BEGINNER] - by Nicholas. - 11.02.2012, 02:10
Re: Scripting [BEGINNER] - by Nicholas. - 11.02.2012, 17:42
Re: Scripting [BEGINNER] - by Mr.Fames - 15.02.2012, 15:59
Re: Scripting [BEGINNER] - by Nicholas. - 16.02.2012, 14:26
Re: Scripting [BEGINNER] - by Dripac - 01.03.2012, 11:47
Re: Scripting [BEGINNER] - by TheDominator - 14.03.2012, 21:31
Re: Scripting [BEGINNER] - by Goru - 10.07.2012, 14:33
Re: Scripting [BEGINNER] - by Nicholas. - 10.07.2012, 20:19
Re: Scripting [BEGINNER] - by Disturn - 11.07.2012, 01:52
Re: Scripting [BEGINNER] - by Goru - 11.07.2012, 03:11
Re: Scripting [BEGINNER] - by Nicholas. - 11.07.2012, 03:29
Re: Scripting [BEGINNER] - by Goru - 11.07.2012, 05:02
Re: Scripting [BEGINNER] - by M3mPHi$_S3 - 11.07.2012, 05:25
Re: Scripting [BEGINNER] - by Nicholas. - 11.07.2012, 05:30
Re: Scripting [BEGINNER] - by Rudy_ - 11.07.2012, 05:35
Re: Scripting [BEGINNER] - by Robert West - 11.07.2012, 05:43
Re: Scripting [BEGINNER] - by Goru - 11.07.2012, 05:44
Re: Scripting [BEGINNER] - by мυ∂υℓ_вacнα - 11.07.2012, 06:16
Re: Scripting [BEGINNER] - by Nicholas. - 11.07.2012, 06:25
Re: Scripting [BEGINNER] - by Max_Coldheart - 11.07.2012, 06:27
Re: Scripting [BEGINNER] - by Nicholas. - 11.07.2012, 06:39
Re: Scripting [BEGINNER] - by Goru - 12.07.2012, 13:15
Re: Scripting [BEGINNER] - by SEnergy - 27.07.2012, 07:04
Re: Scripting [BEGINNER] - by TheBestInTheWorld028 - 28.07.2012, 02:41
Re: Scripting [BEGINNER] - by SuNL1GhT - 28.07.2012, 06:21
Re: Scripting [BEGINNER] - by bathushan - 28.07.2012, 08:08
Re: Scripting [BEGINNER] - by Raiden Dragneel - 02.08.2012, 22:10
Re: Scripting [BEGINNER] - by Kwarde - 05.08.2012, 10:52
Re: Scripting [BEGINNER] - by Augis123 - 06.08.2012, 21:39
Re: Scripting [BEGINNER] - by LeMoi - 08.08.2012, 10:58
Re: Scripting [BEGINNER] - by MNA26 - 24.12.2012, 05:06
Re: Scripting [BEGINNER] - by Nicholas. - 24.12.2012, 14:19
Re: Scripting [BEGINNER] - by Zempist - 28.02.2013, 02:30
Re: Scripting [BEGINNER] - by Grooty - 18.06.2013, 02:26
Re: Scripting [BEGINNER] - by Raaf - 02.07.2013, 13:27
Re: Scripting [BEGINNER] - by SadGasm - 24.07.2013, 12:56
Re: Scripting [BEGINNER] - by SadGasm - 24.07.2013, 12:59
Re: Scripting [BEGINNER] - by Eugine - 16.01.2014, 19:40
Re: Scripting [BEGINNER] - by Ramzi10 - 25.01.2014, 07:48
Re: Scripting [BEGINNER] - by Stev - 08.02.2014, 17:46
Re: Scripting [BEGINNER] - by Unfriendly - 09.02.2014, 15:27
Re: Scripting [BEGINNER] - by AgusZ - 08.01.2015, 14:04
Re: Scripting [BEGINNER] - by Mido10 - 08.05.2015, 22:23
Re: Scripting [BEGINNER] - by JaydenJason - 08.05.2015, 22:28
Re: Scripting [BEGINNER] - by Mido10 - 08.05.2015, 23:08
Re: Scripting [BEGINNER] - by Konverse - 08.05.2015, 23:20
Re: Scripting [BEGINNER] - by Spypros - 12.08.2015, 19:24
Re: Scripting [BEGINNER] - by PrivateUserName - 03.01.2016, 12:44

Forum Jump:


Users browsing this thread: 1 Guest(s)