My SQL doesn't save moneyz!
#1

Hello.

I've noticed that when I have money Ingame and I /q on my script it doesn't save my money to the Database!

OnPlayerDisconnect calls the function "saveplayer(playerid)"

And it does work but it doesn't save the money, It counts it as 0. O_O.

Also, How would I make it load the money to the player when He spawns? The money from his account.

Current OnPlayerSpawn:
pawn Код:
public OnPlayerSpawn(playerid) {
    // Let's check if the player has logged in. Have they not? Let's kick them.
    new string[128];
    if(playerVariables[playerid][pStatus] != 1){
    if(playerVariables[playerid][pAdmin]){
    format(string, sizeof(string), "SERVER: {FFFFFF}You are logged in as level %d administrator.", playerVariables[playerid][pAdmin]);
    SendClientMessage(playerid, COLOR_NICERED, string);}
    SetPlayerColor(playerid, COLOR_GREY);
    GivePlayerMoney(playerid, playerVariables[playerid][pMoney]);
    SendClientMessage(playerid, COLOR_GREY, "You need to login before you can spawn.");
    return Kick(playerid);
    }

    return 1;
}
My "saveplayer" function.

pawn Код:
stock savePlayer(playerid) {
    // Let's save the player's information into the mysql database so when they login it can be reset.
    // Before we do anything, we need to grab the most up-to-date information and save it into the player variables.
   
    new
        szQuery[512];   // Since we're going to save a lot of data, our query size will need to be big.
       
    // We need to get the position and facing angle of the player, so we can save it. IF, they are logged in.
    GetPlayerPos(playerid, playerVariables[playerid][pPos][0], playerVariables[playerid][pPos][1], playerVariables[playerid][pPos][2]);
    GetPlayerFacingAngle(playerid, playerVariables[playerid][pPos][3]);
       
    // Interior and virtual world too... In fact, everything else significant about the player that SA-MP can tell us.
    playerVariables[playerid][pInterior] = GetPlayerInterior(playerid);
    playerVariables[playerid][pVirtualWorld] = GetPlayerVirtualWorld(playerid);

    GetPlayerHealth(playerid, playerVariables[playerid][pHealth]);
    GetPlayerArmour(playerid, playerVariables[playerid][pArmour]);
    GetPlayerMoney(playerid, playerVariables[playerid][pMoney]);
   
    // We will now take the nformation we grabbed and input it to make a query.
    // Remember the database ID? This is one instance of where it will be useful to use.
    format(szQuery, sizeof(szQuery), "UPDATE players SET Health = '%f', Armour = '%f', PosX = '%f', PosY = '%f', PosZ = '%f', PosR = '%f'", playerVariables[playerid][pHealth], playerVariables[playerid][pArmour], playerVariables[playerid][pPos][0], playerVariables[playerid][pPos][1], playerVariables[playerid][pPos][2], playerVariables[playerid][pPos][3]);
    format(szQuery, sizeof(szQuery), "%s, Interior = %d, Skin = %d, Money = %d WHERE ID = %d", szQuery, playerVariables[playerid][pInterior], playerVariables[playerid][pSkin], playerVariables[playerid][pMoney], playerVariables[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);

    return 1;
}

Anyone know the resolutions!? been trying to figure it out for ages now!
Reply
#2

Look mysql_debug.txt for more information. Does the query succeed? Tell us. If no, which error?
Reply
#3

All the queries run it says the money is 0! When it isn't, all the other variables run.
Reply
#4

[22:02:16] (MySQL) Query: UPDATE players SET Health = '100.000000', Armour = '0.000000', PosX = '-145.727005', PosY = '1206.778808', PosZ = '19.689229', PosR = '172.503402', Interior = 0, Skin = 147, Money = 0 WHERE ID = 9 | ResultID: 4


^^ from the server_log, All runs, but 0 money!? :O
Reply
#5

pawn Код:
GetPlayerMoney(playerid, playerVariables[playerid][pMoney]);
GetPlayeMoney has only one parameter, and give money to a player everytime he spawns, he will give the original money x times he spawned.
Reply
#6

So., How do I fix this? :/
Reply
#7

Replace with
pawn Код:
GetPlayerMoney(playerid);
Inside the savePlayer custom function.

Note; when you disconnect, your money should be greater than 0 to see if it works or not and post the debug.
Reply
#8

NOANY, still 0 D:

pawn Код:
[22:17:49]  

[22:17:49] ---------------------------

[22:17:49] MySQL Debugging activated (12/30/12)

[22:17:49] ---------------------------

[22:17:49]  

[22:17:49] >> mysql_connect( )

[22:17:49] CMySQLHandler::CMySQLHandler() - constructor called.

[22:17:49] CMySQLHandler::CMySQLHandler() - Connecting to "XXX.XX.XX.XXX" | DB: "XXXXXX_XXXX" | Username: "8060_bcrp" ...

[22:17:50] CMySQLHandler::Connect() - Connection was successful.

[22:17:50] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[22:17:50] >> mysql_ping( Connection handle: 1 )

[22:17:50] CMySQLHandler::Ping() - Connection is still alive.

[22:17:50] >> mysql_query( Connection handle: 1 )

[22:17:50] CMySQLHandler::Query(resultID) - Threaded query with id 100 started. (Extra ID: 0)

[22:17:50] >> mysql_connect( )

[22:17:50] CMySQLHandler::Connect() - Connection was successful.

[22:17:50] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[22:17:50] CMySQLHandler::ProcessQueryThread(CREATE TABLE IF NOT EXISTS `samp_ban` (`BanID` int(6) NOT NULL AUTO_INCREMENT,`user_banned` varchar(24) NOT NULL,`user_banned_ip` varchar(15) NOT NULL,`user_banner` varchar(24) NOT NULL,`ban_reason` varchar(40) NOT NULL,`ban_timestamp` timestamp NOT NULL,`ban_time` int(10) NOT NULL,PRIMARY KEY (`BanID`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;) - Data is getting passed to OnQueryFinish() - (Threadsafe: Yes)

[22:17:50] OnQueryFinish(100,"CREATE TABLE IF NOT EXISTS `samp_ban` (`BanID` int(6) NOT NULL AUTO_INCREMENT,`user_banned` varchar(24) NOT NULL,`user_banned_ip` varchar(15) NOT NULL,`user_banner` varchar(24) NOT NULL,`ban_reason` varchar(40) NOT NULL,`ban_timestamp` timestamp NOT NULL,`ban_time` int(10) NOT NULL,PRIMARY KEY (`BanID`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;") - Called.

[22:18:24] >> mysql_query_callback( Connection handle: 1 )

[22:18:24] CMySQLHandler::Query("jban_OnQueryFinish") - Custom callback query with index 102 started (ExtraID: 0)

[22:18:24] >> mysql_real_escape_string( Connection handle: 1 )

[22:18:24] CMySQLHandler::EscapeString(Oscii_Shively); - Escaped 13 characters to Oscii_Shively.

[22:18:24] >> mysql_query( Connection handle: 1 )

[22:18:24] CMySQLHandler::ProcessQueryThread(SELECT user_banner, ban_reason, TIMESTAMPDIFF(MINUTE, NOW(), DATE_ADD(ban_timestamp, INTERVAL ban_time MINUTE)) FROM `samp_ban` WHERE user_banned_ip = '192.168.0.3' AND (NOW() <= DATE_ADD(ban_timestamp, INTERVAL ban_time MINUTE) OR ban_time = 0)) - Data is getting passed to jban_OnQueryFinish() - (Threadsafe: Yes)

[22:18:24] CMySQLHandler::Query(resultID) - Threaded query with id 1 started. (Extra ID: 0)

[22:18:24] jban_OnQueryFinish(102,"SELECT user_banner, ban_reason, TIMESTAMPDIFF(MINUTE, NOW(), DATE_ADD(ban_timestamp, INTERVAL ban_time MINUTE)) FROM `samp_ban` WHERE user_banned_ip = '192.168.0.3' AND (NOW() <= DATE_ADD(ban_timestamp, INTERVAL ban_time MINUTE) OR ban_time = 0)") - Called.

[22:18:24] >> mysql_store_result( Connection handle: 1 )

[22:18:24] CMySQLHandler::StoreResult() - Result was stored.

[22:18:24] >> mysql_num_rows( Connection handle: 1 )

[22:18:24] CMySQLHandler::NumRows() - Returned 0 row(s)

[22:18:24] >> mysql_free_result( Connection handle: 1 )

[22:18:24] CMySQLHandler::FreeResult() - Result was successfully free'd.

[22:18:24] CMySQLHandler::ProcessQueryThread(SELECT * FROM players WHERE Username = '
Oscii_Shively') - Data is getting passed to OnQueryFinish() - (Threadsafe: Yes)

[22:18:24] OnQueryFinish(1,"SELECT * FROM players WHERE Username = '
Oscii_Shively'") - Called.

[22:18:24] >> mysql_store_result( Connection handle: 1 )

[22:18:24] CMySQLHandler::StoreResult() - Result was stored.

[22:18:24] >> mysql_num_rows( Connection handle: 1 )

[22:18:24] CMySQLHandler::NumRows() - Returned 1 row(s)

[22:18:24] >> mysql_retrieve_row( Connection handle: 1 )

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Password") - B87E41BB83A4B9B5DBD145F15C2F32F91A533E4AC98AFBC6FF97D26CDACC07BB096895DAE7FE543F2C4EA81F2E6146200215CB1D58C9959D764ED9D50A3B7A52

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("ID") - 9

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Money") - 0

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Admin") - 7

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("PosX") - -145.727005

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("PosY") - 1206.778808

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("PosZ") - 19.689229

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("PosR") - 172.503402

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Health") - 100

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Armour") - 0

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Interior") - 0

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("VirtualWorld") - 0

[22:18:24] >> mysql_fetch_field_row( Connection handle: 1 )

[22:18:24] CMySQLHandler::FetchField("Skin") - 147

[22:18:24] >> mysql_free_result( Connection handle: 1 )

[22:18:24] CMySQLHandler::FreeResult() - Result was successfully free'
d.

[22:18:48] >> mysql_query( Connection handle: 1 )

[22:18:48] CMySQLHandler::Query(resultID) - Threaded query with id 4 started. (Extra ID: 0)

[22:18:48] CMySQLHandler::ProcessQueryThread(UPDATE players SET Health = '100.000000', Armour = '0.000000', PosX = '-147.720626', PosY = '1191.628906', PosZ = '19.742187', PosR = '172.503402', Interior = 0, Skin = 147, Money = 0 WHERE ID = 9) - Data is getting passed to OnQueryFinish() - (Threadsafe: Yes)

[22:18:48] OnQueryFinish(4,"UPDATE players SET Health = '100.000000', Armour = '0.000000', PosX = '-147.720626', PosY = '1191.628906', PosZ = '19.742187', PosR = '172.503402', Interior = 0, Skin = 147, Money = 0 WHERE ID = 9") - Called.
Reply
#9

I just set my money from the DB and went ingame and still no money, but when I /q'd the Server_LOG said i had the money I set in the DB
Reply
#10

I'm sure you've changed another one.
pawn Код:
format(szQuery, sizeof(szQuery), "%s, Interior = %d, Skin = %d, Money = %d WHERE ID = %d", szQuery, playerVariables[playerid][pInterior], playerVariables[playerid][pSkin], GetPlayerMoney(playerid), playerVariables[playerid][pDBID]);
On the format, it updates what the variable playerVariables[playerid][pMoney] holds and in your case is 0. Just use the GetPlayerMoney function to the formatted text.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)