How do I create player stats?
#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


Messages In This Thread
How do I create player stats? - by Gabriel1337 - 23.05.2013, 10:39
Re: How do I create player stats? - by Revo - 23.05.2013, 10:41
Re: How do I create player stats? - by Gabriel1337 - 23.05.2013, 10:41
Re: How do I create player stats? - by Revo - 23.05.2013, 10:45
Re: How do I create player stats? - by Gabriel1337 - 23.05.2013, 10:57
Re: How do I create player stats? - by Revo - 23.05.2013, 10:59
Re: How do I create player stats? - by Gabriel1337 - 23.05.2013, 11:02
Re: How do I create player stats? - by Revo - 23.05.2013, 11:07
Re: How do I create player stats? - by Gabriel1337 - 23.05.2013, 11:13
Re: How do I create player stats? - by Revo - 23.05.2013, 11:16

Forum Jump:


Users browsing this thread: 1 Guest(s)