[Tutorial] Script Basics
#1

Scripting Basics
Hello world, this is my first Tutorial, I made it for beginners. You can visit wiki.sa-mp.com for more information.

FAQ:
-What is the difference between pawno and pawn?
-Pawno is the program, while pawn is the language.

Lesson 1: Starting.

1. Download a server package: http://sa-mp.com/download.php
2. Extract these files into a folder.
3. Open pawno/pawno.exe.
4. Click on new.

Lesson 2: Scripting basics.

1. How to add classes:
Код:
AddPlayerClass(skin, Float:x, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
Example:
Код:
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
Put this code under OnGameModeInit.
Example:
Код:
public OnGameModeInit ()
{
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}
2. How to change the gamemode text:
Код:
    SetGameModeText("Change Me");
Put this under OnGameModeInit.
Change Change Me to the name you want.

3. How to add vehicle/s:
Код:
    AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
Example:
Код:
    AddStaticVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1);
Put this code under OnGameModeInit.

4. How to change the class selection place:

You will find this in your code;
Код:
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;
}
SetPlayerPos sets the player's position, parameters are: playerid, x, y, z. You have to find the spawn coordinates you want.

Simple Example:
Код:
public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetCameraBehindPlayer(playerid);
	return 1;
}
5. How to create pickup/s
Код:
CreatePickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
View this page: https://sampwiki.blast.hk/wiki/CreatePickup for more information.

6. How to create objects:
Parameters:
Код:
   CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance)
Visit https://sampwiki.blast.hk/wiki/CreateObject for more information.

7. How to spawn weapons:
Код:
    GivePlayerWeapon(playerid, weaponid,  ammo):
Put this code under OnPlayerSpawn.

Now, you have learnt all the scripting basics, here is some useful includes and plugins:
ZCMD // https://sampforum.blast.hk/showthread.php?tid=91354
Sscanf // https://sampforum.blast.hk/showthread.php?tid=570927
Streamer // https://sampforum.blast.hk/showthread.php?tid=102865

Lesson 3: How to add includes.
1. Download an include.
2. Save the code as "theincname.Inc"
3. Copy the include and paste it in "server/pawno/include"

Lesson 4: Server.cfg config.
This is the default Server.cfg file.
Код:
echo Executing Server Config...
lanmode 0
rcon_password changeme
maxplayers 50
port 7777
hostname SA-MP 0.3 Server
gamemode0 grandlarc 1
filterscripts gl_actions gl_realtime gl_property gl_mapicon ls_mall attachments skinchanger vspawner
announce 0
query 1
chatlogging 0
weburl www.sa-mp.com
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
maxnpc 0
logtimeformat [%H:%M:%S]
1. rcon_password (string) [This is the RCON password]
2. port [This is the port of your server, default is: 7777.]
3. hostname (string) [This is the name of your server.]
4. gamemode0 [This is the name of your gamemode, default is: grandlarc.]
5. filterscripts [This is the name of your filterscript/s For example: gl_action other other, when you make any filterscript you should define it here.]
announce [This makes your server on Internet tab.]
6. weburl [This is the link of your community/forum.]

Lesson 5: Medium Level Scripting.


1. How to use stock:

The 'stock' function modifier is a flag that tells the compiler to ignore the function or variable marked with 'stock' at compile time if it isn't used. This means that the compiled code will not have the unused data and thus use less disk space and memory. It must nonetheless be noted that there usually isn't any need to declare a function as stock within a gamemode or filterscript. You will most likely want to use that function anyway and the compiler will issue a handy warning in case you do forget to use it.

When you compile a script only the stock functions which you use in your script are saved, and any you fail to include do not appear in the compiled ".amx", thus increasing efficiency in one way or another. For example, if you have a stock function that gave the player a vehicle, but you never use it, when you go to compile the compiler wouldn't bothered including it. This makes it advantageous to have large stock libraries stored in includes, as the script will only "extract" the ones it requires upon compiling.

example:
Код:
stock KillPlayer(playerid)
{
    SetPlayerHealth(playerid, 0.0); // Sets the player health to 0, That kills the player.
    return 1;
{

CMD:kill(playerid) // You must have ZCMD Include to make this.
{
    KillPlayer(playerid); // That's the stock function.
    return 1;
}
Other example:
Код:
stock Restart()
{
    SendRconCommand("gmx"); // Sends rcon command to restart the server [In game command = /rcon gmx]
    return 1;
}

//Put this anywhere you want.
    Restart();
2. How to make timers:

Код:
forward RestartServer(); // make this to make "public RestartServer"

stock Restart()
{
    SendRconCommand("gmx");
    return 1;
}

public RestartServer()
{
    Restart();
    return 1;
}

public OnFilterScriptInit()
{
    SetTimer("RestartServer", 10000 * 60 * 10, true);
    return 1;
}
3. Usage of strcat:
Visit this page: https://sampwiki.blast.hk/wiki/Strcat for more information.

4. Dialogs and styles:
Styles - https://sampwiki.blast.hk/wiki/Dialog_Styles
Dialog Response - https://sampwiki.blast.hk/wiki/OnDialogResponse
Dialog Examples - https://sampwiki.blast.hk/wiki/ShowPlayerDialog

5. How to use Enumenators > Making Kill/Death system [Using Enumenators]

Enumerations are a very useful system for representing large groups of data and modifying constants quickly:
Here is an Example:
Код:
enum PlayerData
{
    kills,
    deaths
};
new PData[MAX_PLAYERS][PlayerData];

public OnPlayerDeath(playerid, killerid, reason)
{
   if(killerid != INVALID_PLAYER_ID)
    {
        PData[killerid][kills] ++;
    } 
    PData[playerid][deaths] ++;  
    return 1;
}
ID's Guide
Interior ID's // http://weedarr.wikidot.com/interior
Weapon ID's // https://sampwiki.blast.hk/wiki/Weapons
Object ID's // http://gta-sa-mp.de/forum/index.php?page=Objects
Weather ID's // https://sampwiki.blast.hk/wiki/WeatherID
Pickup ID's // http://weedarr.wikidot.com/pickups

SA-MP wiki
- Timers: https://sampwiki.blast.hk/wiki/SetTimer
- Textdraws: https://sampwiki.blast.hk/wiki/Textdraw
Reply
#2

Its called curly brackets.

Gj.
Reply
#3

Quote:
Originally Posted by Freezo
Посмотреть сообщение
Its called curly brackets.
Curly brackets = braces = { }.
Reply
#4

Simple and straightforward, yet not any different from any other beginner tutorial.

Quote:
Originally Posted by ._Xavier$$
Посмотреть сообщение
NOTE: you must make 4 spaces at every line you make , not all but for Example:
Or, you know, press Tab ...
Reply
#5

Quote:
Originally Posted by ._Xavier$$
Посмотреть сообщение
FAQ:
-What is the difference between pawno and pawno?
None.

Looks good enough. Keep it updated!
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Simple and straightforward, yet not any different from any other beginner tutorial.



Or, you know, press Tab ...
Thanks, yeah I know

Quote:
Originally Posted by Michael B
Посмотреть сообщение
None.

Looks good enough. Keep it updated!
Thanks
Reply
#7

I've made a small update, hope you like it.
Reply
#8

Yep, looks better now, with more information. Keep it up!
Reply
#9

Try to surpass this: http://forum.sa-mp.com/showpost.php?...46&postcount=1
Reply
#10

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
I will try.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)