PDA

View Full Version : [Guide] Scripting for beginners (Part 1)



Alan Brookside
16th February 2016, 02:49 PM
http://i.imgur.com/Tdu9L41.png

Tutorial Part 1




Hello guys. I've decided to make this tutorial since I see that some of you would like to script. I have done it from own experiences but some of the definitions were also adjusted and taken from the internet since I'm not good at explaining things. I'd like to see some more new players interested in scripting and helping the server which is also one of the ways to get the server up and to get it better, with a better playerbase and many new updates, more actively. I hope you guys like it, thanks.



So basically, SA:MP uses PAWN programming language which is also very similar to the "C" programming language. If you want to start scripting, you have to have the program and to have the basic knowledge. Just to say, becoming a good scripter doesn't take a week, even if you're a superman. It takes a lot of time and SARP's developers have more than 1 year of practicing, even more. I'll go through the steps for the beginners, remember, you can't just build a gamemode from scratch with this tutorial. I'm maybe going to post more if I see some interest here. Basically, I'm going to post easy steps which will help you guys to learn the programming language which is the first step of becoming a good scripter. If you know the ways of PAWN, it's very easy. You know, time matters here.



What is PAWN? What is PAWNO?

PAWN is a programming language similar to C language. PAWN isn't used only for SAMP, but also for other programs. It uses CompuPhase Small, which is simple. It's 32 bit extension language. When we know what PAWN is, we came to a question. What is PAWNO? PAWNO is a program (.exe) which was created in order for programming/scripting PAWN. Shortly, PAWN is a programming language, PAWNO is a program on which you can create scripts/filterscripts in PAWN language.



Step 1 - Downloading needed/recommend files.

Alright so, I'd recommend you to download a whole server package to make it easier so you can test what you've done yet. You can download Windows server package here (http://files.sa-mp.com/samp037_svr_R2-1-1_win32.zip) and Linux server package here (http://files.sa-mp.com/samp037svr_R2-1.tar.gz).
Wait for it to download. After it downloads (which shouldn't take long since it's only 2MB) you need to extract the files somewhere (I'd recommend to desktop). After it's extracted, open the folder and there would be a folder called "pawno". Go into it and there you should see a program called "pawno" as well. Double-click on it and there you go, it's opened.




Step 2 - Basic knowledge

Alright so if you want to script yourself and you want to make a gamemode/filterscript, you have to have the basic PAWN programming language knowledge. Alright so, follow my steps and read it carefully from now on. First, when you open "pawno.exe" program, go to the left up corner and browse for a "new file" (blank white paper icon). button. A code of about 100 lines long will pop-up. We will be making a gamemode, not a filterscript. So delete this from the script;
#if defined FILTERSCRIPT

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

public OnFilterScriptExit()
{
return 1;
}

#else


It's not needed to remove, but it gives you a better look-up. You're more lookable over the code. Alright so first we will work on this;
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;
}


Alright so this;
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}will actually "print" what you'll write to the console when you'll open the "server.exe". You can name it however you want. I've done it like this (example);
{
print("\n----------------------------------");
print(" Tutorial Gamemode for Beginners");
print("----------------------------------\n");
}

Alright. When you've adjusted the SetGameModeText, you can make progress and you can go to the player classes now. Player classes (shortly) are ped moves;
public OnGameModeInit()
{

SetGameModeText("T:GM v1.0");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}

You can set the gamemode text to whatever you want. Gamemode text will apear in the SA:MP client such as SARP's (SARP v3.2c - current one). AddPlayerClass is a OnGameModeInit callback, we'll talk about callbacks later. Let's continue with the basic stuff.




Step 3 - Functions & Callbacks

Alright as we start, I'll put an example of a basic script which I think everyone will understand;
#include <a_samp>

main()
{
print("RIP SA:RP 2007-2016");
return 1;
}

That #include <a_samp> basically loads an .inc file from samp server package folder/pawno/includes/a_samp.inc to the script so you can use it in your script. It's simple. There are many other include files. Many people create their own includes as well so it's easier for them. Alright, so, a function is a chunk of a code which can do something and it can be managed/written to do this thing from somewhere else. So calling;
print("RIP SA:RP 2007-2016"); calls the function "print" from a_samp.inc. (which is also defined/I will say explained in the programming language) in the a_samp.inc files in your pawno/includes. That's why you also have to #include it. If you wouldn't have, it wouldn't be working, simple. It's a complete logic system. Alright so now you may understand, "print" is a callback defined in a_samp.inc. I won't be that complicated because I guess some of you don't even understand what I've done till now, so I'll go ahead with the basic stuff.



Step 4 - Classes & Spawnpoints

