Y_INI - Save on change
#1

So I tried to make it so whenever you get a status update it'll automatically change aka a saving system. It does save when you relog but it does not when you restart the server.

Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Admin Level", PlayerInfo[playerid][pAdmin]);
    INI_Int("Faction Director", PlayerInfo[playerid][pFacDirector]);
    INI_Int("Faction", PlayerInfo[playerid][pFaction]);
    INI_Int("Faction Rank", PlayerInfo[playerid][pFacRanks]);
    
    return 1;
}
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
hook OnGameModeInit(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "/PlayerData/%s.ini", .bExtra = true, .extra = playerid);
    }
    return 1;
}
hook OnPlayerUpdate(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");

    INI_WriteInt(File,"Admin Level", PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Faction Director", PlayerInfo[playerid][pFacDirector]);
    INI_WriteInt(File,"Faction", PlayerInfo[playerid][pFaction]);
    INI_WriteInt(File,"Faction Rank", PlayerInfo[playerid][pFacRanks]);

    INI_Close(File);

    return 1;
}
Reply
#2

You have to save the player's data before restarting the server. Also, you shouldn't use OnPlayerUpdate to save player's data.
Reply
#3

Quote:
Originally Posted by oMa37
Посмотреть сообщение
You have to save the player's data before restarting the server. Also, you shouldn't use OnPlayerUpdate to save player's data.
Yes, well, that's why I'm here. How?

I made a gmx command since the one through rcon is too fast and it won't give the time for the system to properly save the player data.
Reply
#4

Create a timer.
Reply
#5

Try with this:

Код:
new AccTimer; // Defines the timer

forward SaveAccounts();
public SaveAccounts()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
	    new INI:File = INI_Open(UserPath(i));
	    INI_SetTag(File,"data");

	    INI_WriteInt(File,"Admin Level", PlayerInfo[i][pAdmin]);
	    INI_WriteInt(File,"Faction Director", PlayerInfo[i][pFacDirector]);
	    INI_WriteInt(File,"Faction", PlayerInfo[i][pFaction]);
	    INI_WriteInt(File,"Faction Rank", PlayerInfo[i][pFacRanks]);

	    INI_Close(File);
	}
    return 1;
}
Put under OnGameModeInit:
AccTimer = SetTimer("SaveAccounts", 60000 *5, true); // Saves all accounts every 5 minutes

Put under OnGameModeExit:
KillTimer(AccTimer);

Under OnPlayerDisconnect:
SaveAccounts();

For safe /gmx command:
new RestartTime = 10;
CMD:gmx(playerid)
{
    if(PlayerInfo[playerid][pAdmin] < 3)
	{
		SendClientMessage(playerid, -1, "You are not authorized to use that command!");
	}
	else if(PlayerInfo[playerid][pAdmin] >= 3)
	{
	    SaveAccounts();
		SetTimer("ServerRestartTime",10000 ,false);
	}
	return 1;
}

forward ServerRestartTime(playerid);
public ServerRestartTime(playerid)
{
	RestartTime--;
	if(RestartTime == 0)
	{
	    RestartTime = 10;
	    SendRconCommand("gmx");
	    return 1;
	}
	return 1;
}
Reply
#6

Quote:
Originally Posted by ShadowMortar
Посмотреть сообщение
Try with this:

Код:
new AccTimer; // Defines the timer

forward SaveAccounts();
public SaveAccounts()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
	    new INI:File = INI_Open(UserPath(i));
	    INI_SetTag(File,"data");

	    INI_WriteInt(File,"Admin Level", PlayerInfo[i][pAdmin]);
	    INI_WriteInt(File,"Faction Director", PlayerInfo[i][pFacDirector]);
	    INI_WriteInt(File,"Faction", PlayerInfo[i][pFaction]);
	    INI_WriteInt(File,"Faction Rank", PlayerInfo[i][pFacRanks]);

	    INI_Close(File);
	}
    return 1;
}
Put under OnGameModeInit:
AccTimer = SetTimer("SaveAccounts", 60000 *5, true); // Saves all accounts every 5 minutes

Put under OnGameModeExit:
KillTimer(AccTimer);

Under OnPlayerDisconnect:
SaveAccounts();

For safe /gmx command:
new RestartTime = 10;
CMD:gmx(playerid)
{
    if(PlayerInfo[playerid][pAdmin] < 3)
	{
		SendClientMessage(playerid, -1, "You are not authorized to use that command!");
	}
	else if(PlayerInfo[playerid][pAdmin] >= 3)
	{
	    SaveAccounts();
		SetTimer("ServerRestartTime",10000 ,false);
	}
	return 1;
}

forward ServerRestartTime(playerid);
public ServerRestartTime(playerid)
{
	RestartTime--;
	if(RestartTime == 0)
	{
	    RestartTime = 10;
	    SendRconCommand("gmx");
	    return 1;
	}
	return 1;
}
Instead of saving it every 5 minutes, how can I make it so it'll update on change? Like, I'd like it so if I'm in faction X, and I change it to faction y the server will save the player data.

Edit: I already made a gmx with a timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)