Why new users get stats of other players?(ini)
#1

Heey guys,
i made a save system with ini.
But when a new player register he gets stats of other existed player who is not online(deaths and kills etc.):S.
Codes:
Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pScore,
    pCaptures,
   	God,
   	GodCar,
   	banned,
   	Warnings,
   	pPlayersloggedin,
   	pPlayersregistered

}

public LoadUser_AccountData(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Banned",PlayerInfo[playerid][banned]);
    INI_Int("Warnings",PlayerInfo[playerid][Warnings]);
	INI_Int("Cash",PlayerInfo[playerid][pCash]);
    //INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    PlayerInfo[playerid][pAdmin]=0;
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Score",PlayerInfo[playerid][pScore]);
    INI_Int("Captures",PlayerInfo[playerid][pCaptures]);
    INI_Int("Rank",ranklvl[playerid]);
    INI_Int("PlayersLoggedIn",PlayerInfo[playerid][pPlayersloggedin]);
    INI_Int("PlayersRegistered",PlayerInfo[playerid][pPlayersregistered]);
    return 1;
}
Код:
//onplayerdisconnect
INI_WriteString(File,"Name",name);
	INI_WriteString(File,"Ip",plrIP);
 	INI_WriteInt(File,"Registered",fexist(UserPath(playerid)));
    INI_WriteInt(File,"LoggedIn",IsPlayerConnected(playerid));
    INI_WriteInt(File,"LoggedIn",0);
    INI_WriteInt(File,"Warnings",PlayerInfo[playerid][Warnings]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][banned]);
	INI_WriteInt(File,"Ping",GetPlayerPing(playerid));
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",0);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Rank",ranklvl[playerid]);
    INI_WriteInt(File,"Captures",capturedzones[playerid]);
    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
    INI_WriteInt(File,"PlayersRegistered",playersregistered);
Код:
//onplayerupdate
INI_WriteString(File,"Name",name);
      		INI_WriteInt(File,"Registered",fexist(UserPath(playerid)));
    		INI_WriteInt(File,"LoggedIn",IsPlayerConnected(playerid));
		    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
			INI_WriteInt(File,"PlayersRegistered",playersregistered);
			INI_WriteInt(File,"Ping",GetPlayerPing(playerid));
			new plrIP[16];
			GetPlayerIp(playerid, plrIP, sizeof(plrIP));
			INI_WriteString(File,"Ip",plrIP);
		    //INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
		    //INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
		    //INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
		    //INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
		    //INI_WriteInt(File,"Score",GetPlayerScore(playerid));
      		INI_WriteInt(File,"Rank",ranklvl[playerid]);
		    INI_WriteInt(File,"Captures",capturedzones[playerid]);
Код:
//and the last one is the register(dialog)
INI_WriteString(File,"Name",name);
				INI_WriteInt(File,"Password",udb_hash(inputtext));
				INI_WriteString(File,"Ip",plrIP);
 				INI_WriteInt(File,"Registered",1);
  				INI_WriteInt(File,"LoggedIn",1);
		    	INI_WriteInt(File,"Banned",0);
    			INI_WriteInt(File,"Ping",0);
			    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
    			INI_WriteInt(File,"PlayersRegistered",playersregistered);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Score",0);
                INI_WriteInt(File,"Rank",0);
    			INI_WriteInt(File,"Captures",0);
Anyone can help me pls. I really need it.
Reply
#2

Firstly, why are you saving upon disconnect and through the update function?

Also, explain a little more.
Reply
#3

I just added the code because i followed u guide:P
just if new player register they get kills and deaths of someone else who is offline.
Reply
#4

Show the Full OnPlayerDisconnect and OnPlayerRegister code.
Reply
#5

