How do I create player stats?
#1

Hi Im having some trouble with enums and understanding it.

How do I create player stats? Usually roleplay gamemodes after someone registers we go to scriptfiles and we can find the name of the player and when we open it we have:

-Score:
-Cash:
-AdminLevel:
-HoursPlayed
-DrivingLicense
-FlyingLicense


etc something like this and we can actually modify it. How can I script this?
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=318307

Search function / ****** - Took <3 seconds.
Reply
#3

Quote:
Originally Posted by Revo
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=318307

Search function / ****** - Took <3 seconds.
I already saw this and I dont understand
Reply
#4

What is it in specific you don't understand?

What have you tried already?

What errors were generated?
Reply
#5

Quote:
Originally Posted by Revo
Посмотреть сообщение
What is it in specific you don't understand?

What have you tried already?

What errors were generated?
What I dont understand is that In this tuturial he shows up with weird words like Gplayerdata or something like that what does the "g" stand for and how can a file be created with this stats just with enums they just say that the word stores data if i tipe

Enum
Pinfo
Money,




this ofc wont save the money stats into a file thats why im getting confused
Reply
#6

I think you're over thinking it, the tutorial covers both less advanced and more advanced techniques;
In reality, the first few paragraphs is all you need to know to cover the basics and create what you want.

Quote:

Enumerators

There is something about enums that many scripters aren't aware of.

There are many of you using enums in your script for storing Player/Vehicle/House Data etc. (Especially user info)

A typical (or very common) example:
pawn Код:
enum
    e_PlayerInfo
{
    SCORE,
    MONEY,
    KILLS,
    DEATHS
};

new pInfo[MAX_PLAYERS][e_PlayerInfo];
Specifically, that part.

So if you want to store a players' score, cash and if he has a drivers license. You'll want something like this:

pawn Код:
enum playerInfo
{
  Money,
  Score,
  License
};

new pInfo[MAX_PLAYERS][playerInfo];
Example usage would be as following:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
  SavePlayerStatsToDB(playerid); // Your function to save player stats, e.g. by MySQL or ini files, whatever you use.
  pInfo[playerid][Score] = 0; // unset the vars.
  pInfo[playerid][Money] = 0;
  pInfo[playerid][License] = 0;  
}

public OnPlayerConnect(playerid)
{
  LoadPlayerStats(playerid);
}

LoadPlayerStats(playerid);
{
  //Load stats
  //Minor example:
  //You have the variable value, which was previously retrieved using your manner of choice.
  pInfo[playerid][License] = value;
}
SavePlayerStatsToDB(playerid)
{
  //Save stats
}

hasLicense(playerid) // Ideally, you don't want to use a plain function, but much rather perform the if check every                                
                            // time you need it, this is merely an example.
{
  if (pInfo[playerid][License])
  {
     return 1; // player has a license
  }
  return 0;
}
Reply
#7

Quote:
Originally Posted by Revo
Посмотреть сообщение
I think you're over thinking it, the tutorial covers both less advanced and more advanced techniques;
In reality, the first few paragraphs is all you need to know to cover the basics and create what you want.


Specifically, that part.
But what of that Code Says to store the data in a Scriptfiles/user txt file? what i mean is writting Money in pawno its like writing SADASDA because he wont recognize that is the money from the "game"
Reply
#8

enums are not for writing to text files, look into dini/file writing functions/mysql/etc.

I've edited my post with more explaination, give it another read
Reply
#9

Quote:
Originally Posted by Revo
Посмотреть сообщение
I think you're over thinking it, the tutorial covers both less advanced and more advanced techniques;
In reality, the first few paragraphs is all you need to know to cover the basics and create what you want.


Specifically, that part.

So if you want to store a players' score, cash and if he has a drivers license. You'll want something like this:

pawn Код:
enum playerInfo
{
  Money,
  Score,
  License
};

new pInfo[MAX_PLAYERS][playerInfo];
Example usage would be as following:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
  SavePlayerStatsToDB(playerid); // Your function to save player stats, e.g. by MySQL or ini files, whatever you use.
  pInfo[playerid][Score] = 0; // unset the vars.
  pInfo[playerid][Money] = 0;
  pInfo[playerid][License] = 0;  
}

public OnPlayerConnect(playerid)
{
  LoadPlayerStats(playerid);
}

LoadPlayerStats(playerid);
{
  //Load stats
  //Minor example:
  //You have the variable value, which was previously retrieved using your manner of choice.
  pInfo[playerid][License] = value;
}
SavePlayerStatsToDB(playerid)
{
  //Save stats
}

hasLicense(playerid) // Ideally, you don't want to use a plain function, but much rather perform the if check every                                
                            // time you need it, this is merely an example.
{
  if (pInfo[playerid][License])
  {
     return 1; // player has a license
  }
  return 0;
}
Thanks so In the place where You puted =Value I must put the value I set to it? So basicly 0
Reply
#10

Well, you're loading it from where you stored the original stats.

For simplicity: If this was an ini file, you'd load the value from the .ini - and that would be the value to verify that the player has a license or not.

Quote:

username.ini
[player]
Score=42
Money=2493239
License=1

This would be what you'd load from the .ini, if he has a license, value would set it to 1. otherwise it'd be 0.

This particular use makes it so that you don't have to load the value from the .ini every time you need it, speeding up your script in general a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)