02.11.2013, 21:52
Herro! If you're reading this, you are most likely a new scripter looking to learn something new. If you're not, well then herro to you too!
Different Script Types
In SAMP scripting, there are a few different script types. The current types are: Gamemodes, Filterscripts, Includes, and a unique type that is not written in Pawn, and that is Plugins.
Gamemodes
These are pretty much the backbone of a server, it reads the code inside of the file and executes it. Think of it like Call of Duty gamemodes, deathmatch, team deathmatch, etc. But with SAMP, there are almost endless opportunities with gamemodes. The common types of gamemodes are; Team Deathmatch, Freeroam, Roleplay, Cops N' Robbers, and Stunting.
You can find gamemodes made by other scripters here: http://forum.sa-mp.com/forumdisplay.php?f=71
Filterscripts
These types of scripts add on to your gamemode. They are coded pretty much the same as gamemodes but have different callbacks which I will talk about later. They can be a variety things such as: anticheats, vehicle systems, admin systems, etc.
Different Script Types
In SAMP scripting, there are a few different script types. The current types are: Gamemodes, Filterscripts, Includes, and a unique type that is not written in Pawn, and that is Plugins.
Gamemodes
These are pretty much the backbone of a server, it reads the code inside of the file and executes it. Think of it like Call of Duty gamemodes, deathmatch, team deathmatch, etc. But with SAMP, there are almost endless opportunities with gamemodes. The common types of gamemodes are; Team Deathmatch, Freeroam, Roleplay, Cops N' Robbers, and Stunting.
You can find gamemodes made by other scripters here: http://forum.sa-mp.com/forumdisplay.php?f=71
Filterscripts
These types of scripts add on to your gamemode. They are coded pretty much the same as gamemodes but have different callbacks which I will talk about later. They can be a variety things such as: anticheats, vehicle systems, admin systems, etc.
Includes
This type extends the possibilities of SAMP and adds new functions that you can use in either gamemodes or filterscripts. Includes range from simple and easy shortcuts to advanced vehicle systems or command processors. The most used includes are ZCMD() and YSI().
Getting Started
Gamemodes, Filterscripts, and Includes all use a scripting language called Pawn.
Quote from the SAMP wiki:
Getting Started
Gamemodes, Filterscripts, and Includes all use a scripting language called Pawn.
Quote from the SAMP wiki:
Quote:
Pawn is a programming language that is embedded into other programs, for example, Half-Life or Quake, in our case, SA-MP. CompuPhase SMALL is a simple, typeless, 32-bit extension language with a C-like syntax. It is designed to be useful as an embedded systems programming language and is distributed under a liberal zLib/libpng license. This language is useful as a safer environment within or alongside the C programming language, for instance as a scripting language in games programming or on resource-limited systems. Now, however, it has been renamed to PAWN. |
Getting Pawno
Pawno is the default Pawn scripting editor, a heavily outdated version of it is already included in the Samp Server Package. Just download it here: . Extract the folder somewhere you will remember, and open up the Pawno folder. To open up the scripting editor, click on Pawno.exe. When it starts up, click File -> New and a default script will appear that will look similar to this:
Analyzing the code
pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Blank Filterscript by your name here");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
#endif
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;
}
Includes
At the top, your includes that you are going to include(haha) always go at the top. You put #include <Include-Name>. The <> means that the include is going to be in the include folder. Another way to include files is to use quotations(""), it includes a .pwn that is relative to the gamemode directory. For example, you put #include "Core/test.pwn" it will include a file in Gamemodes\Core\ named test.pwn.
Defines
Defines are basically shortcuts so you don't have to type the same thing over and over again. They are commonly used for COLOR defines and settings.
This is tutorial is currently really incomplete, i'll add new sections.
Defines
Defines are basically shortcuts so you don't have to type the same thing over and over again. They are commonly used for COLOR defines and settings.
This is tutorial is currently really incomplete, i'll add new sections.