SA-MP Forums Archive
Saving money to offline users. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Saving money to offline users. (/showthread.php?tid=221785)



Saving money to offline users. - Haydz - 06.02.2011

Hey guys, on my server you can purchase vehicles of offline players. I was wondering how you can set a certain amount of money to the offline players account(the player who use to own the vehicle)

heres some things you may/may not need to know.

pawn Код:
mysql - strickenkids.
vehicle owners is - VehicleInfo[vehicleid][Owner]
the sell price is defined by players - VehicleInfo[vehicleid][SalePrice]
So any help is much appreciated. if you need any thing else feel free to ask.


Re: Saving money to offline users. - Antonio [G-RP] - 06.02.2011

Do a query that looks something like this...

pawn Код:
new pname[24], query[200];
GetPlayerName(playerid, pname, sizeof(pname));

format(query, sizeof(query), "UPDATE `accounts` SET `money` = %d WHERE `playername` = '%s'", VehicleInfo[vehicleid][SalePrice], pname);
mysql_query(query);
Ofcourse you will need to find a function called GetFromAccount (commonly known SQL function) and it will help you get the players existing money from the DB, and then you can add on the SALEPRICE money to it.


Re: Saving money to offline users. - Haydz - 06.02.2011

I tryed that before without the GetFromAccount function so i was close lol. Mind linking me to the page. searched ****** and nothing came up apart from this thread.

Cheers.


Re: Saving money to offline users. - Antonio [G-RP] - 06.02.2011

pawn Код:
stock GetFromAccount(dbid, obtaining[], holdingvar[])
{
    new Query[ 128 ];
    format(Query, sizeof(Query), "SELECT `%s` FROM `accounts` WHERE `SQLid` = %d", obtaining, dbid);
    mysql_query(Query);
    mysql_store_result();

    if(mysql_fetch_row(holdingvar) == 1)
    {
        mysql_free_result();
    }

    return 1;
}
Enjoy.


Re: Saving money to offline users. - Haydz - 06.02.2011

Cheers mate, would you mind explain the code. like what is dbid/obtaining[] and holdingvar[].


Re: Saving money to offline users. - Antonio [G-RP] - 06.02.2011

Well for me, there's a field in the 'accounts' table that is a players 'SQLid'. This field is auto incremented, which means that each player is assigned a unique SQLid.

Obtaining is what you want to get.

Now lets do an example. Say my SQLid is 1, because I was the FIRST player to register on the server.
And what I'm looking for, is my money. I'm trying to find how much money I have.

What I will do is..

pawn Код:
new money[12], actualmoney;
GetFromAccount(PlayerStats[playerid][pSQLid], cash, money); // The SQLid is the dbid, cash is the field in the table `accounts`, and money is the holding variable.
// Currently, 'money' is a string, so...
actualmoney = strval(money);
// Now you can do whatever you wish with money.