SQL question
#1

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.
Reply
#2

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 ...);
Reply
#3

You should read the server sided money tutorial.
  • It's a money anti-cheat
  • Money variable is updated everytime you use it.
  • Money is always stored in the server for ease of use.
So yeah, that' pretty much solves all your problems.

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

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
Reply
#5

Got it working, thanks guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)