11.02.2012, 01:17
(
Последний раз редактировалось Nicholas.; 11.07.2012 в 05:42.
)
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:
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.
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:
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:
I would recommend compiling before continuing further with your scripting.
Now let's work on our function "main()"
So you'll have this:
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:
So let's now work on OnGameModeInit() function.
We have this:
Now, We're gong to set the 'SetGameModeText'. This will show the server's mode, example version.
So let's do this:
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.
Now add your coordinates to your script.
Now, we have this:
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
The first 0 in the coordinate is the vehicle ID so let's change this to 402.
So we have this:
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:
So let's work on this....
Let's do this:
Now let's add our SendClientMessage.
Let's do this:
So we have this:
End of Tutorial. This was a basic tutorial to get beginners started. Keep reading SA:MP Wiki about scripting.
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] |
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] |
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:
*
*******************************************************************************/
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");
}
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");
}
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;
}
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;
}
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, 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);
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;
}
This is what we have:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
Let's do this:
pawn Код:
{
if (strcmp("/help", cmdtext, true, 4) == 0)
Let's do this:
pawn Код:
SendClientMessage(playerid,0xFFFFFF,"This is a Deathmatch Script.");
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.