[SOLVED] Problem with /stats, Money donґt save.
#1

Hello again,

This will be a difficult problem. But I hope anyone of you can resolv it. The problem is short but big. I canґt save the money from stats. When I disconnect the money wonґt save and in game the money donґt increase when I earn some. I know wait it donґt save but I canґt fix it ;( I need urgently help!

pawn Код:
enum PlayerData
{
    Registered,
    LoggedIn,
    AdminLevel,
    Password,
    Kills,
    Deaths,
    Money,
    PlayerIP
pawn Код:
public OnPlayerConnect(playerid)
{
            if(playerIP[50] == playerIp[49])
            {
              SendClientMessage(playerid, COLOR_GREEN, "You have been automatically logged in! Welcome back to the server.");
              PlayerInfo[playerid][Registered] = 1;
            PlayerInfo[playerid][LoggedIn] = 1;
            PlayerInfo[playerid][AdminLevel] = dini_Int(PlayerFile, "AdminLevel");
                PlayerInfo[playerid][Kills] = dini_Int(PlayerFile, "Kills");
                PlayerInfo[playerid][Deaths] = dini_Int(PlayerFile, "Deaths");
                PlayerInfo[playerid][Money] = dini_Int(PlayerFile, "Money");
            }
            else
            {
              PlayerInfo[playerid][Registered] = 1;
            PlayerInfo[playerid][LoggedIn] = 0;
            SendClientMessage(playerid, COLOR_GREEN," Since you are registered, please use /login to login onto your account.");
            }
pawn Код:
dcmd_login(playerid, params[])
{
    new pName[24], PlayerFile[50], Pass[256], plrIP[50];
    GetPlayerName(playerid, pName, sizeof(pName));
    format(PlayerFile, sizeof(PlayerFile), "/users/%s.ini", pName);

    if(PlayerInfo[playerid][LoggedIn] == 1) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You are already logged in!");
    if(PlayerInfo[playerid][Registered] == 0) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You are not registered! Use /register to register.");
    if(sscanf(params, "s", Pass)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "Usage: /login [password]");

    Pass = dini_Get(PlayerFile, "Password");

    if(!strcmp(MD5_Hash(params), Pass, true))
    {
        GetPlayerIp(playerid, plrIP, sizeof(plrIP));
      dini_Set(PlayerFile, "PlayerIP", plrIP);
        SendClientMessage(playerid, COLOR_GREEN, "You have been succesfully logged in");
        PlayerInfo[playerid][LoggedIn] = 1;
        PlayerInfo[playerid][AdminLevel] = dini_Int(PlayerFile, "AdminLevel");
        PlayerInfo[playerid][Kills] = dini_Int(PlayerFile, "Kills");
        PlayerInfo[playerid][Deaths] = dini_Int(PlayerFile, "Deaths");
        PlayerInfo[playerid][Money] = dini_Int(PlayerFile, "Money");
    }
    else
    {
pawn Код:
dcmd_stats(playerid, params[])
{
    new pName[24], PlayerFile[50], str[128], pDeaths[50], pKills[50], pMoney[50],targetid;

    if(!strlen(params)) targetid = playerid;
    else targetid = strval(params);
    GetPlayerName(targetid, pName, sizeof(pName));
    format(PlayerFile, sizeof(PlayerFile), "/users/%s.ini", pName);

    if(!dini_Exists(PlayerFile)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "Usage: /stats [ID].");

    if(dini_Exists(PlayerFile))
    {
        pDeaths[24] = dini_Int(PlayerFile, "Deaths");
        pKills[24] = dini_Int(PlayerFile, "Kills");
        pMoney[24] = dini_Int(PlayerFile, "Money");
        new Float:Ratio=floatdiv(pKills[24], pDeaths[24]);
        format(str, sizeof(str), "               ||%sґs Statistics ||", pName);
        SendClientMessage(playerid, COLOR_GREEN, str);
        format(str, sizeof(str), "(Money): Money: %d", pMoney[24]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
        format(str, sizeof(str), "(Stats): Kills: %d || Deaths: %d || Ratio: %.2f || Money: %d", pKills[24], pDeaths[24], Ratio, pMoney[24]);
        SendClientMessage(playerid, COLOR_YELLOW, str);
I know I must put something between OnPlayerDisconnect but I donґt know what and I donґt know really how to save money ;/

I would be grateful if someone help me ;(
Reply
#2

Код:
dini_IntSet(file,"money", GetPlayerMoney(playerid));
That would save the money.
Reply
#3

Thatґs look awesome

Put I donґt know where to put it in ;/

Reply
#4

Quote:
Originally Posted by Flashy
Thatґs look awesome

Put I donґt know where to put it in ;/

OnPlayerDisconnect

But edit "file" to PlayerFile or waht now you save in (:
Reply
#5

It doesnґt work
I try many things..I donґt get any erros and warnings but still it wonґt save.
And in game it donґt shows me the actual money

Need to fix that quickly D: Help
Reply
#6

edit your /login command to that and it will work :

Код:
dcmd_login(playerid, params[])
{
	new pName[24], PlayerFile[50], Pass[256], plrIP[50];
	GetPlayerName(playerid, pName, sizeof(pName));
 	format(PlayerFile, sizeof(PlayerFile), "/users/%s.ini", pName);

 	if(PlayerInfo[playerid][LoggedIn] == 1) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You are already logged in!");
 	if(PlayerInfo[playerid][Registered] == 0) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You are not registered! Use /register to register.");
	if(sscanf(params, "s", Pass)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "Usage: /login [password]");

	Pass = dini_Get(PlayerFile, "Password");

	if(!strcmp(MD5_Hash(params), Pass, true))
	{
		GetPlayerIp(playerid, plrIP, sizeof(plrIP));
	  dini_Set(PlayerFile, "PlayerIP", plrIP);
		SendClientMessage(playerid, COLOR_GREEN, "You have been succesfully logged in");
		PlayerInfo[playerid][LoggedIn] = 1;
		PlayerInfo[playerid][AdminLevel] = dini_Int(PlayerFile, "AdminLevel");
		PlayerInfo[playerid][Kills] = dini_Int(PlayerFile, "Kills");
		PlayerInfo[playerid][Deaths] = dini_Int(PlayerFile, "Deaths");
		SetPlayerMoney(playerid,dini_Int(PlayerFile, "Money"));
	}
 	else
	{
Reply
#7

Looks good but I get one error:

Adminscript.pwn(1679) : error 017: undefined symbol "SetPlayerMoney"

Your SetPlayerMoney istnґt definite and I am sure it wonґt save. Cause if you are already login this change nothing.
Okease someone must fix it D:
Reply
#8

SetPlayerMoney is not a native function
Use GivePlayerMoney instead.
Код:
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid,amount);
Or easier,let's define SetPlayerMoney :P
Код:
forward SetPlayerMoney(playerid,amount);
public SetPlayerMoney(playerid,amount)
{
  ResetPlayerMoney(playerid);
  GivePlayerMoney(playerid,amount);
  return 1;
}
Now you can use SetPlayerMoney.
Reply
#9

Before I try to put it in my script:
Why do you include "ResetPlayerMoney" in your script? I donґt want that my currently moeny will be reseted
Reply
#10

Update:

I fixed the problem that I can see my currently money in game.

Currently problems:

Canґt save the money I won in game automatically. How to fix that?
When I disconnect it donґt save my money. How to fix that?
When I connect there is only the money from my dini File. Example: IN my dini file is: Money=5353. Then it shows me in game I have 5353 but I won more? How to fix that?


[EDIT]

Solved by myself.

Note for further notice and for other palyer have the same problem:

Just write a public function:


pawn Код:
public OnPlayerUpdate(playerid)
{
        new PlayerFile[128];
        new uCash = GetPlayerMoney(playerid);
        new name[MAX_PLAYER_NAME];
        format(PlayerFile, sizeof(PlayerFile), "/users/%s.ini", name);
        dini_IntSet(file,"Money", uCash);

}

Thx to all who help me

Helpful topic: http://forum.sa-mp.com/index.php?top...563#msg1021563
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)