SA-MP Forums Archive
SQL question - 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: SQL question (/showthread.php?tid=346473)



SQL question - vIBIENNYx - 28.05.2012

Okay, basically, I have a money variable in my MySQL which is:
pawn Код:
PVar[playerid][money]
Is there a way to add or take away to the variable inside the MySQL and THEN get the player money from the variable, rather than updating the money then saving it?

This is my Save code for exiting the server.

pawn Код:
stock SavePVar(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        new
            Query[600];

        format(Query, sizeof(Query), "UPDATE `username` SET `username` = %s, `ppassword` = %s, `alevel` = %d, `kills` = %d, `deaths` = %d, `money` = %d, `level` = %d, `factionID` = %d, `factionRank` = %d, `clothes` = %d", // Also remember to update this...

        PVar[playerid][username],
        PVar[playerid][ppassword],
        PVar[playerid][alevel],
        PVar[playerid][kills],
        PVar[playerid][deaths],
        PVar[playerid][money],
        PVar[playerid][level],
        PVar[playerid][factionID],
        PVar[playerid][factionRank],
        GetPlayerSkin(playerid),
        pName(playerid));

        mysql_query(Query);
        mysql_free_result();
        return 1;
    }
    else return 0;
}
When the player spawns it gives them the money with this:

pawn Код:
public OnPlayerSpawn(playerid)
{
    GivePlayerMoney(playerid, PVar[playerid][money]);
    return 1;
}
What I am asking is if I could do every time a transaction is made in the server:

pawn Код:
PVar[playerid][money] + 100;
GivePlayerMoney(playerid, PVar[playerid][money]);
But it doesn't work for some odd reason.


Re: SQL question - jamiesage123 - 28.05.2012

Add '' around the %d's and %s's.

(cant remember what they're called :P)

Example:

format(Query, sizeof(Query), "UPDATE `users` SET money = '%d', score = '%d', noteOne = '%s' WHERE username = '%s'", bla, bla ...);


Re: SQL question - ReneG - 28.05.2012

You should read the server sided money tutorial.
So yeah, that' pretty much solves all your problems.

https://sampforum.blast.hk/showthread.php?tid=71136


Re: SQL question - iGetty - 28.05.2012

It's just like using OnPlayerUpdate, like this:

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerMoney(playerid) != PVar[playerid][money])
    {
        ResetPlayerMoney(playerid);
        GivePlayerMoney(playerid, PVar[playerid][money]);
    }
    return 1;
}
Hope it helps Ben. PS: BBM me biatch <3


Re: SQL question - vIBIENNYx - 28.05.2012

Got it working, thanks guys.