Alright, classes. Some of the gamemodes don't have CJ ped move or a custom running style pedmove, they have the normal classes pedmoves, which don't have to be scripted manually. CJ is class 0, for example (it's also skin id 0). Classes can be found in the peds.ide file but you can also use SA:MP debug script to find them easily. You can start debug by going to "C:\Program Files\Rockstar Games\GTA San Andreas\samp_debug.exe". That's the basic root folder of GTA SA installation, by the way. Once you're in samp_debug.exe, you can change classes by using F11 and F12 button on your keyboard. As I've mentioned above;
AddPlayerClass is a OnGameModeInit callback, we'll talk about callbacks later. Let's continue with the basic stuff., it's also a callback. You can use;
public OnGameModeInit()
{

SetGameModeText("T:GM v1.0");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}and players will have CJ's class by playing in the gamemode. You can adjust the classes by looking for them in peds.ide or simply googling them. Let's talk about spawnpoints now. Spawnpoint is a point where player spawns when he/she joins the server (enters the gamemode). You can manage spawnpoints like this (examples);
public OnPlayerRequestClass(playerid, classid // you have to put the class which you've put above in the AddPlayerClass, so when player joins he requests the class automatically and he automatically gets the PlayerClass 0 - if you've set the class 0)
{
SetPlayerPos(playerid, you have to put coordinates of the player's spawn position (ex. sarp has the coords near the skate park));
SetPlayerCameraPos(playerid, you have to put the coordinates of the player's camera position here (ex. on sarp your camera is set to be above the skatepark);
SetPlayerCameraLookAt(playerid, you have to put coordinates of the player's camera position here - it actually turns the player's screen/look to the coords which you've put there (ex. on sarp you're turned to the newbie spawn building);
return 1;
}

You can get the coordinates mentioned above by going into debug and typing /save at the position you want to get them. When you type /save, you can go to GTA SA User Files in your Documents folder. Here's an image of how it should look;http://i.imgur.com/tPyFL70.jpg
When you'll open the savedpositions.txt there should pop-up something like this;http://i.imgur.com/MyEAYAu.jpg
If it doesn't, it means you haven't typed /save or there's maybe any other issue (if you have it, PM/VM me or google it).



Step 5 - Running the Gamemode

Alright so after you've done that, you should click F5 while being in your pawno.exe. PAWN Compiler will create an .amx file which is used to run the server. Servers can't be ran with .pwn file, because .pwn is used to create a script which you compile to an .amx. Compiler will also give you errors if they are some, but there shouldn't be any. Here's a tutorial how to do this and how to turn the server on;
1. After you click on the compile button, it will ask you where you want to save the file (.amx)
2. After it's saved, move it to the gamemodes folder in the SAMP server package.
3. Open server.cfg and rename the rcon password to whatever you want, gamemode0 to the name of the .amx file you've put in the gamemodes folder and you can adjust the hostname etc.
4. Open server.exe after you save all those files, it should ask you for the firewall permission unless you have it adjusted already, just click all the boxes and go on.
5. Go to samp.exe (the samp client) and add 127.0.0.1****** to the favorites list (make sure server.exe is on)
6. Try to connect to the server, it will print the words you've posted above in this
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}to the server.exe and to server_log.txt in your server package folder.
7. When you'd join there should be the class and the camera position that you've set before here
public OnPlayerRequestClass(playerid, classid // you have to put the class which you've put above in the AddPlayerClass, so when player joins he requests the class automatically and he automatically gets the PlayerClass 0 - if you've set the class 0)
{
SetPlayerPos(playerid, you have to put coordinates of the player's spawn position (ex. sarp has the coords near the skate park));
SetPlayerCameraPos(playerid, you have to put the coordinates of the player's camera position here (ex. on sarp your camera is set to be above the skatepark);
SetPlayerCameraLookAt(playerid, you have to put coordinates of the player's camera position here - it actually turns the player's screen/look to the coords which you've put there (ex. on sarp you're turned to the newbie spawn building);
return 1;
}
8. I hope it works and you enjoy it. I'll come with a new tutorial soon.


Step 6 - The End

Alright guys, I hope you've enjoyed my tutorial and you like it. I'd be posting part 2 soon if I manage to get good opinons and some likes, and if I see that you liked it. I'll be also posting a mapping tutorial soon, when I'll feel to. Alright, so that's the end of my tutorial, again, I hope you've liked it. Thanks for your opinions which you'll be posting (hopefully you will). I hope I've helped some of you guys and you have learned the basics. I'm not going to rush everything in one tutorial. I know it's not the best one, but I've put 2 hours effort into this guys. I'm still not the best in the PAWN, but I can do a lot of things.



Credits;
Alan Brookside (original creator)
SAMP Wiki (examples of some codes)

Rellex
16th February 2016, 03:08 PM
- nvm -

Alan Brookside
16th February 2016, 03:14 PM
- nvm -

What do you mean pal? Is it a good one?

Jizzy Black
16th February 2016, 03:24 PM
tbh, you just defined how to start off by PAWN, a small similar language to C/C++.

If you want to be making a good BEGINNER tutorial, start off by the parameters, functions, variables, arithmetic and all of that. You should also make a list of requirements as well. You can also start by saying what is PAWN, what is it made off and how it was developed, just an introduction.

I wouldn't call myself a beginner, nor a professional but I did see many tutorials and I can say that this one isn't bad. You directly started with giving examples for the functions and not mentioning the use of the function, the use of the #include, how was it made and all that.

To make a tutorial, you should be a professional or probably more to answer any questions that you may be asked.

Alan Brookside
16th February 2016, 03:29 PM
tbh, you just defined how to start off by PAWN, a small similar language to C/C++.

If you want to be making a good BEGINNER tutorial, start off by the parameters, functions, variables, arithmetic and all of that. You should also make a list of requirements as well. You can also start by saying what is PAWN, what is it made off and how it was developed, just an introduction.

I wouldn't call myself a beginner, nor a professional but I did see many tutorials and I can say that this one isn't bad. You directly started with giving examples for the functions and not mentioning the use of the function, the use of the #include, how was it made and all that.

To make a tutorial, you should be a professional or probably more to answer any questions that you may be asked.

Thanks for your response pal, I appreciate it. I will take those into the Part 2 tutorial, and I will hopefully make it better. This is my first tutorial I've ever made tbh, thanks for being honest pal. Just tryna help out ya know :-)

Or I'll just edit the main post in few hours, tired af.

Michael
16th February 2016, 03:32 PM
http://forum.sa-mp.com/showthread.php?t=317336

Rellex
16th February 2016, 03:34 PM
Unless you plan on teaching absolutely everything, I highly doubt this will be useful.

Alan Brookside
16th February 2016, 03:34 PM
http://forum.sa-mp.com/showthread.php?t=317336

I've already mentioned that I've typed it myself but I've also took some examples from other sites. I'm going to list credits if you want, lol.


Unless you plan on teaching absolutely everything, I highly doubt this will be useful.

I will, but not in one tutorial. Probably in like 10 tutorial parts. I'm not that good as you are I guess, and I'll still be learning and posting here. Thanks for all the suggestions and I'll be editing this one very soon.

Michael
16th February 2016, 03:51 PM
I've already mentioned that I've typed it myself but I've also took some examples from other sites. I'm going to list credits if you want, lol.

You should always list credits.

Alan Brookside
16th February 2016, 03:52 PM
You should always list credits.

Alright, thanks for the reminder mate.

DwayneD
16th February 2016, 04:17 PM
I have to agree with Jizzy in the fact that you just fly by the essentials and aren't even considering this to be "beginner-friendly". You don't explain what the thing's actually doing(example; AddPlayerClass), just how to add it. Not really a method someone new to the language should be introduced to(in my honest opinion it seems like you are just giving code throughout much of the tutorial). Another example in AddPlayerClass are the x, y, z coordinates. Someone new to this type of system(especially PAWN/C languages as well) may not know how to use those(or how to get them from the game). All in all, this isn't a very good tutorial for a person who has never seen C nor PAWN, try to do some further editing to improve it's friendliness to beginners.

Alan Brookside
16th February 2016, 04:18 PM
I have to agrre with Jizzy in the fact that you just fly by the essentials and aren't even considering this to be "beginner-friendly". You don't explain what the thing's actually doing(example; AddPlayerClass), just how to add it.
(You don't even explain what the coordinates are, how would a beginner be expected to know this?)

All in all, this isn't a very good tutorial for a person who has never seen C nor PAWN.

I agree with it too. Please excuse me, it's my first tutorial. I'll be improving it mate. Thanks for your honest reply.

Rellex
16th February 2016, 06:14 PM
I will, but not in one tutorial. Probably in like 10 tutorial parts. I'm not that good as you are I guess, and I'll still be learning and posting here. Thanks for all the suggestions and I'll be editing this one very soon.

You should get lead dev if you can do a whole language in 10 tutorials

Tommy Corleone
16th February 2016, 06:16 PM
I tried but all I managed to do is spawn with a dildo make it more detailed

Alan Brookside
16th February 2016, 06:23 PM
I tried but all I managed to do is spawn with a dildo make it more detailed

I've also posted that I'm going to, thanks for your reply.

troll


You should get lead dev if you can do a whole language in 10 tutorials

I didn't mean exactly 10, I just said I'll do at least 10 tuts or even more.

Kiyomi
16th February 2016, 06:33 PM
Your saying that this is tutorial for beginners yet you haven't explained anything properly at all, You're using words like
Alright so this;
Alright, we will go on;

and when you do all you doing is skipping the scripting part and showing a sample of what you did but never explained why and never told your audience on what does every number represent, what the function does, how you could improve the function and etc.

explain in details between every step, let your audience/student know what you're talking about otherwise, no offense but this is just crap and a copy & paste from my Point of View.(yeh, quit the "I've typed it myself but I've also took some examples from other sites." bullshit, we all know that story by now.)

Alan Brookside
16th February 2016, 06:36 PM
Your saying that this is tutorial for beginners yet you haven't explained anything properly at all, You're using words like
Alright so this;
Alright, we will go on;

and when you do all you doing is skipping the scripting part and showing a sample of what you did but never explained why and never told your audience on what does every number represent, what the function does, how you could improve the function and etc.

explain in details between every step, let your audience/student know what you're talking about otherwise, no offense but this is just crap and a copy & paste from my Point of View.(yeh, quit the "I've typed it myself but I've also took some examples from other sites." bullshit, we all know that story by now.)

Alright, 7th time, I'm editing it right now. Thanks!

EDIT: Updated it a bit, please tell me if you see any other issues I should update.