Saving money to offline users.
#1

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)