Save stats
#1

Hi. I searched the internet and tried to do a system register / login dini. I set the register to receive level 1 and $ 20,000 cash. After relog not saved anything, Level 0, Money 0. I looked everywhere, I tried all sorts of ways but no result.

This is the sistem:


Код HTML:
enum pInfo
{
 	Pass,
	Level,
	Money,
	Adminlevel,
	AdminDuty,
	VIPlevel,
	Kills,
	Deaths,
	Jailed,
};
Код HTML:
public OnPlayerRequestClass(playerid, classid)
{
    SpawnPlayer(playerid);
	ShowPlayerDialog(playerid,1234, DIALOG_STYLE_MSGBOX,""GREEN"Reguli",""ALB"Nu folosi un limbaj vulgar!\n"ALB"Nu face reclama altor servere\n"ALB"Nu iti da id-ul pe chat","Accept","Refuz");
	return 1;
}
Код HTML:
public OnPlayerConnect(playerid)
{
    new string[128];
    new plname[MAX_PLAYER_NAME];
   	GetPlayerName(playerid, plname, sizeof(plname));
	PlayerInfo[playerid][Level] = 0;
	PlayerInfo[playerid][Money] = 0;
	PlayerInfo[playerid][Adminlevel] = 0;
	PlayerInfo[playerid][VIPlevel] = 0;
	PlayerInfo[playerid][Kills] = 0;
	PlayerInfo[playerid][Deaths] = 0;
    format(string, sizeof(string), "%s.ini", plname);
    if(dini_Exists(string))
	{
		gPlayerAccount[playerid] = 1;
	}
	else
	{
		gPlayerAccount[playerid] = 0;
	}
Код HTML:
public OnPlayerRegister(playerid, password[]) // [] isn't needed as the password is a integer (whole number)
{
    if(IsPlayerConnected(playerid))
    {
        new file[64];
        new playername3[MAX_PLAYER_NAME];
        GetPlayerName(playerid, playername3, sizeof(playername3));
        format(file, sizeof(file), "%s.ini", playername3);

        if(dini_Exists(file))
        {
            return SendClientMessage(playerid,COLOR_GREY,"This account is already registered.");
        }
        else
        {
            dini_Create(file);
            new password2 = num_hash(password);
            PlayerInfo[playerid][Pass] = password2;
            dini_IntSet(file, "Password",password2);
            dini_IntSet(file, "Level",PlayerInfo[playerid][Level]);
            dini_IntSet(file, "Money",PlayerInfo[playerid][Money]);
            dini_IntSet(file, "Adminlevel",PlayerInfo[playerid][Adminlevel]);
            dini_IntSet(file, "AdminDuty",PlayerInfo[playerid][AdminDuty]);
            dini_IntSet(file, "VIPlevel",PlayerInfo[playerid][VIPlevel]);
            dini_IntSet(file, "Kills",PlayerInfo[playerid][Kills]);
            dini_IntSet(file, "Deaths",PlayerInfo[playerid][Deaths]);
            dini_IntSet(file, "Jailed",PlayerInfo[playerid][Jailed]);
            ShowPlayerDialog(playerid, 1245, DIALOG_STYLE_INPUT,""ALB"Bun Venit",""ALB"Cont inregistrat cu succes!\n"ALB"Scrie parola ta mai jos pentru a te loga","Log-in","Quit");
        }
    }
    return 1;
}
Код HTML:
public OnPlayerUpdate(playerid)
{
 	if(IsPlayerConnected(playerid))
	{
	    if(gPlayerLogged[playerid] == 1)
	    {
			new string3[64];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "%s.ini", playername3);
			dini_IntSet(string3, "Password",PlayerInfo[playerid][Pass]);
			dini_IntSet(string3, "Level",PlayerInfo[playerid][Level]);
			dini_IntSet(string3, "Money",PlayerInfo[playerid][Money]);
			dini_IntSet(string3, "Adminlevel",PlayerInfo[playerid][Adminlevel]);
			dini_IntSet(string3, "AdminDuty",PlayerInfo[playerid][AdminDuty]);
            dini_IntSet(string3, "VIPlevel",PlayerInfo[playerid][VIPlevel]);
            dini_IntSet(string3, "Kills",PlayerInfo[playerid][Kills]);
            dini_IntSet(string3, "Deaths",PlayerInfo[playerid][Deaths]);
            dini_IntSet(string3, "Jailed",PlayerInfo[playerid][Jailed]);
		}
	}
	return 1;
}
Код HTML:
public OnPlayerLogin(playerid,password[])
{
    SetPlayerColor(playerid, 0xFFFFFFAA);
    SetTimerEx( "SpawnInfo", 200, false, "i", playerid );
	new	string2[64];
	new	playername3[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playername3, sizeof(playername3));

	format(string2, sizeof(string2), "%s.ini", playername3);

	if (dini_Exists(string2))
	{
	    new password2 = num_hash(password);
 		if(dini_Int(string2,"Password") == password2)
		{
		    PlayerInfo[playerid][Pass] = dini_Int(string2,"Password");
		    PlayerInfo[playerid][Level] = dini_Int(string2,"Level");
			PlayerInfo[playerid][Money] = dini_Int(string2,"Money");
			PlayerInfo[playerid][Adminlevel] = dini_Int(string2,"Adminlevel");
			PlayerInfo[playerid][AdminDuty] = dini_Int(string2,"AdminDuty");
			PlayerInfo[playerid][VIPlevel] = dini_Int(string2,"VIPlevel");
			PlayerInfo[playerid][Kills] = dini_Int(string2,"Kills");
			PlayerInfo[playerid][Deaths] = dini_Int(string2,"Deaths");
			PlayerInfo[playerid][Jailed] = dini_Int(string2,"Jailed");
		}
		else
		{
	        gPlayerLogTries[playerid] += 1;
	        ShowPlayerDialog(playerid, 1245, DIALOG_STYLE_INPUT,""ALB"Mai incearca!",""ALB"Ai introdus o parola gresita\n"ALB"Scrie-ti parola pentru a te loga!","Log-in","Quit");
	        if(gPlayerLogTries[playerid] == 3) { Kick(playerid); }
	        return 1;
		}
    }
	return 1;
}
Код HTML:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 1234)
	{
		if(response)
	    {
	        new playername[MAX_PLAYER_NAME];
	        GetPlayerName(playerid, playername, sizeof(playername));
	        new string[64];
	        format(string, sizeof(string), "%s.ini", playername);
			if (dini_Exists(string))
			{
				ShowPlayerDialog(playerid, 1245, DIALOG_STYLE_INPUT,""ALB"Bun venit. Te rugam sa te loghezi.",""ALB"Scrie parola ta aici pentru a te loga","Log-in","Quit");
			}
			else
			{
				ShowPlayerDialog(playerid, 1246, DIALOG_STYLE_INPUT,""ALB"Te rugam sa te inregistrezi!",""ALB"Scrie parola ta aici pentru a te inregistra.","Register","Quit");
			}
		}
		else
		{
		    SendClientMessage(playerid, COLOR_GREY,"*Ai refuzat. Trebuie sa accepti regulile pentru a juca");
			Kick(playerid);
		}
	}
	if(dialogid == 1245)
	{
	    if(response)
	    {
	        strmid(Typed[playerid], inputtext, 0, strlen(inputtext), 255);
         	if(!strcmp(Typed[playerid], "None", true))
			{
				ShowPlayerDialog(playerid, 1245, DIALOG_STYLE_INPUT,""ALB"Incerca din nou.",""ALB"Nu ai introdus o parola!\n"ALB"Scrie-ti parola mai jos pentru a te inregistra","Log-in","Quit");
		  	}
		  	else
		  	{
	        	OnPlayerLogin(playerid, inputtext);
			}
		}
		else
		{
		    Kick(playerid);
		}
	}
	if(dialogid == 1246)
	{
	    if(response == 1)
	    {
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new string[512];
	        format(string, sizeof(string),""ALB"Nume: "LIGHTBLUE"%s\n"ALB"Parola: "LIGHTBLUE"%s,\n"ALB"Bani: "LIGHTBLUE"10000\n"ALB"Scor: "LIGHTBLUE"1",sendername,inputtext);
	        ShowPlayerDialog(playerid, 1242, DIALOG_STYLE_MSGBOX, ""LIGHTBLUE"Te-ai inregistrat cu succes",string,"Ok","");
	        GivePlayerMoney(playerid, 20000);
	        SetPlayerScore(playerid, 1);
	        OnPlayerRegister(playerid, inputtext);
   		}
		else
		{
		    Kick(playerid);
		}
	}
