17.07.2013, 09:00
(
Последний раз редактировалось Rufio; 18.07.2013 в 18:15.
)
INTRODUCTION
I created this tutorial to help people who doesn't know how to create a server and who doesn't know how to make basic scripting. I will make this topic a serie. Going to probably 6 or 7. Or maybe more. I have got lots to explain. But they will come soon. We will go through several things, they are :
So let's start, shall we ?
- - What is PAWN ?
- What is Pawno ?
- What is function ?
- What is callback ?
- Defining colors.
- Includes
- Let's write hello world !
- Well-known compiler errors
So let's start, shall we ?
1) What is PAWN ?
PAWN is a programming language which is typeless. It is a mix of already known programming languages. PAWN is used by many games including SA-MP. It has got functions and callbacks just like any other programming language !
2) What is Pawno ?
[B][I][CENTER]Pawno is a programming language application which helps us creating PAWN scripts. It has got a pawncc.exe which works as a compiler and a compiler helps you finding errors and warnings which prevents your script working good. If it compiles right, it will create an .amx file which will be used if you start samp-server.exe. Servers use .amx files, they do NOT use .pwn file to open the script.
3) Where can I get 'Pawno' ?
Well, it is in standard SA-MP server package. You can get SA-MP server package for 0.3x here : Click me !. After you download SA-MP server package's RAR, extract them to desktop. Open the folder and here we go. Pawno is in Pawno folder inside your server folder. Just click on Pawno.exe
4) But it is blank page and I can't write something !
Of course you can not ! Just hit 'New' at the left-top corner of your pawno. It must be a blank page. When you scroll your mouse to there it already says 'New'. Hit there and you will see a empty script with lots of callbacks !
We will make a gamemode so we should delete these lines :
pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
pawn Код:
#define FILTERSCRIPT
What else will we do ?
Well, delete these lines as we are not making filterscript again.
pawn Код:
#if defined FILTERSCRIPT // Well, if you are making a filterscript, then don't delete here. This tells the script if filterscript's defined at the top of our script.
public OnFilterScriptInit() // This is a callback. Here starts as soon as your filterscript gets started. Even though before your server starts. So you can use here to connect your SQL to your server ! And you can add your vehicles, classes, objects here ! And lots of more of course ! :)
{
print("\n--------------------------------------");
print(" Blank Filterscript by your name here"); // These prints are the ones which prints to your console. Such as 'Rufio's Test gamemode has been started !' !
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit() // This is the callback used in filterscript's exiting. That can be done manually by RCON-logging in your server and typing /rcon unloadfs 'fsname' or automatically by closing your server. You can print again of course ! Such as 'Rufio's test filterscript has been shut down !' ! ;)
{
return 1; // Return 1 is a function though. It means return this true. 1 is true, 0 is false.
}
#else // This tells the script if this script is a gamemode.
pawn Код:
#endif
So, final-looking of our gamemode shall be :
pawn Код:
#include <a_samp>
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
Код:
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
We will edit this gamemode later. But first, I will tell you what is function and what is callback.
5) What is function ?
Function is a part of scripting. It tells the script what to do in which callback. Such as,
SendPlayerMessage(playerid, 'COLOR' , "Asdasdasdas");
is a function. It tells the script to send player a message in a color you specified. And the message should be asdasdasdas. Well, you must put " " before writing your text. It means string in scripting languages. And string means text in proper English. Let's give an example to understand this better:
If we add this to OnPlayerConnect, it should look like this:
pawn Код:
public OnPlayerConnect(playerid)
{
SendPlayerMessage(playerid, COLOR_RED, " Welcome to our server ! Have fun ! :)" );
return 1;
}
When a player connects, this message will appear to him. Just him. If we want to send this to public, we will simply make:
pawn Код:
public OnPlayerConnect(playerid)
{
SendPlayerMessageToAll(COLOR_RED,"A player has joined our server ! Welcome ! :)");
return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
pawn Код:
SendPlayerMessageToAll(COLOR_RED,"A player has joined our server ! Welcome ! :) ");
Still, our script should give a error. It should be this :
Код:
error 017: undefined symbol "COLOR_RED"
For more about functions, visit wiki.sa-mp.com !
[B][I][CENTER]6) What is callback ?
Callbacks are the skeletons of scripting. Callbacks tell our script statements. You can understand them with your English though. So I won't tell too much about callbacks. They are really easy to understand ! Such as :
pawn Код:
OnPlayerConnect
pawn Код:
OnPlayerDisconnect
pawn Код:
OnPlayerSpawn
pawn Код:
OnPlayerDeath
But, there are several important callbacks. I will talk about them :
They are :
pawn Код:
main()
pawn Код:
OnGameModeInIt
OnGameModeInIt is almost for everything ! Pickups, map-icons , objects, vehicles, classes, Gamemode text.
That is all I am going to tell about callbacks. Visit wiki.sa-mp.com for more ! You can ask help in here too !
7) Defining Colors !
We will use this:
pawn Код:
#define
It should be
pawn Код:
#define COLOR_RED 0xA10000AA
pawn Код:
#define COLOR_YELLOW 0xE0E377AA
Includes
Look at the top of your script. It should say :
pawn Код:
#include <a_samp>
Just do not forget this syntax:
pawn Код:
#include <include name>
9) Writing "Hello World!"
Lets make a command.
For so, we will use :
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
it is :
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]) // if a player writes command
{ // callback starts.
if (strcmp("/mycommand", cmdtext, true, 10) == 0) // if a player writes /mycommand
{ // if he writes, start these functions:
// Do something here
return 1; // return true.
} // we ended this command's functions.
return 0; // return false because there is a true above.
} // we ended this callback's functions.
lets do it like this :
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]) // if a player writes command
{ // callback starts.
if (strcmp("/scripting", cmdtext, true, 10) == 0) // if a player writes /scripting
{ // if he writes, start these functions:
SendPlayerMessage(playerid, COLOR_RED, " Hello world !"); // If he writes, send him a red colored "Hello world !" message.
return 1; // return true.
} // we ended this command's functions.
return 0; // return false because there is a true above.
} // we ended this callback's functions.
10) Last but not least, Well-known compiler errors !
the worst of them is :
Код:
error 025: function heading differs from prototype
you wrote a forward wrong. Such as:
If you should have written
pawn Код:
forward SetPlayerTeamFromClass(playerid, classid);
pawn Код:
forward SetPlayerTeamFromClass();
the most common error :
Код:
fatal error 100: cannot read from file: "the include's name"
Код:
error 054: unmatched closing brace ("}")
Код:
error 001: expected token: ";", but found "}"
Код:
error 021: symbol already defined: "a thing you have already defined"
This is all I guess. Hope I helped. You can ask questions of course ! Good Luck !
I will continue this series when I find time though. See you guys !
Tell me all the things I did wrong. I will edit