SA-MP Forums Archive
[Tutorial] How to make an Include file for Sa-Mp. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make an Include file for Sa-Mp. (/showthread.php?tid=515497)



How to make an Include file for Sa-Mp. - Rittik - 26.05.2014

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



Re: How to make an Include file for Sa-Mp. - jihadmeneer - 26.05.2014

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.


Re: How to make an Include file for Sa-Mp. - Rittik - 26.05.2014

No, it's a basic tutorial for beginners .


Re: How to make an Include file for Sa-Mp. - jihadmeneer - 26.05.2014

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


Re: How to make an Include file for Sa-Mp. - Rittik - 26.05.2014

Not using foreach makes my code wrong ?


Re: How to make an Include file for Sa-Mp. - jihadmeneer - 26.05.2014

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!


Re: How to make an Include file for Sa-Mp. - NaClchemistryK - 26.05.2014

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


Re : How to make an Include file for Sa-Mp. - S4t3K - 26.05.2014

Well, to you, critics are negative ?

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


Re: How to make an Include file for Sa-Mp. - jihadmeneer - 26.05.2014

I am just telling them how to improve his tutorial.


Re: How to make an Include file for Sa-Mp. - Rittik - 26.05.2014

Foreach added


Re: How to make an Include file for Sa-Mp. - Niko_boy - 26.05.2014

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


Re: How to make an Include file for Sa-Mp. - Rittik - 27.05.2014

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


Re: How to make an Include file for Sa-Mp. - iFarbod - 27.05.2014

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.


Re: How to make an Include file for Sa-Mp. - Vince - 27.05.2014

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.


Re: How to make an Include file for Sa-Mp. - iFarbod - 27.05.2014

- 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!