Jump to content
Hostul a fost schimbat. Daca vedeti serverul offline readaugati rpg.b-zone.ro sau 141.95.124.78:7777 in clientul de sa-mp ×

[PAWN] How to code SA-MP


Dion ibe
 Share

Recommended Posts

Hello ,If you have problem in your script ,Check my étape one by one! to know how you can code SA-MP Pawn [Tutorial]
 
Introduction
There is hundreds of tutorials on the web to help you learn to code. Whether it be PHP, C or even PAWN. This tutorial though is for our regulars at AdrenalineX. A quick overview of how easy adding new features to the server can be.
 
Tools Required
You don't need much to get to started, just download the SA-MP Server files and you're ready to go.
Select 'SA-MP Windows Server Download'
Extract this file to create a new folder, the server folder.
pawno : The scripting folder, this contains the pawno.exe application that's used to script Pawn.
server.cfg : This contains all the setup data for the server, including gamemode, filterscripts and plugins.
gamemodes : The gamemode is the main script that is hosted.
filterscripts : Filterscripts are extra scripts needed by the server, like Anti-Cheat scripts for example.
plugins : These are server side plugins, .dll files that hook into the server from the host server.
server.exe : The server application, double click to start server.
samp-npc.exe : The NPC (Bot) application. Used by server.exe only. Each both had it's own samp-npc.exe process.
announce.exe : To announce the server on the SA-MP Master List. Used by the server.exe only.
Getting Started
Inside the pawno folder is an application named 'pawno.exe', double click it to load the window. Click 'file' then 'new' to auto create a base for your script.
NOTE: Net Framework 1.1 is needed, as it uses it to compile the script.
○-Tesing Code-
Now we have started to script, we should test it to see it in action. Click 'file' and then 'save as'. The script needs to saved into the 'gamemodes' folder. Select a name to save as, I'm going to call it TestCode. Press F5 to compile the script.
In your main server folder, open the file named server.cfg and edit the gaemodes line.
gamemode0 gtl 1

You should change it to your script name, I called mine TestCode.

gamemode0 TestCode 1
While you have the server.cfg open, edit the rcon password.
rcon_password mypassword

Go back to your server folder and start the server by double clicking server.exe.

Add your local server I.P to your SA-MP client. By default the I.P and port will be 127.0.0.1:7777.
Callbacks
SA-MP callbacks are easily described as triggers, the player triggers an event that contacts the server. Along with the triggered event, extra params are sent, thus enabling the server to take the data from the event.
public OnPlayerDeath( playerid, killerid, reason )
{
   GameTextForPlayer( playerid, " WASTED ! ",5000,0);
   GameTextForPlayer( killerid, " YOU KILLED HIM ! ",5000,0);
   printf("[[debug] Player %d got killed by %d    reason id %d ",playerid, killerid, reason );
    return 1;
}
Custom Callbacks
Along with the SA-MP Callbacks, you can also create custom callbacks to track player changes. A good example is OnPlayerHeal( playerid, Float:increase ).
The above on it's own though it's pretty useless as all you're only telling the server the players ID and a float value.
Under your include <a_samp> add the following line:
forward OnPlayerHeal( playerid, Float:increase );
The above gives the compiler an address to call, basically when OnPlayerHeal is called, it won't give any errors.
Now create the actual custom callback, but keep it empty for now.
 
Quote

public OnPlayerHeal( playerid, Float:increase )
{
    return 1;
}
Unlike the SA-MP Callbacks, we have to manually code when they are triggered. OnPlayerHeal, the player can be healed at any time, so the best solution here is a timer. Creating a timer is very easy, it even appears on the right of the Pawno application.
Under OnGameModeInit() (this callback happens only when the server is started/restarted) you need to add the code to create a timer.
public OnGameModeInit()
{
    SetTimer( "HealthTimer", 1000, 1);
    return 1;
}
The new identifies it as a new variable. Float: lets it also know it's a float value (56.44). playerHealth is the name we're going to call the variable. The [MAX_PLAYERS] states that is can store data for all players (ID). The [2] means it has two storage places (two values to the same variable name).
Now we can add the code that will let the server know if the player has healed.
public HealthTimer()  
{
    // now we have to scan all connected players, to
    // see if their health has changed.  This requires a loop
    for(new i; i < MAX_PLAYERS; ++)
    {
        // the above loops through all player ID's
        // the i we now define as the playerid
        GetPlayerHealth( i, playerHealth[ i ][ 0 ] );
        if( playerHealth[ i ][ 0 ] >  playerHealth[ i ][ 1 ] )
        {
            // player found with health increased, call OnPlayerHeal
            OnPlayerHeal( i, playerHealth[ i ][ 0 ] - playerHealth[ i ][ 1 ] );
        }
        playerHealth[ i ][ 1 ] = playerHealth[ i ][ 0 ];
   }
    return 1;
}

Thanks for your time,Good luck :*:* :((:42:X(:(

 

Edited by Cdorsu
Link to comment
Share on other sites

Frumos, te pricepi

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.