18.09.2010, 07:14
(
Последний раз редактировалось Kwarde; 27.05.2011 в 22:29.
)
Hi!
Are you an beginner in PAWN scripting, and do you wanna learn more?
I'll help you for the begin! (At least, I hope that I can help you :"))
STEP 1: Includes
You need "includes" before you can make a usefull gamemode or filterscript. You can do this with '#include'
The most people put this above their script, so I strongly recommend you to do this too
For a good FS/GM (FilterScript/GameMode) you need the include 'a_samp' : here are all the basic functions.
So put this above the script
Easy!! :O
And there are more includes, the standard includes and the one that people made. You need to put the includes in the 'pawno/includes' map. So if you wanna make a log system, a join log for example, you'll need to use files! These are included in a_samp, but this is just an example! You should add this:
You can include as much you want, just watch out that some includes don't have the same function names.
STEP 2: Starting FS/GM
Maybe you need to set some string if the game starts. You need to put this in 'public OnFilterScriptInit()' or 'public OnGameModeInit()' If you are making a gamemode you need to put 'main()' to in the script.
But this is not everything! Now it's gonna be a bit harder. You need to set... things in it :'). Use brackets to open and close the function ({ & }). Example's:
The function print: It just shows some text in the samp_server.exe client. You can use printf too to format some things (printf("text: %s", string)
You need to do the same with public OnGameModeInit and public OnFilterScriptInit as main():
It is easy :') - You can do this the same way to EXIT the FS/GM (OnFilterScriptExit and OnGameModeExit)
STEP 3 - Making variables and defines
You are really making you own FS/GM now! Now it is very handy to make variables and defines.
Variables are just things you can use for usersystems or something, to check if someone is logged.
Make this things on this way: new VAR_NAME;. If you are just using it as an 'TRUE' and 'FALSE' variable you can make a bool: new bool:VAR_NAME = false;. And yeah, you can set the string of it when you are making it: new VAR_NAME = STRING;. This won't work: new VAR_NAME = Just Some Text;. Then you will get an error :S. Then use this: new VAR_NAME = "Just Some Text";. I don't know of it works, I never use it. I am using 'STRINS'. You can make strings for one player, or one vehicle (I meant: one 'effect' per player or vehicle). Just add [MAX_PLAYERS] or [MAX_VEHICLES] behing the 'VAR_NAME'. You can set the max string too, if the string may not be longer then 10 lettre's, use this: new VAR_NAME[10];
But whatever, There are DEFINES too. These are almost the same, but different too .
You can't change this things, but you can remove them (the normal variables can't). You make one with '#define'.
The most people put this under the INCLUDES, Me too, So I recommend you to do it too :'). It is very handy and usefull to make Color Defines for sending messages. The define will look like this: #define DEFINE_NAME INT
after #define and DEFINE_NAME a space. So a color will look like this: #define COLOR_WHITE 0xFFFFFFAA. Very handy . You can put text into defines too: #define OWNER_NAME "Kwarde".
There are more ways to use defines, like 'mini functions' (macro's): #define SendMessage(%0, %1, %2) SendClientMessage(%0, %1, %2);. But enough about this stuff. Let's talk about functions.
STEP 4 - Making Functions
Functions are VERRRRY usefull :'). If you are constantly using one thing it is better to make one function, it cost less diskspace. You can make a function on different ways, the PUBLIC function, the STOCK function and the "" Funtions (-.-).
Let's begin with the public function. This are callbacks. There are standard callbacks, like 'public OnPlayerConnect(playerid): Do something if a player connects'- 'public OnPlayerDisconnect(playerid, reason): Do something if a player disconnect'. You can just put these callbacks in your script (the built in callbacks!). But if you wanna make your own, you need to FORWARD it on this way: forward FUNCTIONNAME();. Ok, forwarded. And now? Simple: Use the public again : public FUNCTIONNAME(){//code}. You can't use the tag 'playerid' now, because it isn't in the callback. Do it on this way:
Easy, isn't it? Remember that you can much more stuff in the callbacks, like vehicleid or your own tag. I'll give an example function, a function that sends a message to ALL the RCON admins, so the non-RCON admins won't see it
In this script, I'll use "SendClientMessage". This is the function to send an client message to a player: SendClientMessage(playerid, color, message[]); - Example: SendClientMessage(playerid, 0xFFFFFFFF, "Hi there!"); : This will send a message "Hi there!" in a white color
The function will work like this: SendMessageToRconAdmins(COLOR_CODE, MESSAGE);. For example: SendMessageToRconAdmins(0xFFFFFFAA, "Hi RCON admins!"); - All Rcon Admins will now see the message 'Hi RCON admins!' in a white color. But enough about this, now the STOCK and the "" functions.
These are easy XD. You don't need to forward these. Just some examples:
OR
Very easy
STEP 5 - Making commands
I think you have seen it: Commands. There are simple commands, like '/commands' or '/help'. These are easy to script. But there are harder commands, like '/pm' (easy for me, for beginners harder :').
You need the CALLBACK OnPlayerCommandText. Use it on this way: public OnPlayerCommandText(playerid, cmdtext[]). Hmm. We didn't make a command yet. Let's do that :P
EASY! But be carefully: this is the way how to script it in a GameMode, you need to do it different in a FilterScript, if you don't all the GameMode commands won't work anymore :P
Well. This ain't hard. If you don't understand it, send me an PM
[EDIT]
I've got a PM from a beginner, he wanted two commands but got a error, so I am gonna explain how to add more commands: Just don't add more 'OnPlayerCommandText' callbacks, because you will get (a) error(s) - Just add more "strcmp's" :') A example:
STEP 6 - Make your script working
This is the easiest thing. Just press F5 (if you are using PAWNO). You need to wait, and then a screen appears. Here are the errors and warnings. If you just see this:
It's okay! Everything is GOOD! If you see warnings it is okay (mostly), but if you see errors, the script won't compile and you need to fix it. I won't help you with this now
This is the end of the tutorial. I hope it was usefull for you, and to the advanced scripters (and maybe beginners): tell me if something is missing!
Kind Regards,
Kwarde
Are you an beginner in PAWN scripting, and do you wanna learn more?
I'll help you for the begin! (At least, I hope that I can help you :"))
STEP 1: Includes
You need "includes" before you can make a usefull gamemode or filterscript. You can do this with '#include'
The most people put this above their script, so I strongly recommend you to do this too
For a good FS/GM (FilterScript/GameMode) you need the include 'a_samp' : here are all the basic functions.
So put this above the script
pawn Код:
#include <a_samp>
And there are more includes, the standard includes and the one that people made. You need to put the includes in the 'pawno/includes' map. So if you wanna make a log system, a join log for example, you'll need to use files! These are included in a_samp, but this is just an example! You should add this:
pawn Код:
#include <file>
STEP 2: Starting FS/GM
Maybe you need to set some string if the game starts. You need to put this in 'public OnFilterScriptInit()' or 'public OnGameModeInit()' If you are making a gamemode you need to put 'main()' to in the script.
But this is not everything! Now it's gonna be a bit harder. You need to set... things in it :'). Use brackets to open and close the function ({ & }). Example's:
pawn Код:
main()
{
print("STARTED");
}
You need to do the same with public OnGameModeInit and public OnFilterScriptInit as main():
pawn Код:
public OnGameModeInit()
{
print("GM STARTED");
}
pawn Код:
public OnFilterScriptInit()
{
print("FS STARTED");
}
STEP 3 - Making variables and defines
You are really making you own FS/GM now! Now it is very handy to make variables and defines.
Variables are just things you can use for usersystems or something, to check if someone is logged.
Make this things on this way: new VAR_NAME;. If you are just using it as an 'TRUE' and 'FALSE' variable you can make a bool: new bool:VAR_NAME = false;. And yeah, you can set the string of it when you are making it: new VAR_NAME = STRING;. This won't work: new VAR_NAME = Just Some Text;. Then you will get an error :S. Then use this: new VAR_NAME = "Just Some Text";. I don't know of it works, I never use it. I am using 'STRINS'. You can make strings for one player, or one vehicle (I meant: one 'effect' per player or vehicle). Just add [MAX_PLAYERS] or [MAX_VEHICLES] behing the 'VAR_NAME'. You can set the max string too, if the string may not be longer then 10 lettre's, use this: new VAR_NAME[10];
But whatever, There are DEFINES too. These are almost the same, but different too .
You can't change this things, but you can remove them (the normal variables can't). You make one with '#define'.
The most people put this under the INCLUDES, Me too, So I recommend you to do it too :'). It is very handy and usefull to make Color Defines for sending messages. The define will look like this: #define DEFINE_NAME INT
after #define and DEFINE_NAME a space. So a color will look like this: #define COLOR_WHITE 0xFFFFFFAA. Very handy . You can put text into defines too: #define OWNER_NAME "Kwarde".
There are more ways to use defines, like 'mini functions' (macro's): #define SendMessage(%0, %1, %2) SendClientMessage(%0, %1, %2);. But enough about this stuff. Let's talk about functions.
STEP 4 - Making Functions
Functions are VERRRRY usefull :'). If you are constantly using one thing it is better to make one function, it cost less diskspace. You can make a function on different ways, the PUBLIC function, the STOCK function and the "" Funtions (-.-).
Let's begin with the public function. This are callbacks. There are standard callbacks, like 'public OnPlayerConnect(playerid): Do something if a player connects'- 'public OnPlayerDisconnect(playerid, reason): Do something if a player disconnect'. You can just put these callbacks in your script (the built in callbacks!). But if you wanna make your own, you need to FORWARD it on this way: forward FUNCTIONNAME();. Ok, forwarded. And now? Simple: Use the public again : public FUNCTIONNAME(){//code}. You can't use the tag 'playerid' now, because it isn't in the callback. Do it on this way:
pawn Код:
forward FUNCTION_NAME(playerid);
public FUNCTION_NAME(playerid)
{
//Code goes here
}
In this script, I'll use "SendClientMessage". This is the function to send an client message to a player: SendClientMessage(playerid, color, message[]); - Example: SendClientMessage(playerid, 0xFFFFFFFF, "Hi there!"); : This will send a message "Hi there!" in a white color
pawn Код:
forward SendMessageToRconAdmins(color, message[]); //Yes, a '[]' behind message, because it is a text string!
public SendMessageToRconAdmins(color, message[])
{
new string[128]; //Make a string, you already know how to do this :P
format(string, sizeof(string), "[RCON] %s", message); //Format the variable string
for(new i = 0; i < MAX_PLAYERS; i++) //Loop through all the players (just a '500' loop)
{
if(IsPlayerConnected(i)) //If the player is connected, prevent laggs
{
if(IsPlayerAdmin(i)) //If Is Player Admin (OMG), just check if the player is an RCON admin
{
SendClientMessage(i, color, string); //SendClientMessage(all_rcon_admins, text_color, var_string);
}
}
}
}
These are easy XD. You don't need to forward these. Just some examples:
pawn Код:
stock SendMessage(playerid, color, text[])
{
SendClientMessage(playerid, color, text);
}
pawn Код:
SendMessage(playerid, color, text[])
{
SendClientMessage(playerid, color, text);
}
STEP 5 - Making commands
I think you have seen it: Commands. There are simple commands, like '/commands' or '/help'. These are easy to script. But there are harder commands, like '/pm' (easy for me, for beginners harder :').
You need the CALLBACK OnPlayerCommandText. Use it on this way: public OnPlayerCommandText(playerid, cmdtext[]). Hmm. We didn't make a command yet. Let's do that :P
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/THE_COMMAND", true) == 0)
{
//Here goes the code
}
return 1;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/THE_COMMAND", true))
{
//Here goes the code
}
return 0;
}
[EDIT]
I've got a PM from a beginner, he wanted two commands but got a error, so I am gonna explain how to add more commands: Just don't add more 'OnPlayerCommandText' callbacks, because you will get (a) error(s) - Just add more "strcmp's" :') A example:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/THE_COMMAND", true))
{
//Code
}
if(!strcmp(cmdtext, "/ANOTHER_COMMAND", true))
{
//Code
}
return 0;
}
STEP 6 - Make your script working
This is the easiest thing. Just press F5 (if you are using PAWNO). You need to wait, and then a screen appears. Here are the errors and warnings. If you just see this:
Quote:
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase |
This is the end of the tutorial. I hope it was usefull for you, and to the advanced scripters (and maybe beginners): tell me if something is missing!
Kind Regards,
Kwarde