[HELP] HOW TO FIX THIS, ?Easy?
#1

Код:
if(listitem == 0) //Smoke
if(GetPlayerMoney(playerid) >= 45) 
{
GivePlayerMoney(playerid, -45);
PlayerInfo[playerid][pCiggy] = 30;
SendClientMessage(playerid, VALGE, "Vihje: /smoke");
_________________________________________
Problem:
and i do /stats then there is Smokes[30]
but when i restart server then there is Smokes[0]
IT DOESNT SAVE, whats the problem?
_________________________________________


i have this under my enum pinfo
Код:
pCiggy
i have this under my onplayerregister
Код:
format(var, 32, "Smokes=%d\n",PlayerInfo[playerid][pCiggy]);fwrite(hFile, var);
i have this under my onplayerlogin
Код:
if( strcmp( key , "Smokes" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCiggy] = strval( val ); }

and thats all if you know the problem please help me



Heres my Onplayerlogin and onplayerregister


Код:
public OnPlayerLogin(playerid,password[])
{
  new string2[256];
	new playername2[MAX_PLAYER_NAME];
  GetPlayerName(playerid, playername2, sizeof(playername2));
	format(string2, sizeof(string2), "cServer/kasutajad/%s.ini", playername2);
	new File: UserFile = fopen(string2, io_read);
	if ( UserFile )
	{
	  new PassData[256];
	  new keytmp[256], valtmp[256];
	  fread( UserFile , PassData , sizeof( PassData ) );
	  keytmp = ini_GetKey( PassData );
	  if( strcmp( keytmp , "Password" , true ) == 0 )
		{
			valtmp = ini_GetValue( PassData );
			strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
		}
		if(strcmp(PlayerInfo[playerid][pPassword],password, true ) == 0 )
		{
			  new key[ 256 ] , val[ 256 ];
			  new Data[ 256 ];
			  while ( fread( UserFile , Data , sizeof( Data ) ) )
				{
					key = ini_GetKey( Data );
			  	if( strcmp( key , "AdminLevel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
			  	if( strcmp( key , "Warnings" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pWarns] = strval( val ); }
			  	if( strcmp( key , "Level" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pLevel] = strval( val ); }
			    if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); }
			    if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); }
			    if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
			    if( strcmp( key , "Bank" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pBank] = strval( val ); }
			    if( strcmp( key , "Skin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pSkin] = strval( val ); }
			    if( strcmp( key , "TimesConnected" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pTimes] = strval( val ); }
			    if( strcmp( key , "PlayingHours" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pHours] = strval( val ); }
			    if( strcmp( key , "PlayingMinutes" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pMins] = strval( val ); }
			    if( strcmp( key , "JailTime" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pJailTime] = strval( val ); }
			    if( strcmp( key , "DayRegistered" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDate1] = strval( val ); }
			    if( strcmp( key , "MonthRegistered" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDate2] = strval( val ); }
			    if( strcmp( key , "YearRegistered" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDate3] = strval( val ); }
			    if( strcmp( key , "Smokes" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCiggy] = strval( val ); }
			    }//end while
     		fclose(UserFile);//close the file after everything has been read in the while
		}
		else
		{
			SendClientMessage(playerid, VALGE, "[Vale Salasхna, 3 korda = ban]");
	    fclose(UserFile);
	    gPlayerLogTries[playerid] += 1;
	    if(gPlayerLogTries[playerid] == 3) { Ban(playerid); }
	    return 1;
		}
		if(PlayerInfo[playerid][pLevel] == -1)
		{
	  	SendClientMessage(playerid, PUNANE, "See kasutaja on bannitud!");
	  	Kick(playerid);
	  	return 1;
	 	}
	 	else if(PlayerInfo[playerid][pLevel] == -2)
		{
	  	Ban(playerid);
	  	return 1;
	 	}
	 	PlaySound(playerid, 1054);
		ResetPlayerMoney(playerid);
		gPlayerLogged[playerid] = 1;
		ConsumingMoney[playerid] = 1;
		PlayerInfo[playerid][pTimes] ++;
		printf("%s Logis Sisse",playername2);
		SendClientMessage(playerid, ROHELINE,"[Sisse Logitud]");
		SetTimerEx("PlayingTime", 60000, 1, "i", playerid);
	}
	return 1;
}
Код:
public OnPlayerRegister(playerid, password[])
{
	if(IsPlayerConnected(playerid))
	{
			new string3[256];
			new string[256];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "cServer/kasutajad/%s.ini", playername3);
			new File: hFile = fopen(string3, io_write);
 			if (hFile)
			{
			  new pIp[128];
			  GetPlayerIp(playerid, pIp, sizeof(pIp));
			  new var[32];
			  strmid(PlayerInfo[playerid][pPassword], password, 0, strlen(password), 255);
				format(var, 32, "Password=%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
				PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
				format(var, 32, "IP=%s\n", pIp);fwrite(hFile, var);
				format(var, 32, "AdminLevel=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
				format(var, 32, "Warnings=%d\n",PlayerInfo[playerid][pWarns]);fwrite(hFile, var);
				format(var, 32, "Level=%d\n",PlayerInfo[playerid][pLevel]);fwrite(hFile, var);
				format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
				format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
				format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
				format(var, 32, "Bank=%d\n",PlayerInfo[playerid][pBank]);fwrite(hFile, var);
				format(var, 32, "Skin=%d\n",PlayerInfo[playerid][pSkin]);fwrite(hFile, var);
				format(var, 32, "TimesConnected=%d\n",PlayerInfo[playerid][pTimes]);fwrite(hFile, var);
				format(var, 32, "PlayingHours=%d\n",PlayerInfo[playerid][pHours]);fwrite(hFile, var);
				format(var, 32, "PlayingMinutes=%d\n",PlayerInfo[playerid][pMins]);fwrite(hFile, var);
				format(var, 32, "JailTime=%d\n",PlayerInfo[playerid][pJailTime]);fwrite(hFile, var);
				format(var, 32, "Smokes=%d\n",PlayerInfo[playerid][pCiggy]);fwrite(hFile, var);
				new year,month,day;
				getdate(year,month,day);
        PlayerInfo[playerid][pDate1] = day;
        PlayerInfo[playerid][pDate2] = month;
        PlayerInfo[playerid][pDate3] = year;
        format(var, 32, "DayRegistered=%d\n",PlayerInfo[playerid][pDate1]);fwrite(hFile, var);
        format(var, 32, "MonthRegistered=%d\n",PlayerInfo[playerid][pDate2]);fwrite(hFile, var);
        format(var, 32, "YearRegistered=%d\n",PlayerInfo[playerid][pDate3]);fwrite(hFile, var);
				fclose(hFile);
				format(string, sizeof(string), "Kasutaja %s Registreeritud, /login [salasхna]", playername3);
				SendClientMessage(playerid, ROHELINE, string);
			}
	}
	return 1;
}
Reply
#2

You don't have anything under the updating section of the script, assuming its a godfather script, the function used to be OnPlayerUpdate, however it was renamed when 0.2X came out.

This same line

pawn Код:
format(var, 32, "Smokes=%d\n",PlayerInfo[playerid][pCiggy]);fwrite(hFile, var);
will no doubt need to go in there for it to save.



In Future, this should go in the gamemodes thread.
Reply
#3

its blank gamemode
Reply
#4

But where and how do you save it? :P Do you have some kind of function that will save the players account when they disconnect? :P
Reply
#5

You definitely don't want to go for the suggestion of putting it under OnPlayerUpdate.

If you want your stuff to be saved when you restart the server e.g. just loop through OnPlayerDisconnect with all logged in playerids (I assume you save each player's stuff in there).
Reply
#6

Damnit wrong topic.

Seems to me you don't save it in your account.
Reply
#7

where should i create saving? onplayerdisconnect?

i created this system from blank well yeh il try then
Reply
#8

Well, saving it upon OnPlayerDisconnect is obviously the first step. I assumed you already did that.
Reply
#9

I have finished it, and i have tested it works like a charm

Код:
public OnPlayerDisconnect(playerid, reason)
{
  		new string3[256];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "cServer/kasutajad/%s.ini", playername3);
			new File: hFile = fopen(string3, io_write);
 			if (hFile)
			{
			  new pIp[128];
			  GetPlayerIp(playerid, pIp, sizeof(pIp));
			  new var[32];
				PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
				format(var, 32, "IP=%s\n", pIp);fwrite(hFile, var);
				format(var, 32, "AdminLevel=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
				format(var, 32, "Warnings=%d\n",PlayerInfo[playerid][pWarns]);fwrite(hFile, var);
				format(var, 32, "Level=%d\n",PlayerInfo[playerid][pLevel]);fwrite(hFile, var);
				format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
				format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
				format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
				format(var, 32, "Bank=%d\n",PlayerInfo[playerid][pBank]);fwrite(hFile, var);
				format(var, 32, "Skin=%d\n",PlayerInfo[playerid][pSkin]);fwrite(hFile, var);
				format(var, 32, "TimesConnected=%d\n",PlayerInfo[playerid][pTimes]);fwrite(hFile, var);
				format(var, 32, "PlayingHours=%d\n",PlayerInfo[playerid][pHours]);fwrite(hFile, var);
				format(var, 32, "PlayingMinutes=%d\n",PlayerInfo[playerid][pMins]);fwrite(hFile, var);
				format(var, 32, "JailTime=%d\n",PlayerInfo[playerid][pJailTime]);fwrite(hFile, var);
				format(var, 32, "Suitsud=%d\n",PlayerInfo[playerid][pSuitsud]);fwrite(hFile, var);
				new year,month,day;
				getdate(year,month,day);
        PlayerInfo[playerid][pDate1] = day;
        PlayerInfo[playerid][pDate2] = month;
        PlayerInfo[playerid][pDate3] = year;
        format(var, 32, "DayRegistered=%d\n",PlayerInfo[playerid][pDate1]);fwrite(hFile, var);
        format(var, 32, "MonthRegistered=%d\n",PlayerInfo[playerid][pDate2]);fwrite(hFile, var);
        format(var, 32, "YearRegistered=%d\n",PlayerInfo[playerid][pDate3]);fwrite(hFile, var);
        gPlayerLogged[playerid] = 0;
				fclose(hFile);
				}
  			return 1;
			}
Finally i have created my own login and register system whats working correctly
Reply
#10

Quote:
Originally Posted by juice.j
You definitely don't want to go for the suggestion of putting it under OnPlayerUpdate.

If you want your stuff to be saved when you restart the server e.g. just loop through OnPlayerDisconnect with all logged in playerids (I assume you save each player's stuff in there).
If you read what I said, I said that if it were the godfather script, the update function was (Past Tense) called OnPlayerUpdate. I would not recommend anyone put file saving under OnPlayerUpdate....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)