[Tutorial] how to make score, kills, deaths, skin saves
#1

SAVING'S


OK let's start by adding some variable's

So, let's do it


On the Top of the Script

pawn Код:
#include <a_samp> // This includes a_samp from pawno/include/
#include <Dini>      // This include is use for saving data's
#include <Dutils>   // This include is used for some important function
#include <Dudb>   //  This include is used for hashing password
You can find these includes in the description.

Add this under that

Код:
#define savefolder "/save/%s.ini" // This defines the file name and folder

under the includes add this

Код:
#pragma unused ret_memcpy // This avoid the ret_memcpy warning
OK now the variable's. Learn this carefully okay.

Under the #pragma add this

Код:
new Killz[MAX_PLAYERS];       // We have used this variable because to save the kills of the player
new Deathz[MAX_PLAYERS];  // Same on here
Now the main part

Add this under OnPlayerConnect

pawn Код:
new pname[128];  // This get's the length of the player name
    new file[128];        // This get's the lenght of the file
    GetPlayerName(playerid, pname, sizeof(pname)); // This get's the player name with the lenght of the player name
    format(file, sizeof(file), savefolder,pname); // This describe's where to save and how to save it
    if(!dini_Exists(file)) { // If the file exist
        dini_Create(file); // Create the file
        dini_IntSet(file, "Score", 0); // Set's "Score"
        dini_IntSet(file, "Money", 0); // Set's "Money"
        dini_IntSet(file, "Kills", Killz[playerid]); // Set's "Kills"
        dini_IntSet(file, "Deaths", Deathz[playerid]); // Set's "Deaths"
        dini_IntSet(file, "Skin", 0); // Set's Skin
        SetPlayerScore(playerid, dini_Int(file, "Score")); // This describes where to load the score
        SetPlayerMoney(playerid, dini_Int(file, "Money")); // This describes where to load the money
        SetPlayerSkin(playerid, dini_Int(file, "Skin")); // This describes where to load the skin
        // and at last this set's the value which were on the file
    }
    else {
        SetPlayerScore(playerid, dini_Int(file, "Score"));
        SetPlayerMoney(playerid, dini_Int(file, "Money"));
        SetPlayerSkin(playerid, dini_Int(file, "Skin"));
        // the same thing
    }
Ok now

Under OnPlayerDisconnect add this

pawn Код:
new pname[128]; // The name length
    new file[128]; // The file length
    GetPlayerName(playerid, pname, sizeof(pname)); //  This get's the player name with the name length
    format(file, sizeof(file), savefolder,pname); // Formatting file
    if(!dini_Exists(file)) { // If the file exist
    }
    else { // if not
        dini_IntSet(file, "Score", GetPlayerScore(playerid)); // This Get the Score
        dini_IntSet(file, "Money", GetPlayerMoney(playerid)); // This Get the cash
        dini_IntSet(file, "Kills", Killz[playerid]);  // This get the kills
        dini_IntSet(file, "Deaths", Deathz[playerid]); // This get the Deaths
        dini_IntSet(file, "Skin", GetPlayerSkin(playerid)); // This get the skin
    }
It's not yet finished. We still have to define the Killz and Deathz.

Under OnPlayerDeath add this

Код:
Killz[killerid] ++; // The killer value will be increased
Deathz[playerid] ++; // The death value will be increased
Descriptions:
-------------

Create a folder on your server scripfiles and rename it to save.

You will need Dini, Dutils and Dudb include.

-------------

Tired of learning and writing. Download this example script

HERE
Reply
#2

nice job. But one question. Why have you use Killz[MAX_PLAYERS] instead of Killz?
Reply
#3

nice question. That is because to find the difference between killerid and playerid
Reply
#4

good work. Now it will be easy
Reply
#5

thanks guys. I have did this tutorial in 10 mins
Reply
#6

Nice man
Reply
#7

thanks!!
Reply
#8

Quote:
Originally Posted by jejemonerz123
Посмотреть сообщение
nice job. But one question. Why have you use Killz[MAX_PLAYERS] instead of Killz?
Because Killz only will work for ID 0, and with MAX_PLAYERS will work for max 500 players, because the a_samp definition of MAX_PLAYERS is 500.
pawn Код:
#define MAX_PLAYERS (500)
So you are doing
pawn Код:
new Killz[ (500) ];
So, size of 500, works for 500 players.

Nice tut, but I don't like Dini.
Reply
#9

Quote:
Originally Posted by Mean
Посмотреть сообщение
Because Killz only will work for ID 0, and with MAX_PLAYERS will work for max 500 players, because the a_samp definition of MAX_PLAYERS is 500.
pawn Код:
#define MAX_PLAYERS (500)
So you are doing
pawn Код:
new Killz[ (500) ];
So, size of 500, works for 500 players.

Nice tut, but I don't like Dini.
me tooo. I like y_ini always. BTW I show it in DINI to make people understand
Reply
#10

Verry nice !
Keep it up!
Reply
#11

Quote:
Originally Posted by [DR]Reaper[GEARS]
View Post
Verry nice !
Keep it up!
thanks mate!
Reply
#12

G00D J0B
Reply
#13

thaNZ
Reply
#14

Question how would I make a command where it shows players stats for exmaple /stats [id] displays there stats like Kils:0 Deaths:0 Money:0 Score:0 ect..
Reply
#15

you can make it easily with format function
Reply
#16

Nice it is very usefull!
Reply
#17

ya thanks
Reply
#18

I think This FS is better so
Reply
#19

thnx for the tutorial
Reply
#20

Quote:
Originally Posted by $$inSane
View Post
thnx for the tutorial
I'm enough, every time i see you in old topics i'm very very enough.
You just making your post count grower, you didn't even test the tutorial.
Don't bother posting in old topics or don't post like

'Nice'
'Thanks it help me alot'
'Rep for you'
'Nice job'

i'm enough really enough!

By the way this is 1 year old topic and you bumping it gosh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)