30.03.2011, 23:32
(
Последний раз редактировалось sciman001; 03.04.2011 в 07:41.
Причина: update
)
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:
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.
That doesnt look like it will work, but it does(or so i was told). So... now we'll make a multi parameter function.
Heres a SendClientMessageToAllEx function:
That will send a message to all except playerid. EX:
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.
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:
So, here is another SIMPLE but useful function you can make in about 15 seconds.
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.
If you save this as minc.inc, you would put #include <minc> in your script. EX:
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:
And save it as inc.inc then, your script would have this at the top of your script:
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!
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
}
}
pawn Код:
stock FlipCar(vehicleid) //the function
{
GetVehicleZAngle(vehicleid,zangle); //gets the z angle
SetVehicleZAngle(vehicleid,zangle); //sets the z angle
}
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
}
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
}
}
}
}
pawn Код:
SendClientMessageToAllEx(playerid, 0xFF0000AA, "MESSAGE"); //sends the message to all except playerid
pawn Код:
native MyFunction(params); //native
So, for the SendClientMessageToAllEx function, it would look like:
pawn Код:
/*
SendClientMessagetoAllEx(playerid, color, string[]); //native
*/
pawn Код:
stock SetPlayerHealthAndArmour(playerid, Float:Value)
{
SetPlayerHealth(playerid, Value);
SetPlayerArmour(playerid, Value);
return 1;
}
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
*/
pawn Код:
#include <minc> //includes minc
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
pawn Код:
#include <inc> //includes inc
main()
{
print("hi"); //prints hi
SendClientMessageToAll(COLOR_RED, "it works!"); //sends a red message saying it works!
}