[+REP] Option 1 or Option 2?
#1

Hello, which is the safest and best option?

OPTION 1:
Every time there is a value to a particular variable the player should be updated.
Exemple:
Код HTML:
pInfo[playerid][pPhoneNumber] = 58823; VPUpdate(playerid, pPhoneNumberu);
pInfo[playerid][pPhoneBook] = 1; VPUpdate(playerid, pPhoneBooku);
pInfo[playerid][pScore] = 1; VPUpdate(playerid, pScoreu);
Код HTML:
forward VPUpdate(id, update);
public VPUpdate(id, update)
{
    new query[254];
    if(IsPlayerConnected(id))
    {
        switch(update)
        {
            case pAdminu: { mysql_format(MySQLCon, query, sizeof(query), "UPDATE players SET Admin='%d' WHERE user='%s'", pInfo[id][pAdmin], GetName(id)); }
            case pHelperu: { mysql_format(MySQLCon, query, sizeof(query), "UPDATE players SET Helper='%d' WHERE user='%s'", pInfo[id][pHelper], GetName(id)); }
            case pMoneyu: { mysql_format(MySQLCon, query, sizeof(query), "UPDATE players SET Money='%d' WHERE user='%s'", pInfo[id][pMoney], GetName(id)); }
            case pScoreu: { mysql_format(MySQLCon, query, sizeof(query), "UPDATE players SET Score='%d' WHERE user='%s'", pInfo[id][pScore], GetName(id)); }
            case pStatusu: { mysql_format(MySQLCon, query, sizeof(query), "UPDATE players SET Status='%d' WHERE user='%s'", pInfo[id][pStatus], GetName(id)); }
            //..........................................
        }
        mysql_pquery(MySQLCon, query);
    }
    return 1;
}
OPTION 2:
All value modified save to disconnect the player.
Exemple:
Код HTML:
public OnPlayerDisconnect(playerid, reason)
{
	mysql_format(MySQLCon, query, sizeof(query), "UPDATE `players` SET `Admin`=%d, `Vip`=%d, `Money`=%d, `Score`=%d, `TrustedLevel`=%d, `Deaths`=%d, `Kills`=%d, `X`=%f, `Y`=%f, `Z`=%f, `FacingAngle`=%f, `Interior`=%d,`VW`=0,`SkinID`=%d WHERE `ID`=%d AND `user`='%e'",
        pInfo[playerid][pAdmin],
        pInfo[playerid][pVip],
        GetPlayerMoney(playerid),
        GetPlayerScore(playerid),
        pInfo[playerid][pTrustedLevel],
        pInfo[playerid][pDeaths],
        pInfo[playerid][pKills],
        pPos[0],
        pPos[1],
        pPos[2],
        FacingAngle,
        GetPlayerInterior(playerid),
		pInfo[playerid][pSkinID],
        pInfo[playerid][pID],
        PlayerName(playerid));
        mysql_tquery(MySQLCon, query, "", "");
	return 1;
}
Reply
#2

Personally I've always done it the option 2 way. No problems with it when I've done it =]
Reply
#3

Ok, thanks for the reply.
Waiting for other opinions.
Reply
#4

Option 2 is better then option 1
Reply
#5

I have heard that option 1 is better and safer for important values, but due to older code we are saving it when triggered. For example, when disconnecting, server shutting down, or on manual saving by an Administrator.

But if you are saving it in bulk it should be faster to use option 2.
Reply
#6

Thanks for the replies.
Most Awaited other opinions...
Reply
#7

Option 2, Saving in disconnecting, But its risky if your server crashed / restarted (not gmx, console restart)
I actually prefer Option 1 (Becasue you're using MySQL so, It w'd be better)..
But Option 2 is more effective, Against speed and others, Its mostly used on every SAMP server..
I using Option 2 on my gamemode (I don't use MySQL, I prefer y_ini.)..
So I just will say, Go ahead with Option 2..
Reply
#8

I prefer saving data the moment their values change.
Reply
#9

Ofcourse OPTION 1

You should safe values when you change them.

When player disconnects if values are the same of the table is 0 need to save them..
Reply
#10

I'd rather using the 1st method of the listed, because it enables you to update the data whenever you need to. It's really convenient as you can use a command to save player's stats, for instance you can use a loop to freeze all the players, inform them that you are updating their data, and then safely restart the server etc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)