[Tutorial] How to make an Include file for Sa-Mp.
#1

Introduction




This is my first tutorial, and this tutorial will help you in making your own include files.Making .inc is very simple.But creating functions are not that easy.




Q."What is an Include ?"

A. According to me an include file is nothing but a file which contains functions,parameters,arguments created by you, which makes coding game modes/filterscripts easier. Sorry, if I am wrong.






Syntax




pawn Code:
#include <filename> //An include should always have a .inc format


Coding





Q."Where do we have to code an Include file for our server ?"

A. Pawno/Pawn

Q."How ?"

A. Step 1: Just open pawn and press ctrl+n, then remove all the syntax/callbacks and everything.



Step 2: Now start creating your own functions.For Example
pawn Code:
//audiostreamforall
stock PlayAudioStreamForAll(url[])
{
   foreach (new i : Player)
     {
        PlayAudioStreamForPlayer(i,url);
     }
return url;
}
//stopaudiostreamforall
stock StopAudioStreamForAll()
{
new i;
    foreach (i : Player)
     {
        StopAudioStreamForPlayer(i);
     }
return 1;
}
Now do not compile it just save it.Then go to the folder where you have saved it as .pwn file, Now rename that .pwn file to .inc




Step 3: Now move that .inc file to pawno\include.




Step 4: Include it to your game mode and you're done.



Thank You
Reply
#2

Where is the part about hooking callbacks/functions?

Why aren't you using foreach?

Code:
if(IsPlayerConnected(i)==1)
can be
Code:
if(IsPlayerConnected(i))
Horrible indentation, edit these 3 points and it'll be alot better.
Reply
#3

No, it's a basic tutorial for beginners .
Reply
#4

Still, you gotta show them how you do it correctly else they won't learn!
Reply
#5

Not using foreach makes my code wrong ?
Reply
#6

Quote:
Originally Posted by Rittik
View Post
Not using foreach makes my code wrong ?
It's not wrong, but foreach is better! If you teach newbies to use it, we all have profit!
Reply
#7

Is it his fault now that he didn't use foreach in his script? Do we have to call the police now and let them arrest him for making this tutorial before he learned foreach? NO. He tried to make a tutorial in hope that someone can learn. It is his first tutorial, as he said. If he messed up doesn't mean we have to do a -rep rampage. The worst thing happening here is that you are doing too much critics on a first tutorial. That is the actual thing wrong here. His indentation in his scripts might be crappy, but your indentation to a first tutorial is just too messy
Reply
#8

Well, to you, critics are negative ?

jihadmeneer just tell him how to make better tutorials next time, what's bad ?
Reply
#9

I am just telling them how to improve his tutorial.
Reply
#10

Foreach added
Reply
#11

foreach wasnt necessary but the way code is presented is messy.
No proper syntax highlighting i.e: use of [Pawn] tags should be made.
Secondly code should be indented properly thats the basic habit one should adopt.

Well Includes is like a part of modular programming or just maintaing user defined functions in a library. It can also have further meaning too
Reply
#12

Updated with [pawn] tags and no more messiness in the code.
Reply
#13

Some tips by me:

- It's not necessary to an include have the .inc extension. and not Necessary to place it in pawno/include. but importing way is different.

In my case i have an .pwn file contain some definitions.

pawn Code:
#include "../gamemodes/definitions.pwn"
#include "../include/colors.inc"
#include "../../ifarbod.txt"
- Making functions in not too hard!
- Those are functions, not callbacks!
- You must replace :
pawn Code:
stock StopAudioStreamForAll(url[])
to
pawn Code:
stock StopAudioStreamForAll()
For Stop the stream you no need the url[] parameter.
Reply
#14

Quote:
Originally Posted by Rittik
View Post
Q."What is an Include ?"
A. According to me ... Sorry, if I am wrong.
Research first, before making a tutorial. I recommend reading pawn-lang.pdf. That goes for everyone, by the way. Also please note the difference between Pawn and Pawno. They're not the same thing.
Reply
#15

- PAWN Is an open-source, embedded language made by ITB CompuPhase!
- Pawno is an PAWN IDE For SA-MP. I Think it's made by spookie and the SA:MP Team!

IDE = Integrated Development Environment

Some people think they are Pawno Scripter!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)