SA-MP Forums Archive
A little issue the y_ini - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: A little issue the y_ini (/showthread.php?tid=650611)



A little issue the y_ini - RxErT - 03.03.2018

(NOTE:I'm running everything on my localhost no servers or anything)
So i'm having an issue in this database saver, like when launch the filterscript it launch successfully and saves my stats, and if i relog my stats will stay the same, but when i close samp-server.exe and relaunch it again and join the server, all my stats were gone...

PHP код:
#define PATH "GoldUser/%s.ini"
forward LoadUser_data(playerid,name[],value[]);
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("Gold",PlayerInfo[playerid][pGold]);
     return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
   new 
INI:File INI_Open(UserPath(playerid));
   
INI_SetTag(File,"data");
   
INI_WriteInt(File,"Gold",PlayerInfo[playerid][pGold]);
   
INI_Close(File);
   return 
1;

is there anything missing or wrong?


Re: A little issue the y_ini - PepsiCola23 - 03.03.2018

Don t save the stats when a player disconnects . Save them right after you modify them , because otherwise in case of a server stop or restart, the data will be lost.


OnPlayerDisconnect is not called if the server crashes or restarts.


Re: A little issue the y_ini - wallen - 03.03.2018

I had that issue, so you basically save stats on callback "On Gamemode Exit"?


Re: A little issue the y_ini - RxErT - 03.03.2018

Quote:
Originally Posted by PepsiCola23
Посмотреть сообщение
Don t save the stats when a player disconnects . Save them right after you modify them , because otherwise in case of a server stop or restart, the data will be lost.


OnPlayerDisconnect is not called if the server crashes or restarts.
So as you're saying it should be like that right?:

Код:
CMD:setgold(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new
             string[400],
             tname[MAX_PLAYER_NAME],
             targetid,
             maxcookies;

		if(sscanf(params, "ii", targetid, maxcookies))
        {
            return SendClientMessage(playerid, 0xF8F8F8FFF, "Syntax: {Ffffff}/setgold <id> <amount>");
        }
        for(new i=0;i<MAX_PLAYERS; i++) continue; {
                 if((!IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID))
                {
                       SendClientMessage(playerid,-1, "{f00f00}ERROR: {FFFFFF}Player isn't Connected!");
                }
	}
        if(maxcookies < 0 || maxcookies > 100000000)
        {
        	return SendClientMessage( playerid, 0xF8F8F8FFF, "{f00f00}ERROR: {FFFFFF}highest amount is 100000000.");
		}
        else
        {
            GetPlayerName(targetid, tname, sizeof(tname));
            format(string, sizeof(string), "{A9C4E4}an administrator has set %s's golds amount to %i.", tname, maxcookies);
            SendClientMessageToAll(0xF8F8F8FFF, string);
            GameTextForPlayer(targetid,"~W~W~P~O~R~W! ~B~N~G~I~R~C~P~E! ~Y~GOLD! ~R~:)",3000,3);
            PlayerPlaySound(targetid, 17802, 0.0, 0.0, 0.0);
            new INI:File = INI_Open(UserPath(targetid));
            PlayerInfo[targetid][pGold] = maxcookies;
            INI_WriteInt(File,"Gold",maxcookies);
       	    INI_Close(File);
            return 1;
        }
    }
    else
    {
	    SendClientMessage(playerid, 0xf8F8F8FFF,"{F00f00}ERROR: {FFFFFF}You aren't authorized to use this command.");
    }
    return 1;
}
Quote:
Originally Posted by wallen
Посмотреть сообщение
I had that issue, so you basically save stats on callback "On Gamemode Exit"?
No, since it's a filterscript i don't use ongamemodeexit and also onfilterscriptexit both aren't used in the script, i just save stats under OnPlayerDisconnected as shown above.


Re: A little issue the y_ini - PepsiCola23 - 03.03.2018

[QUOTE=RxErT;3999321]So as you're saying it should be like that right?:

Код:
CMD:setgold(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new
             string[400],
             tname[MAX_PLAYER_NAME],
             targetid,
             maxcookies;

		if(sscanf(params, "ii", targetid, maxcookies))
        {
            return SendClientMessage(playerid, 0xF8F8F8FFF, "Syntax: {Ffffff}/setgold <id> <amount>");
        }
        for(new i=0;i<MAX_PLAYERS; i++) continue; {
                 if((!IsPlayerConnected(targetid)) || (targetid == INVALID_PLAYER_ID))
                {
                       SendClientMessage(playerid,-1, "{f00f00}ERROR: {FFFFFF}Player isn't Connected!");
                }
	}
        if(maxcookies < 0 || maxcookies > 100000000)
        {
        	return SendClientMessage( playerid, 0xF8F8F8FFF, "{f00f00}ERROR: {FFFFFF}highest amount is 100000000.");
		}
        else
        {
            GetPlayerName(targetid, tname, sizeof(tname));
            format(string, sizeof(string), "{A9C4E4}an administrator has set %s's golds amount to %i.", tname, maxcookies);
            SendClientMessageToAll(0xF8F8F8FFF, string);
            GameTextForPlayer(targetid,"~W~W~P~O~R~W! ~B~N~G~I~R~C~P~E! ~Y~GOLD! ~R~:)",3000,3);
            PlayerPlaySound(targetid, 17802, 0.0, 0.0, 0.0);
            new INI:File = INI_Open(UserPath(targetid));
            PlayerInfo[targetid][pGold] = maxcookies;
            INI_WriteInt(File,"Gold",maxcookies);
       	    INI_Close(File);
            return 1;
        }
    }
    else
    {
	    SendClientMessage(playerid, 0xf8F8F8FFF,"{F00f00}ERROR: {FFFFFF}You aren't authorized to use this command.");
    }
    return 1;
}
yes you need to save the data whenever you edit it.


Re: A little issue the y_ini - RxErT - 03.03.2018

Okay so, i did it and in every single command, but when i closed samp-server.exe and relaunched it is saw that the same issue is still there, maybe because i ain't loading player data under OnPlayerConnnect? or something else?


Re: A little issue the y_ini - RxErT - 03.03.2018

FIXED!
Sharing what i did to fix:

Let me start off thanking PepsiCola for his idea because it helped to save the data but not to load it.
so what i did, is i put this under public OnPlayerConnect(playerid) callback so when player's name is already exists in the database his/her data will be loaded, but if he/she is new, it wouldn't do anything..

PHP код:
public OnPlayerConnect(playerid)
{
    if(
fexist(UserPath(playerid)))
    {
        
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra true, .extra playerid);
        
SendClientMessage(playerid, -1"Welcome back");
    }
    else
    {
        
SendClientMessage(playerid, -1"welcome it's ur first time");
    }
    return 
1;