Reply
#2

Saving under OnPlayerUpdate is not a wise option, especially with dini...
Reply
#3

and what should I do?
Reply
#4

Use y_ini, it's much easier and efficient.
Again, I definitely would not use OnPlayerUpdate to save stats, you can either save once when they disconnect, or save multiple times on a timer. (Not 1 second timers and stuff like that...)
Reply
#5

Yeah, every 5 minutes would be okay.
Reply
#6

The issue is you're setting the variables (on saving) to the variables of PlayerInfo[playerid][Money] (which is reset to 0 on OnPlayerConnect), but I don't think you're changing the variables e.g under GivePlayerMoney.
Reply
#7

I tried to put this timer at public OnGameModeInit

Код HTML:
SetTimer("OnPlayerUpdate",60000,1);
and at public OnPlayerDisconnect I write that:

Код HTML:
OnPlayerUpdate(playerid);
But I have not done anything


I tried and y_ini but don't show login after register dialog. This is only one who work.
P.S: Sorry but I'm beginner
Reply
#8

up...
Reply
#9

I have those under OnPlayerDisconnect
Reply
#10

Quote:
Originally Posted by Hade.
Посмотреть сообщение
I have those under OnPlayerDisconnect
You're right, those should be made into a separate function and saved upon OnPlayerDisconnect or on a reasonable timer. However, the issue with your script is that (as far as I can see through the code you posted), you're not actually assigning the variables [Money] any variable, so when it saves, it's just saving 0. Try editing the file and setting money to a different number and seeing if it resets to 0.

Also OnPlayerUpdate doesn't need to be ran in a timer.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)