05.09.2011, 10:33
(
Последний раз редактировалось samtey; 05.09.2011 в 11:46.
)
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!
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:
There you go!
This is your currently callback:
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:
That's NOT what we want! Replace the content of the functions:
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:
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:
The one is for this, that this is the FIRST team here!
under this, you type now:
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!
Got it? "Sir, yes SIR!" Ok, then you need to write UNDER the callback OnGameModeInit(NOT IN IT!!!):
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!
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!
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?
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:
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!
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:
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
to this
60 is the time in seconds the vehicle will respawn after, you can change it by yourself...
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(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;
}
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(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
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(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
PHP код:
SetPlayerTeamFromClass(playerid, classid);
SetPlayerPos(playerid,X,Y,Z-POSITIONS HERE FROM THE FIRST ONE YOU TOOK, NOT THE 4th POSITION);
SetPlayerFacingAngle(playerid, 4TH POSITION OF 1st CO-ORDINATE, THAT MEANS THE FACING ANGLE);
SetPlayerCameraPos(playerid, THE X Y Z Co-ordinates of the SECOND ONE YOU TOOK);
SetPlayerCameraLookAt(playerid, THE X-Y-Z CO-ORDINATES OF THE FIRST ONE AGAIN!!!);
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(playerid, classid) {
switch(classid) {
case 0: {
SetPlayerTeamFromClass(playerid, classid);
SetPlayerPos(playerid,X,Y,Z-POSITIONS HERE FROM THE FIRST ONE YOU TOOK, NOT THE 4th POSITION);
SetPlayerFacingAngle(playerid, 4TH POSITION OF 1st CO-ORDINATE, THAT MEANS THE FACING ANGLE);
SetPlayerCameraPos(playerid, THE X Y Z Co-ordinates of the SECOND ONE YOU TOOK);
SetPlayerCameraLookAt(playerid, THE X-Y-Z CO-ORDINATES OF THE FIRST ONE AGAIN!!!);
}
}
return1;
}
At the top of your script:
PHP код:
#define GROVE 1
under this, you type now:
PHP код:
#define TEAM_GROVE_COLOR 0x00FF00AA
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];
PHP код:
SetPlayerTeamFromClass(playerid, classid)
{
switch(classid)
{
case 0 :
{
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(playerid, TEAM_GROVE_COLOR);
}
}
}
PHP код:
case 0 .. 2 {
PHP код:
SetPlayerTeamFromClass(playerid, classid)
{
switch(classid)
{
case 0 :
{
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(playerid, TEAM_GROVE_COLOR);
}
case SECONDTEAM:
{
SetPlayerColor(playerid, SECOND_TEAM_COLOR);
}
}
}
4. Running your server with your script
Now, first you need to save your script! Go in the upper right corner: File -> Save asand 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]
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
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-POSITION, FACING ANGLE,COLOR1,COLOR2); // NAME
PHP код:
AddStaticVehicleEx(CAR-ID YOU HAD,X-Y-Z-POSITION, FACING ANGLE,COLOR1,COLOR2, 60); // NAME