Код:
//dialog of register
case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                new plrIP[16];
				GetPlayerIp(playerid, plrIP, sizeof(plrIP));
				new name[MAX_PLAYER_NAME];
    			GetPlayerName(playerid, name, sizeof(name));
                INI_SetTag(File,"AccountData");
                INI_WriteString(File,"Name",name);
				INI_WriteInt(File,"Password",udb_hash(inputtext));
				INI_WriteString(File,"Ip",plrIP);
 				INI_WriteInt(File,"Registered",1);
  				INI_WriteInt(File,"LoggedIn",1);
		    	INI_WriteInt(File,"Banned",0);
    			INI_WriteInt(File,"Ping",0);
			    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
    			INI_WriteInt(File,"PlayersRegistered",playersregistered);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Score",0);
                INI_WriteInt(File,"Rank",0);
    			INI_WriteInt(File,"Captures",0);
    			PlayerInfo[playerid][pPlayersregistered]++;
                INI_Close(File);

                //new listitems1[] = "{FFFF00}Europe Alliance:0{FFFF00}\n{33CCFF}United States Of America:0{33CCFF}\n{00FF00}Sovjet Union:0{00FF00}\n{660000}Japan:0{660000}\n{FF8040}Asian Empire:0{FF8040}\n{FF00FF}Russia:0{FF00FF}\n{800080}Australiл:0{800080}\n{FFFFFF}Afghanistan:0{FFFFFF}";
				//ShowPlayerDialog(playerid,3,DIALOG_STYLE_LIST,"**Select Your Team!**:",listitems1,"Select","");
				//SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                //SpawnPlayer(playerid);
                //ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
			}
        }
Код:
//onplayerdisconnect
public OnPlayerDisconnect(playerid, reason)
{
	new
        string[64],
        name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    switch(reason)
    {
        case 0: format(string,sizeof string,"%s left the server. (Timed out)",name);
        case 1: format(string,sizeof string,"%s left the server. (Leaving)",name);
        case 2: format(string,sizeof string,"%s left the server. (Kicked/Banned)",name);
    }
    pCount[playerid] = 0;
    playersloggedin--;
    SendClientMessageToAll(COLOR_GREY,string);
	new INI:File = INI_Open(UserPath(playerid));
	new plrIP[16];
    INI_SetTag(File,"AccountData");
    SetTimerEx("CheckSpawnPosition", 8000, false, "i", playerid); //time is in milliseconds (8000 Milliseconds = 8 Seconds)
	GetPlayerName(playerid, name, sizeof(name));
  	INI_WriteString(File,"Name",name);
	INI_WriteString(File,"Ip",plrIP);
 	INI_WriteInt(File,"Registered",fexist(UserPath(playerid)));
    INI_WriteInt(File,"LoggedIn",IsPlayerConnected(playerid));
    INI_WriteInt(File,"LoggedIn",0);
    INI_WriteInt(File,"Warnings",PlayerInfo[playerid][Warnings]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][banned]);
	INI_WriteInt(File,"Ping",GetPlayerPing(playerid));
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",0);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Rank",ranklvl[playerid]);
    INI_WriteInt(File,"Captures",capturedzones[playerid]);
    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
    INI_WriteInt(File,"PlayersRegistered",playersregistered);
	Delete3DTextLabel(label[playerid]);
	GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    INI_Close(File);
	return 1;
}
Reply
#6

Quote:
Originally Posted by admigo
Посмотреть сообщение
Код:
//dialog of register
case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                new plrIP[16];
				GetPlayerIp(playerid, plrIP, sizeof(plrIP));
				new name[MAX_PLAYER_NAME];
    			GetPlayerName(playerid, name, sizeof(name));
                INI_SetTag(File,"AccountData");
                INI_WriteString(File,"Name",name);
				INI_WriteInt(File,"Password",udb_hash(inputtext));
				INI_WriteString(File,"Ip",plrIP);
 				INI_WriteInt(File,"Registered",1);
  				INI_WriteInt(File,"LoggedIn",1);
		    	INI_WriteInt(File,"Banned",0);
    			INI_WriteInt(File,"Ping",0);
			    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
    			INI_WriteInt(File,"PlayersRegistered",playersregistered);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Score",0);
                INI_WriteInt(File,"Rank",0);
    			INI_WriteInt(File,"Captures",0);
    			PlayerInfo[playerid][pPlayersregistered]++;
                INI_Close(File);

                //new listitems1[] = "{FFFF00}Europe Alliance:0{FFFF00}\n{33CCFF}United States Of America:0{33CCFF}\n{00FF00}Sovjet Union:0{00FF00}\n{660000}Japan:0{660000}\n{FF8040}Asian Empire:0{FF8040}\n{FF00FF}Russia:0{FF00FF}\n{800080}Australiл:0{800080}\n{FFFFFF}Afghanistan:0{FFFFFF}";
				//ShowPlayerDialog(playerid,3,DIALOG_STYLE_LIST,"**Select Your Team!**:",listitems1,"Select","");
				//SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                //SpawnPlayer(playerid);
                //ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
			}
        }
