[Tutorial] How to make a very SIMPLE deathmatch server [PART 1]
#1

Hi @ll!

This is my very first tutorial! As you can read, it is for PAWN beginners, and explain them the Intro into scripting!
The example is: a SIMPLE deathmatch server! In the first part, the player will see his first scripted lines, get some knowledge about PAWN which is similar with C++ and can be proud of his very first script!^^

First of all, you should read the main things! Go to wiki.sa-mp.com and read "Introduction" until "Getting Started"!
Maybe it explains you something more! So, now we can start!

1.SA-MP
Download the SA-MP Client 0.3c and Server-Package for Windows OR Linux! Go to sa-mp.com, then you navigate to Downloads and voila, here you go! Put the Client into your GTA SA directory, the server package I would say, into a special folder (The special folder should be also into your SA-directory...)!

2. PAWN-EDITOR
In your server package, you should find a folder called pawno! Go into it and start the application pawno...
Note: NOT pawncc, okay?
Then, click on "new" (into pawno application), and here it is! Your VERY first script! Well, you can't even make your dog happy with this, so let's add some nice skins, okay? Your sheet should look now like this:

PHP код:
// 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(01958.37831343.157215.3746269.1425000000);
    return 
1;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerRequestClass(playeridclassid)
{
    
SetPlayerPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraLookAt(playerid1958.37831343.157215.3746);
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    return 
1;
}
public 
OnPlayerSpawn(playerid)
{
    return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    return 
1;
}
public 
OnVehicleSpawn(vehicleid)
{
    return 
1;
}
public 
OnVehicleDeath(vehicleidkillerid)
{
    return 
1;
}
public 
OnPlayerText(playeridtext[])
{
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/mycommand"cmdtexttrue10) == 0)
    {
        
// Do something here
        
return 1;
    }
    return 
0;
}
public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    return 
1;
}
public 
OnPlayerExitVehicle(playeridvehicleid)
{
    return 
1;
}
public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    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(playeridobjectid)
{
    return 
1;
}
public 
OnPlayerPickUpPickup(playeridpickupid)
{
    return 
1;
}
public 
OnVehicleMod(playeridvehicleidcomponentid)
{
    return 
1;
}
public 
OnVehiclePaintjob(playeridvehicleidpaintjobid)
{
    return 
1;
}
public 
OnVehicleRespray(playeridvehicleidcolor1color2)
{
    return 
1;
}
public 
OnPlayerSelectedMenuRow(playeridrow)
{
    return 
1;
}
public 
OnPlayerExitedMenu(playerid)
{
    return 
1;
}
public 
OnPlayerInteriorChange(playeridnewinterioridoldinteriorid)
{
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    return 
1;
}
public 
OnRconLoginAttempt(ip[], password[], success)
{
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    return 
1;
}
public 
OnPlayerStreamIn(playeridforplayerid)
{
    return 
1;
}
public 
OnPlayerStreamOut(playeridforplayerid)
{
    return 
1;
}
public 
OnVehicleStreamIn(vehicleidforplayerid)
{
    return 
1;
}
public 
OnVehicleStreamOut(vehicleidforplayerid)
{
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    return 
1;
}
public 
OnPlayerClickPlayer(playeridclickedplayeridsource)
{
    return 
1;

There you go!

3. Scripting with PAWNO
You still here? Good! Then let's go! Navigate into your script to "OnGameModeInit"!

This is your currently callback:

PHP код:
public OnGameModeInit()
{
    
// Don't use these lines if it's a filterscript
    
SetGameModeText("Blank Script");
    
AddPlayerClass(01958.37831343.157215.3746269.1425000000);
    return 
1;

AddPlayerClass adds a skin! "Samtey, there are soooo much numbers, I never was good in Maths at school!"
Doesn't matter, I come and explain it you!

AddPlayerClass(SKIN, X-POSITION,Y-POSITION,Z-POSITION, WEAPON,AMMO, WEAPON,AMMO, WEAPON,AMMO)

That was it! Each word = each number, so I think you know what I'm talking about, right?

The skin ID is currently 0, which stands for CJ! Get your favourite skin ID's here and replace them with 0 for example....:
https://sampwiki.blast.hk/wiki/Skins:All

Now the positions:
This is where you need to work with SA-MP DEBUG! It should be in your San Andreas directory! Go and launch it! Launched? Launched!! Okay, now press T (to get into the chat in SA-MP) and write: /v 425
This performs that you get a helicopter! Fly with it to your favourite position!
(More to vehicle commands later...)
Arrived....: Now at your favourite position, type T. Then type /save Give_it_a_name!
Replace that with your name, example: SpawnPoint 1!
Finish! Now, exit the debugger (I hope you took the co-ordinates at foot, not in the helicopter...)
!

Then, you need to find the file "savedpositions.txt"! It is in GTA San Andreas User Files ->SAMP
or it is into your San Andreas directory! Open it! There you got your co-ordinates!
Short explaining: If you got for example this co-ordinates:
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
1958.3783 = X-Pos
1343.1572 = Y-Pos
15.3746 = Z-Pos
269.1425 = Facing Angle

Now, add this under your OnGameModeInit:
AddPlayerClass(YOUR SKIN ID HERE, YOUR CO-ORDINATES HERE, 0, 0, 0, 0, 0, 0);
Ok, now we need the weapons! This is as easy as clapping with your hands:
Here are the weapon ID's!
https://sampwiki.blast.hk/wiki/Weapons_DE
So your PlayerClass should or can look now like this:
AddPlayerClass(YOUR SKIN ID HERE, YOUR CO-ORDINATES HERE ,WEAPON1, AMMO1, WEAPON2, AMMO2, WEAPON3, AMMO3);
So far so good!
But of course you want, when you join the game, SEE the skin you are choosing! Really easy! Go to the Debug, then navigate to the place where your Skin should spawn! Then, simply place CJ where you want to see him while choosing! Type /save NAME After this, go 3 steps backwards, so your front of CJ can see the old position! Then type again /save NAME2!
If you don't understand too well, then I try to attach a video!
Now, when you look in your "savedpositions.txt" you should have 3 times AddPlayerClasses:
The first one
The two from now

They should look similar like this:
AddPlayerClass(YOUR SKIN ID HERE, X,Y,Z,FACING ANGLE, 0, 0, 0, 0, 0, 0);
and
AddPlayerClass(YOUR SKIN ID HERE, X,Y,Z,FACNG ANGLE, 0, 0, 0, 0, 0, 0);
Now, in your script navigate to:
OnPlayerRequestClass
You will see:
PHP код:
    SetPlayerPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraLookAt(playerid1958.37831343.157215.3746); 
That's NOT what we want! Replace the content of the functions:
PHP код:
SetPlayerTeamFromClass(playeridclassid);
SetPlayerPos(playerid,X,Y,Z-POSITIONS HERE FROM THE FIRST ONE YOU TOOKNOT THE 4th POSITION);
SetPlayerFacingAngle(playerid4TH POSITION OF 1st CO-ORDINATETHAT MEANS THE FACING ANGLE);
SetPlayerCameraPos(playeridTHE X Y Z Co-ordinates of the SECOND ONE YOU TOOK);
SetPlayerCameraLookAt(playeridTHE X-Y-Z CO-ORDINATES OF THE FIRST ONE AGAIN!!!); 
Got it? The SetPlayerTeamFromClass we need now, because we want to know in the game, to which team each skin is!
Now, because we only got ONE AddPlayerClass, we need to say the function, that case0 is the start here! Your OnPlayerRequest must look like this now:

PHP код:
public OnPlayerRequestClass(playeridclassid) {
switch(
classid) {
case 
0: {
SetPlayerTeamFromClass(playeridclassid);
SetPlayerPos(playerid,X,Y,Z-POSITIONS HERE FROM THE FIRST ONE YOU TOOKNOT THE 4th POSITION);
SetPlayerFacingAngle(playerid4TH POSITION OF 1st CO-ORDINATETHAT MEANS THE FACING ANGLE);
SetPlayerCameraPos(playeridTHE X Y Z Co-ordinates of the SECOND ONE YOU TOOK);
SetPlayerCameraLookAt(playeridTHE X-Y-Z CO-ORDINATES OF THE FIRST ONE AGAIN!!!);
    }
      }
      
return1;    

Now, (we could do it earlier, but now it didn't get late ) we need to define the teams! I use TEAM1 here, name it WHATEVER you want!
At the top of your script:
PHP код:
#define GROVE 1 
The one is for this, that this is the FIRST team here!
under this, you type now:
PHP код:
#define TEAM_GROVE_COLOR 0x00FF00AA 
0x00FF00AA is a hexadecimal number for the color green! Get all the colors here:
https://sampforum.blast.hk/showthread.php?tid=157789
So far so good! Now, we only need the script to know, in which team each skin is!
First, under your defines, we need to define a new variable, an ARRAY! An array is like a big variable, which can include much of them!
PHP код:
new gTeam[MAX_PLAYERS]; 
Got it? "Sir, yes SIR!" Ok, then you need to write UNDER the callback OnGameModeInit(NOT IN IT!!!):
PHP код:
SetPlayerTeamFromClass(playeridclassid)
{
    switch(
classid)
    {
        case 
:
        {
            
gTeam[playerid] = GROVE//Now, here you have to put in the name of the team which you defined...
        
}
    }
}
SetPlayerToTeamColor(playerid)
{
    switch(
gTeam[playerid])
    {
        case 
GROVE:
        {
            
SetPlayerColor(playeridTEAM_GROVE_COLOR);
        }
    }

Remember: case 0 is only there, because an array starts from 0! You only got one Skin in there, so it is 0! If you got 3 skins in one team, you must replace it for example like this!
PHP код:
case .. 
Also, the same rule is into OnPlayerRequestClass... Simply, if you want more teams, make more defines with the team and the colors like explained! And under the two funtions, add them like this!
PHP код:
SetPlayerTeamFromClass(playeridclassid)
{
    switch(
classid)
    {
        case 
:
        {
            
gTeam[playerid] = GROVE//Now, here you have to put in the name of the team which you defined...
        
}
case 
HERE_THE_NUMBER_OF_THE_FIRST _SKIN_OF_THE_TEAM     HERE_THE_NUMBER_OF_THE_LAST_SKIN_OF_THE_TEAM:
{
    
gTeam[playerid]=SECOND_TEAM;
}
    }
}
SetPlayerToTeamColor(playerid)
{
    switch(
gTeam[playerid])
    {
        case 
GROVE:
        {
            
SetPlayerColor(playeridTEAM_GROVE_COLOR);
        }
case 
SECONDTEAM:
{
    
SetPlayerColor(playeridSECOND_TEAM_COLOR);
}
    }

If in your second team the 3th AddPlayerClasses is the first skin of the team for example, and the 5th is the last one, then in your case you start with 3 and stop with 5! Simple, not?
4. Running your server with your script
Now, first you need to save your script! Go in the upper right corner: File -> Save as
and save it in your SERVER-FOLDER under gamemodes! Give it a name like test!
Got it? Good! Now press F5 for compiling! It shouldn't give you an error! If yes, post it here!
Then, go to your server folder and open a file called server.cfg! It should look like this:
Код:
echo Executing Server Config...
lanmode 0
rcon_password YOURPASSWORD HERE
maxplayers 32 (YOU CAN INCREASE THE MAX PLAYERS HERE)
port 7777
hostname TYPE YOUR HOSTNAME OF THE SERVER HERE
gamemode0 The name of your saved script here, okay?
filterscripts 
plugins 
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 gamemode0, be careful that you type CORRECTLY the name of your script!
Now, you can run the application samp-server.exe! It's in your server-folder!
Then, open up your SA-MP Client! It's in your San Andreas directory!
Arrived? Then klick on the check mark, which is in the upper left corner!
There you type "localhost"!
VOILA! You should see your server with it's name! Now, you can connect to it and test those things! Experiment with the script, add things, and make yourself ready for PART 2 COMING SOON!

Credits: everything by me, samtey

HOPE YOU LEARNED AND ENJOYED!

5.Adding vehicles
This is an EDIT:
Launch your SA-MP DEBUG! Type /v [ID]
Vehicle ID's can be found here:
https://sampwiki.blast.hk/wiki/Vehicles:All

Drive to the place you want the vehicle! Then, type /save NAME

Exit and open "savedpositions.txt" ! There you find something like this:

PHP код:
AddStaticVehicle(461,1997.9093,-1273.2574,23.3769,2.2858,149,149); // NAME 
Simple:
AddStaticVehicle(CAR-ID YOU HAD,X-Y-XPOSITION, FACING ANGLE,COLOR1,COLOR2); // NAME
Replace them with your Co-ordinates and add the two colors!

Color ID's for cars are all here + hidden colors:

https://sampwiki.blast.hk/wiki/Color_ID

Save + compile it and finish! Your server will need a restart after this!

Now, if you want that your vehicle respawns after a time, convert this
PHP код:
AddStaticVehicle(CAR-ID YOU HAD,X-Y-Z-POSITIONFACING ANGLE,COLOR1,COLOR2); // NAME 
to this

PHP код:
AddStaticVehicleEx(CAR-ID YOU HAD,X-Y-Z-POSITIONFACING ANGLE,COLOR1,COLOR260); // NAME 
60 is the time in seconds the vehicle will respawn after, you can change it by yourself...
Reply
#2

Looks nice.
Reply
#3

Fairly Explained.
Reply
#4

erhm Not very well explained but ye..
EDIT: Ok a bit, but some other parts could be a bit more explained.
Reply
#5

Nice, good job.
Reply
#6

@all

Thanks, I tried my best!

@THREAD

Added the vehicle-tutorial...
Reply
#7

Btw you wrote X-Y-X, it's X-Y-Z
Reply
#8

Good work.
Reply
#9

Nice tutorial dude, well done and keep up the good work
Reply
#10

Good work!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)