[y_ini] Interval Saving?
#1

Hey guys, I'm not sure if this is the right place to ask this but here goes. I am using y_ini to save player data, so now I was wondering...

With y_ini being fast at saving/loading data, should I make it so that it saves data on intervals? Like every 10 Seconds?

The reason I'm asking this is because I've noticed that in my "Unfinished" GameMode, when a player's game crashes for some reason, their data isn't saved.

If someone could answer this question or even give me a different way on saving data now and then I would be grateful.
Reply
#2

Interval saving is usual reserved for the 5 to 10 minute range. If your players aren't saving information when they crash then something is wrong. Most information should be server sided, so whether or not the player crashed shouldn't effect the outcome.
Reply
#3

You can also save certain data the moment it's changed. So like if you update the players weapons for example instead of storing it in an array like you might do you store it in the file aswell. (It's what I do with mySQL but that's threaded I doubt it'll cause a delay with y_ini though).
Reply
#4

Wow thanx for the advice, actually storing the data once it changes is a good idea, Thanx for the advice.
Reply
#5

That really isn't a good idea

When it comes to files, you can only save a single key by saving them all also. So if your money changes, you'll end up rewriting the whole file.

You should really determine what's causing the non-save issue on crashing as it shouldn't be a problem.
Reply
#6

Thanx for the reply. My code is cleaned up a bit, and it saves the players data only OnPlayerDisconnect, but for some reason not when they crash... Dont know why though, And me being the "Server Owner" My data doesn't save also. Any Ideas?
Reply
#7

Show the OnPlayerDisconnect.
Reply
#8

This is cleaned up code.

Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(fexist(Path(playerid)))
    {
        CallLocalFunction("SaveUser","playerid");
        return 1;
    }
    return 1;
}
It saves the data when I disconnect, but not when I crash. Oh and before you say that is my problem there, here is the old code I used.

Код:
public SaveUser(playerid)
{
	GetPlayerName(playerid, pInfo[playerid][UserName], MAX_PLAYER_NAME);
	GetPlayerPos(playerid, pInfo[playerid][PosX], pInfo[playerid][PosY], pInfo[playerid][PosZ]);
	GetPlayerFacingAngle(playerid,pInfo[playerid][Angle]);
	GetPlayerHealth(playerid, pInfo[playerid][Health]);
	GetPlayerArmour(playerid, pInfo[playerid][Armour]);

	new INI:file = INI_Open(Path(playerid));
	INI_SetTag(file,"Player's Data");
//==General_Info================================================================
    INI_WriteString(file,"UserName",pInfo[playerid][UserName]);
	INI_WriteInt(file,"AdminLevel",pInfo[playerid][AdminLevel]);
	INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);
	INI_WriteInt(file,"Level",GetPlayerScore(playerid));
	INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
	INI_WriteInt(file,"Wallet",pInfo[playerid][Wallet]);
	INI_WriteInt(file,"Bank",pInfo[playerid][Bank]);
	INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);
	INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);
	INI_WriteInt(file,"Jailed",pInfo[playerid][Jailed]);
	INI_WriteInt(file,"WantedLevel",pInfo[playerid][WantedLevel]);
	INI_WriteInt(file,"FightingStyle",pInfo[playerid][FightingStyle]);
	INI_WriteFloat(file,"Health",pInfo[playerid][Health]);
	INI_WriteFloat(file,"Armour",pInfo[playerid][Armour]);
//==Position_Interior_VirtualWorld_Skin=========================================
	INI_WriteInt(file,"Skin",GetPlayerSkin(playerid));
	INI_WriteInt(file,"VirtualWorld",GetPlayerVirtualWorld(playerid));
	INI_WriteInt(file,"Interior",GetPlayerInterior(playerid));
	INI_WriteFloat(file,"PosX",pInfo[playerid][PosX]);
	INI_WriteFloat(file,"PosY",pInfo[playerid][PosY]);
	INI_WriteFloat(file,"PosZ",pInfo[playerid][PosZ]);
	INI_WriteFloat(file,"Angle",pInfo[playerid][Angle]);
//==Items=======================================================================
	INI_WriteInt(file,"Materials",pInfo[playerid][Materials]);
	INI_WriteInt(file,"Marijuana",pInfo[playerid][Marijuana]);
	INI_WriteInt(file,"Cocaine",pInfo[playerid][Cocaine]);
	INI_Close(file);
	SendClientMessage(playerid,COLOR_PURPLE,"Player Info Saved");
    return 1;
}
PS: The code above is the code that was OnPlayerDisconnect, now I cleaned it up by putting it in a function as I am using it in a lot of places(to save the data when it changes).
Reply
#9

Can anyone help me here, I'm not sure what i'm doing wrong here. Please, its getting annoying and I cant save all the data over and over again unless I can change only one line in the .ini file, and AFAIK its not possible with y_ini(please note that i'm still new to pawn coding so I'm not sure if it is the case).

Please, I need help to figure this problem out.
Reply
#10

Never mind,I figured the problem out...

Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(fexist(Path(playerid)))
    {
        CallLocalFunction("SaveUser","playerid");
        return 1;
    }
    return 1;
}
Had to be...

Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(fexist(Path(playerid)))
    {
        CallLocalFunction("SaveUser","playerid");
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)