Код:
//onplayerdisconnect
public OnPlayerDisconnect(playerid, reason)
{
	new
        string[64],
        name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    switch(reason)
    {
        case 0: format(string,sizeof string,"%s left the server. (Timed out)",name);
        case 1: format(string,sizeof string,"%s left the server. (Leaving)",name);
        case 2: format(string,sizeof string,"%s left the server. (Kicked/Banned)",name);
    }
    pCount[playerid] = 0;
    playersloggedin--;
    SendClientMessageToAll(COLOR_GREY,string);
	new INI:File = INI_Open(UserPath(playerid));
	new plrIP[16];
    INI_SetTag(File,"AccountData");
    SetTimerEx("CheckSpawnPosition", 8000, false, "i", playerid); //time is in milliseconds (8000 Milliseconds = 8 Seconds)
	GetPlayerName(playerid, name, sizeof(name));
  	INI_WriteString(File,"Name",name);
	INI_WriteString(File,"Ip",plrIP);
 	INI_WriteInt(File,"Registered",fexist(UserPath(playerid)));
    INI_WriteInt(File,"LoggedIn",IsPlayerConnected(playerid));
    INI_WriteInt(File,"LoggedIn",0);
    INI_WriteInt(File,"Warnings",PlayerInfo[playerid][Warnings]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][banned]);
	INI_WriteInt(File,"Ping",GetPlayerPing(playerid));
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",0);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Rank",ranklvl[playerid]);
    INI_WriteInt(File,"Captures",capturedzones[playerid]);
    INI_WriteInt(File,"PlayersLoggedIn",playersloggedin);
    INI_WriteInt(File,"PlayersRegistered",playersregistered);
	Delete3DTextLabel(label[playerid]);
	GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    INI_Close(File);
	return 1;
}
I've seperated you code. 'playersloggedin and playersregistered' explain to me what they are.

Try defining everything other than what your writing outside of the code (though i doubt it will affect it), it just seems to be neater in particular.

Other than that, nothing seems to be wrong.
Reply
#7

Just a code if the player is logged in in game and is registered.
Can you help me to fix this pls?
Reply
#8

As server doesn't restart, and when a player joins, he/she takes the first available id in order, the variables of that id still have the value set before for the first id user, so all you have to make is, when player connects, it sets all values to the default, for example:

pawn Код:
public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pKills] = 0; // As for integers.
    PlayerInfo[playerid][Coordinate] = 0.0; // As for floats.
    format(PlayerInfo[playerid][BanMSG], sizeof(PlayerInfo[playerid][BanMSG]),"Not banned."); // As for strings.
}
You will also have the variables sets to the default as you make the variable's value 0, 0.0 or "None", depending on the variable type and the default value of the variable.
Reply
#9

Quote:
Originally Posted by Randy More
Посмотреть сообщение
As server doesn't restart, and when a player joins, he/she takes the first available id in order, the variables of that id still have the value set before for the first id user, so all you have to make is, when player connects, it sets all values to the default, for example:

pawn Код:
public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pKills] = 0; // As for integers.
    PlayerInfo[playerid][Coordinate] = 0.0; // As for floats.
    format(PlayerInfo[playerid][BanMSG], sizeof(PlayerInfo[playerid][BanMSG]),"Not banned."); // As for strings.
}
You will also have the variables sets to the default as you make the variable's value 0, 0.0 or "None", depending on the variable type and the default value of the variable.
BUMP - This solution doesnt work ... :/
It's very annoying that when someone dissconect, the next player connect get the previous players stats.
ANYONE? Please...
Reply
#10

I had an issue similar to this. You didn't post it so I'm not sure how the code looks.

But the issue I had was fixed by making it when the player connects it sets all of their stats to 0 BEFORE you load and set the stats you have saved. I'll explain further when I get home if you don't get what I am saying.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)