SA-MP Forums Archive
[Tutorial] Include Making - 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] Include Making (/showthread.php?tid=245335)



Include Making - sciman001 - 30.03.2011

Include Making!
So, whats the big deal with includes? Why would we want to make our own? Well, firstly i think that includes are the most inportant part of a script itself! They provide all the FUNCTIONS. For example... a custom function could be:
pawn Код:
stock KillAll() //the function
{
    for(new i=0; i<MAX_PLAYERS; i++) //the loop
    {
        SetPlayerHealth(i, 0); //sets the players health to 0
    }
}
So if you have a big function like... a register or login function, you could put the function in an include to reduse script size and thus, compile time(i think). So... i think that pretty much answers the questions stated above. Now, lets make a function with some parameters. This function will flip the defined car.
pawn Код:
stock FlipCar(vehicleid) //the function
{
    GetVehicleZAngle(vehicleid,zangle); //gets the z angle
    SetVehicleZAngle(vehicleid,zangle); //sets the z angle
}
That doesnt look like it will work, but it does(or so i was told). So... now we'll make a multi parameter function.
pawn Код:
stock GOTO(playerid, teleid) //the function
{
    new Float:x, Float:y, Float:z; //defines x, y, z
    GetPlayerPos(teleid, x, y, z); //gets the tele player's position
    SetPlayerPos(playerid, x, y, z+1); sets the players position
}
Heres a SendClientMessageToAllEx function:
pawn Код:
stock SendClientMessageToAllEx(playerid, color, string[]) //function
{
    for(new i; i=MAX_PLAYERS; i<MAX_PLAYERS; i++) //loop
    {
        if(IsPlayerConnected(i)) //if the player IS connected
        {
            if(!i == playerid) //if the player IS NOT == to playerid
            {
                SendClientMessage(i, color, string); //sends the message
            }
        }
    }
}
That will send a message to all except playerid. EX:
pawn Код:
SendClientMessageToAllEx(playerid, 0xFF0000AA, "MESSAGE"); //sends the message to all except playerid
Now... you know when you are in pawno and there is all the functions and the include names above the functions in the include... well, just putting the function in the include alone wont get the function to show up in this columb. To make it show up, we have to use something called a native. A native looks like this.
pawn Код:
native MyFunction(params); //native
You want the native to be commented for it to work flawlessly(or so i was told).
So, for the SendClientMessageToAllEx function, it would look like:
pawn Код:
/*
SendClientMessagetoAllEx(playerid, color, string[]); //native
*/
So, here is another SIMPLE but useful function you can make in about 15 seconds.
pawn Код:
stock SetPlayerHealthAndArmour(playerid, Float:Value)
{
    SetPlayerHealth(playerid, Value);
    SetPlayerArmour(playerid, Value);
    return 1;
}
This sets the players HEALTH AND ARMOUR. I think this is a simple but still useful function. This just shows how to add parameters to your functions. It also shows how you make a param a float.
Here is an example of a "full" include. You put includes in /pawnpo/includes just so you know. And, you HAVE to save it as a .inc file.
pawn Код:
#if defined _minc //if minc is defined
    #endinput //ends the input(i think!)
#endif //ends if
#define _minc //defines minc

stock SendConnectMessage(playerid) //function
{
    new name[MAX_PLAYER_NAME], string[44]; //defines name and scring
    GetPlayerName(playerid, name, sizeof(name)); //gets the player'd name
    format(string, sizeof(string), "%s has joined the server.",name); //formats the message
    SendClientMessageToAll(0x0000FFAA, string); //sends the message
}

stock SendDisconnectMessage(playerid, reason) //function
{
    new string[64], //defines string
    name[MAX_PLAYER_NAME]; //defines name
    GetPlayerName(playerid,name,MAX_PLAYER_NAME); //gets the players name
    switch(reason) //switches
    {
    case 0: format(string,sizeof string,"%s left the server. (Timed out)",name); //formats the message
    case 1: format(string,sizeof string,"%s left the server. (Leaving)",name); //formats the message
    case 2: format(string,sizeof string,"%s left the server. (Kicked/Banned)",name); //formats the message
    }
    SendClientMessageToAll(0x0000FFAA,string); //sends the message
}
/*
native SendConnectMessage(playerid); //native
native SendDisconnectMessage(playerid, reason); //native
*/
If you save this as minc.inc, you would put #include <minc> in your script. EX:
pawn Код:
#include <minc> //includes minc
I really dont think i NEEDED to put that, but there are some people who are new. This is how they learn.
You can even use an include to hold all your defines and if you really wanted, other includes for your script. EX:
pawn Код:
#include <a_samp> //include
#include <blah> //include

#define COLOR_RED, 0xFF0000AA //defines COLOR_RED
And save it as inc.inc then, your script would have this at the top of your script:
pawn Код:
#include <inc> //includes inc

main()
{
     print("hi"); //prints hi
     SendClientMessageToAll(COLOR_RED, "it works!"); //sends a red message saying it works!
}
But you wouldnt need to define color_red since its in the include. And you wouldne need to include a_samp since it also is in the include. I personally really like this method. You cold also have variables and arrays in the include.
There is basically no limit when using includes(except for max playerd, objects, checkpoints, vehicles, etc.). As always, please let me know if any of this is incorrect. THANKS!


Re: Include Making - SchurmanCQC - 31.03.2011

This is a good tutorial for those who aren't sure how to use/make includes.


Re: Include Making - Venice - 31.03.2011

Good TUT


Re: Include Making - ElChapoGuzman - 31.03.2011

nice man


Re: Include Making - sciman001 - 31.03.2011

Thank you VERY much! Its not even done and its already got some great comments! I really appreciate that. THANKZ!


Re: Include Making - BASITJALIL - 31.03.2011

Nice work


Re: Include Making - -Rebel Son- - 31.03.2011

Very exellent man. good job.


Re: Include Making - Kwarde - 31.03.2011

Here's a cut of an include of Ingocnito's streamer.

pawn Код:
#if defined _streamer_included
    #endinput
#endif
#define _streamer_included
a_samp.inc (another cut):
pawn Код:
#if defined _samp_included
    #endinput
#endif
#define _samp_included
a_vehicles.inc:
pawn Код:
#if defined _vehicles_included
    #endinput
#endif
#define _vehicles_included
Getting the feeling that you forgot something that could be usefull? :P
However, it's a nice tutorial.


Re: Include Making - sciman001 - 31.03.2011

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Here's a cut of an include of Ingocnito's streamer.

pawn Код:
#if defined _streamer_included
    #endinput
#endif
#define _streamer_included
a_samp.inc (another cut):
pawn Код:
#if defined _samp_included
    #endinput
#endif
#define _samp_included
a_vehicles.inc:
pawn Код:
#if defined _vehicles_included
    #endinput
#endif
#define _vehicles_included
Getting the feeling that you forgot something that could be usefull? :P
However, it's a nice tutorial.
what exactly are these codes for? I knew they existed.. but i never knew what they did.


Re: Include Making - Calgon - 31.03.2011

Why would you make a tutorial if you're completely clueless to the subject you made a tutorial around?

Pseudo-natives can be used to show include functions in the right-hand side of the PAWNO editor, so define the native IN a comment, because you're not going to be able to use the function as a native. Look up how native functions work here.

The code above is to prevent the same include from being implemented in to the script more than once.

You should explain callback hooking or just drop this tutorial, since it really is of no value to anyone at this stage.