Register

If you already have an account with us, please use the login panel below to access your account.

Results 1 to 17 of 17

Threaded View

  1. #1
    O.G. Hobo
    #BROOKSIDE NIGGAS

    Taxi Driver
    Alan Brookside's Avatar
    Join Date
    Feb 2016
    Location
    ♡ Australia ♡
    Age
    31
    Posts
    277
    In-Game Name(s)
    .
    Post Thanks / Like

    [Guide] Scripting for beginners (Part 1)



    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 and Linux server package here.
    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;
    Code:
    #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;
    Code:
    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;
    Code:
    {
    	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);
    Code:
    {
    	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;
    Code:
    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;
    Code:
    #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;
    Code:
    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;
    Quote Originally Posted by AlanB
    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;
    Code:
    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);
    Code:
    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;
    When you'll open the savedpositions.txt there should pop-up something like this;
    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
    Spoiler!
    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
    Spoiler!

    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)




    Last edited by Alan Brookside; 16th February 2016 at 07:43 PM. Reason: Updated!

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Click to connect to Discord (San Andreas Roleplay)Click to go to the official San Andreas Multiplayer websiteDownload Teamspeak