[HELP] MySQL saving accounts
#1

Okay I have a problem since I started scripting :S
With any INI include my stats doesn't save on gmx or when I restart my console, same is with MySQL
Here is register & login script
pawn Код:
enum pInfo
{
    pKills,
    pDeaths,
    pAdmin,
    pScore,
    pMoney,
    pVIP,
    pOnline,
    pWarns,
    pCode
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    CustomBanCheck(playerid);
    ResetPlayerMoney(playerid);
    SetWorldTime(12);
    TogglePlayerClock(playerid, 0);
    format(string, sizeof(string), "Dobrodoљli na iStunt %s by System32", VERSION);
    SendClientMessage(playerid, 0xFF6C6C99, string);
    SendClientMessage(playerid, 0x80FF0099, "Upiљite /help da vidite listu komandi!");
   
    new escpname[24];
    mysql_real_escape_string(GetName(playerid), escpname);
    format(Query, sizeof(Query), "SELECT * FROM `racuni` WHERE `Korisnik` = '%s' LIMIT 1", escpname);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() == 1)
    {
        SetPlayerCameraPos(playerid, 1584.69, -1310.56, 124.02);
        SetPlayerCameraLookAt(playerid, 1581.30, -1314.24, 126.07);
   
        format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
        format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} je registrirano!\nPrijavite se!", GetName(playerid));
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT , title, text2, "Ok", "Izlaz");
    }
    else
    {
        PlayerPlaySound(playerid, 1185, 0.0, 0.0, 10.0);
        TogglePlayerSpectating(playerid, 1);
        ForceClassSelection(playerid);
        ClearChatForPlayer(playerid, 30);
        TextDrawShowForPlayer(playerid, IntroBackground);
        TextDrawShowForPlayer(playerid, IntroPresents);
        TextDrawShowForPlayer(playerid, IntroRevolution);
        TextDrawShowForPlayer(playerid, IntroSystem32);
        TextDrawShowForPlayer(playerid, IntroFlare);
        IntroTimer[playerid] = SetTimerEx("Intro", 10000, 0, "d", playerid);
    }
    mysql_free_result();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(rBit1_Get(IsPlayerLogged, playerid))
    {
        new escpname[24];
        mysql_real_escape_string(GetName(playerid), escpname);
        format(Query, sizeof(Query), "UPDATE `racuni` SET `Bodovi` = %d, `Novac` = %d, `Ubojstva` = %d, `Smrti` = %d, `Code` = %d, `Warns` = %d, `Online` = %d, `VIP` = %d, `Admin` = %d WHERE `Korisnik` = '%s'", GetPlayerScore(playerid), GetPlayerCash(playerid), PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pCode], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pOnline], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pAdmin], escpname);
        mysql_query(Query);
        mysql_free_result();
    }
   
    players --;
    TextDrawDestroy(esp[playerid]);
    TextDrawDestroy(esph[playerid]);
    TextDrawDestroy(espi[playerid]);
    return 1;
}
public OnPlayerSpawn(playerid)
{
    SetPlayerHealth(playerid, 100.0);
    TextDrawShowForPlayer(playerid,iStunt);
    TextDrawShowForPlayer(playerid, ShadowsRandom);
    TextDrawShowForAll(tdplayers);
    TextDrawShowForAll(Time);
   
    PingTimer[playerid] = SetTimerEx("CheckPing", 1000, 1, "i", playerid);
    SetPlayerInterior(playerid, 0);
   
    if(rBit1_Get(InJailZone, playerid))
    {
        rBit1_Set(InDmZone, playerid, 1);
        SetPlayerInterior(playerid, 6);
        SetPlayerPos(playerid, 264.2483,77.5985,1001.03914);
    }
    if(rBit1_Get(InDmZone, playerid))
    {
        rBit1_Set(InDmZone, playerid, 0);
    }
    if(rBit1_Get(IsPlayerLogged, playerid) && GetPVarInt(playerid, "MoneyGiven") > 0)
    {
        GivePlayerMoney(playerid, GetPVarInt(playerid, "MoneyGiven"));
        SetPVarInt(playerid, "MoneyGiven", 0);
    }
    return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[playerid][pDeaths] = PlayerInfo[playerid][pDeaths] + 1;
    if(killerid != INVALID_PLAYER_ID) PlayerInfo[playerid][pKills] = PlayerInfo[playerid][pKills] + 1;
    SendDeathMessage(killerid, playerid, reason);
    rBit1_Set(InDmZone, playerid, 0);
    SetPlayerHealth(killerid, 100.0);
}

public OnGameModeInit()
{
    mysql_debug(1);
    mysql_connect("localhost", "root", "sa:mp", "");

    WasteDeAMXersTime();
   
    SetGameModeText("iStunt "VERSION);
    DisableInteriorEnterExits();
    UsePlayerPedAnims();
    SetWeather(1);
    EnableStuntBonusForAll(0);
   
    CreateDynamicHouse(-2521.3315,-623.4722,132.7717, 3, 1527.229980,-11.574499,1002.097106, 1000, 0, 0);
    CreateDynamicHouse(-2504.2537,-624.8500,132.7227, 5, 2350.339843,-1181.649902,1027.976562, 15000, 2, 2);
    CreateDynamicHouse(-2514.5139,-631.3778,134.0594, 12, 2324.419921,-1145.568359,1050.710083, 5000, 1, 1);

    CreateRentVehicle(405,-2396.89990234,-601.00000000,132.60000610,0.00000000,-1,-1,15, 1000); //Sentinel
    AddStaticVehicle(411,-2405.60009766,-594.00000000,132.39999390,260.00000000,-1,-1); //Infernus

    SetTimer("Online", 3600000, 1);
    SetTimer("RandomMessage", 10000, 1);
    SetTimer("MoneyTimer", 1000, 1);
    SetTimer("TimeUp", 1000, 1);
    return 1;
}

public OnGameModeExit()
{
    mysql_close();

    TextDrawDestroy(iStunt);
    TextDrawDestroy(ShadowsRandom);
    TextDrawDestroy(tdplayers);
    TextDrawDestroy(Time);
   
    TextDrawDestroy(IntroPresents);
    TextDrawDestroy(IntroRevolution);
    TextDrawDestroy(IntroSystem32);
    TextDrawDestroy(IntroScripter);
    TextDrawDestroy(IntroScripterName);
    TextDrawDestroy(IntroMapper);
    TextDrawDestroy(IntroMapperName);
    TextDrawDestroy(IntroFlare);
    TextDrawDestroy(IntroBackground);
    TextDrawDestroy(IntroBackground1);
    TextDrawDestroy(IntroBackground2);
    TextDrawDestroy(IntroBackground3);
    TextDrawDestroy(IntroBackground4);
    TextDrawDestroy(IntroBackground5);
    TextDrawDestroy(IntroBackground6);
    TextDrawDestroy(IntroBackground7);
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 1:
        {
            if(!response) return Kick(playerid);
            if(!strlen(inputtext))
            {
                format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
                format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} nije registrirano!\nRegistrirajte se!", GetName(playerid));
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT , title, text2, "Ok", "Izlaz");
            }
            new escpname[24], escpass[100];
            mysql_real_escape_string(inputtext, escpass);
            mysql_real_escape_string(GetName(playerid), escpname);
            format(Query, sizeof(Query), "INSERT INTO `racuni` (`Korisnik`, `Lozinka`, `Ubojstva`, `Smrti`, `Admin`, `Bodovi`, `Novac`, `VIP`, `Online`, `Warns`, `Code`, `IP`) VALUES ('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s')", escpname, escpass, GetIP(playerid));
            mysql_query(Query);
            format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
            format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} je registrirano!\nPrijavite se!\n\nUpiљite vaљ aktivacijski kod!", GetName(playerid));
            ShowPlayerDialog(playerid, 3, DIALOG_STYLE_INPUT, title, text2, "Ok", "");
            rBit1_Set(IsPlayerLogged, playerid, 1);
        }
        case 2:
        {
            if(!response) return Kick(playerid);
            new escpname[24];
            mysql_real_escape_string(GetName(playerid), escpname);
            format(Query, sizeof(Query), "SELECT * FROM `racuni` WHERE `Korisnik` = '%s' AND `Lozinka` = '%s' LIMIT 1", escpname, inputtext);
            mysql_query(Query);
            mysql_store_result();
            if(mysql_num_rows() == 0)
            {
                SetPVarInt(playerid, "WrongPass", GetPVarInt(playerid, "WrongPass") + 1);
                format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
                format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} je registrirano!\nPrijavite se!\n\n{F81414}Upisali ste pogreљnu lozinku!", GetName(playerid));
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT , title, text2, "Ok", "Izlaz");
                if(GetPVarInt(playerid, "WrongPass") == 3)
                {
                    format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
                    format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} je registrirano!\nPrijavite se!\n\nUpiљite vaљ aktivacijski kod!", GetName(playerid));
                    ShowPlayerDialog(playerid, 4, DIALOG_STYLE_INPUT, title, text2, "Ok", "");
                }
            }
            else
            {
                new line[750];
                if(mysql_fetch_row_format(line, "|"))
                {
                    TogglePlayerSpectating(playerid, 0);
                    rBit1_Set(IsPlayerLogged, playerid, 1);
                    sscanf(line, "e<p<|>ddddddddd>", PlayerInfo[playerid]);
                    mysql_free_result();
                }
            }
        }
        case 3:
        {
            new escpname[24];
            if(IsNumeric(inputtext))
            {
                PlayerInfo[playerid][pCode] = strval(inputtext);
                mysql_real_escape_string(GetName(playerid), escpname);
                format(Query, sizeof(Query), "UPDATE `racuni` SET `code` = '%d' WHERE `Korisnik` = '%s'", PlayerInfo[playerid][pCode], escpname);
                mysql_query(Query);
            }
            else
            {
                format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
                format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} je registrirano!\nPrijavite se!\n\nUpiљite vaљ aktivacijski kod!\nKod mora biti samo brojevi!", GetName(playerid));
                ShowPlayerDialog(playerid, 3, DIALOG_STYLE_INPUT, title, text2, "Ok", "");
            }
        }
        case 4:
        {
            new escpname[24];
            mysql_real_escape_string(GetName(playerid), escpname);
            format(Query, sizeof(Query), "SELECT * FROM `racuni` WHERE `Korisnik` = '%s' AND `Code` = '%d' LIMIT 1", escpname, inputtext);
            mysql_query(Query);
            mysql_store_result();
            if(mysql_num_rows() == 1 && IsNumeric(inputtext))
            {
                new line[750];
                if(mysql_fetch_row_format(line, "|"))
                {
                    rBit1_Set(IsPlayerLogged, playerid, 1);
                    sscanf(line, "e<p<|>ddddddddd>", PlayerInfo[playerid]);
                    mysql_free_result();
                }
            }
            else
            {
                SetPVarInt(playerid, "WrongCode", GetPVarInt(playerid, "WrongCode") + 1);
                format(title, sizeof(title), "{00CCFF}     Dobrodoљao{FFFFFF} %s!", GetName(playerid));
                format(text2, sizeof(text2), "{FFFFFF}______________________________\n\n{00CCFF}Ime{FFFFFF} %s{00CCFF} je registrirano!\nPrijavite se!\n\n{F81414}Upisali ste pogreљan aktivacijski kod!", GetName(playerid));
                ShowPlayerDialog(playerid, 4, DIALOG_STYLE_INPUT , title, text2, "Ok", "");
                if(GetPVarInt(playerid, "WrongCode") == 3)
                {
                    Kick(playerid);
                }
            }
        }
Reply
#2

Show us the IsPlayerlogged whatsoever function. Also, the strings (query string, etc.) might be too small. Also what are the MYSQL debug messages?
Reply
#3

pawn Код:
new rBit1: IsPlayerLogged <MAX_PLAYERS>;
query size is 300, I also tried in OnDialogResponse put return 0; but the same...
debug:
pawn Код:
[16:27:57] >> mysql_connect( )

[16:27:57] CMySQLHandler::CMySQLHandler() - constructor called.

[16:27:57] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "sa:mp" | Username: "root" ...

[16:27:57] CMySQLHandler::Connect() - Connection was successful.

[16:27:57] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[16:27:57] >> mysql_query( Connection handle: 1 )

[16:27:57] CMySQLHandler::Query(SELECT * FROM `house` WHERE `HouseID` = '0' LIMIT 1) - Successfully executed.

[16:27:57] >> mysql_store_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::StoreResult() - Result was stored.

[16:27:57] >> mysql_num_rows( Connection handle: 1 )

[16:27:57] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:27:57] >> mysql_fetch_row_format( Connection handle: 1 )

[16:27:57] CMySQLHandler::FetchRow() - Return: None|-2521.331542|-623.472229|132.771697|1527.22998|-11.574499|1002.097106|3|1000|0|0

[16:27:57] >> mysql_free_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:27:57] >> mysql_free_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::FreeResult() - The result is already empty.

[16:27:57] >> mysql_query( Connection handle: 1 )

[16:27:57] CMySQLHandler::Query(SELECT * FROM `house` WHERE `HouseID` = '
2' LIMIT 1) - Successfully executed.

[16:27:57] >> mysql_store_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::StoreResult() - Result was stored.

[16:27:57] >> mysql_num_rows( Connection handle: 1 )

[16:27:57] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:27:57] >> mysql_fetch_row_format( Connection handle: 1 )

[16:27:57] CMySQLHandler::FetchRow() - Return: None|-2504.253662|-624.849975|132.722702|2350.339843|-1181.649902|1027.976562|5|15000|2|2

[16:27:57] >> mysql_free_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::FreeResult() - Result was successfully free'
d.

[16:27:57] >> mysql_free_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::FreeResult() - The result is already empty.

[16:27:57] >> mysql_query( Connection handle: 1 )

[16:27:57] CMySQLHandler::Query(SELECT * FROM `house` WHERE `HouseID` = '1' LIMIT 1) - Successfully executed.

[16:27:57] >> mysql_store_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::StoreResult() - Result was stored.

[16:27:57] >> mysql_num_rows( Connection handle: 1 )

[16:27:57] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:27:57] >> mysql_fetch_row_format( Connection handle: 1 )

[16:27:57] CMySQLHandler::FetchRow() - Return: None|-2514.513916|-631.377807|134.059402|2324.419921|-1145.568359|1050.710083|12|5000|1|1

[16:27:57] >> mysql_free_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:27:57] >> mysql_free_result( Connection handle: 1 )

[16:27:57] CMySQLHandler::FreeResult() - The result is already empty.

[16:28:09] >> mysql_real_escape_string( Connection handle: 1 )

[16:28:09] CMySQLHandler::EscapeString(Tony_Stark); - Escaped 10 characters to Tony_Stark.

[16:28:09] >> mysql_query_callback( Connection handle: 1 )

[16:28:09] CMySQLHandler::Query("sOnQueryFinish") - Custom callback query with index 102 started (ExtraID: 0)

[16:28:09] >> mysql_real_escape_string( Connection handle: 1 )

[16:28:09] CMySQLHandler::EscapeString(Tony_Stark); - Escaped 10 characters to Tony_Stark.

[16:28:09] >> mysql_query( Connection handle: 1 )

[16:28:09] CMySQLHandler::Query(SELECT * FROM `racuni` WHERE `Korisnik` = '
Tony_Stark' LIMIT 1) - Successfully executed.

[16:28:09] >> mysql_store_result( Connection handle: 1 )

[16:28:09] CMySQLHandler::StoreResult() - Result was stored.

[16:28:09] >> mysql_num_rows( Connection handle: 1 )

[16:28:09] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:28:09] >> mysql_free_result( Connection handle: 1 )

[16:28:09] CMySQLHandler::FreeResult() - Result was successfully free'
d.

[16:28:09] CMySQLHandler::ProcessQueryThread(SELECT * FROM `bans` WHERE Banned = 'Tony_Stark') - Data is getting passed to sOnQueryFinish() - (Threadsafe: Yes)

[16:28:09] sOnQueryFinish(102,"SELECT * FROM `bans` WHERE Banned = 'Tony_Stark'") - Called.

[16:28:09] >> mysql_store_result( Connection handle: 1 )

[16:28:09] CMySQLHandler::StoreResult() - Result was stored.

[16:28:09] >> mysql_num_rows( Connection handle: 1 )

[16:28:09] CMySQLHandler::NumRows() - Returned 0 row(s)

[16:28:09] >> mysql_free_result( Connection handle: 1 )

[16:28:09] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:28:11] >> mysql_real_escape_string( Connection handle: 1 )

[16:28:11] CMySQLHandler::EscapeString(Tony_Stark); - Escaped 10 characters to Tony_Stark.

[16:28:11] >> mysql_query( Connection handle: 1 )

[16:28:11] CMySQLHandler::Query(SELECT * FROM `racuni` WHERE `Korisnik` = '
Tony_Stark' AND `Lozinka` = 'pass' LIMIT 1) - Successfully executed.

[16:28:11] >> mysql_store_result( Connection handle: 1 )

[16:28:11] CMySQLHandler::StoreResult() - Result was stored.

[16:28:11] >> mysql_num_rows( Connection handle: 1 )

[16:28:11] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:28:11] >> mysql_fetch_row_format( Connection handle: 1 )

[16:28:11] CMySQLHandler::FetchRow() - Return: Tony_Stark|pass|0|0|0|0|0|0|0|0|0|192.168.1.233

[16:28:11] >> mysql_free_result( Connection handle: 1 )

[16:28:11] CMySQLHandler::FreeResult() - Result was successfully free'
d.

[16:28:46] >> mysql_real_escape_string( Connection handle: 1 )

[16:28:46] CMySQLHandler::EscapeString(Tony_Stark); - Escaped 10 characters to Tony_Stark.

[16:28:46] >> mysql_query( Connection handle: 1 )

[16:28:46] CMySQLHandler::Query(UPDATE `racuni` SET `Bodovi` = 0, `Novac` = 0, `Ubojstva` = 0, `Smrti` = 0, `Code` = 0, `Warns` = 0, `Online` = 0, `VIP` = 0, `Admin` = 0 WHERE `Korisnik` = 'Tony_Stark') - Successfully executed.

[16:28:46] >> mysql_free_result( Connection handle: 1 )

[16:28:46] CMySQLHandler::FreeResult() - The result is already empty.
Wanna my cmds for adding admins, money etc.?
Also I don't understand this
pawn Код:
[16:28:46] CMySQLHandler::Query(UPDATE `racuni` SET `Bodovi` = 0, `Novac` = 0, `Ubojstva` = 0, `Smrti` = 0, `Code` = 0, `Warns` = 0, `Online` = 0, `VIP` = 0, `Admin` = 0 WHERE `Korisnik` = 'Tony_Stark') - Successfully executed.
why is everything 0 ?
Reply
#4

System64 its the same here, I tried Kush, Seven Of Nine and etc registeration tutorials and finshed versions of it, but stats does not saves, though it creates the ini file only.
Reply
#5

Is this only happening with GMX's? Also, generally if you close your server and re-open it, the players don't 'disconnect' so it won't save.
Reply
#6

If it's only at the GMX you need to create a custom GMX command. Call a function at the GMX command that's saving everything for the player(s).
Reply
#7

Also, System64 don't use 'mysql_free_result' unless you've stored the result.

Here I made the command for you:

pawn Код:
COMMAND:gmx(playerid, params[])
{
    new time;
    if(!IsPlayerAdmin(playerid))return 0;
    foreach(Player,i)
    {
        if(rBit1_Get(IsPlayerLogged, i))
        {
            new escpname[24];
            mysql_real_escape_string(GetName(i), escpname);
            format(Query, sizeof(Query), "UPDATE `racuni` SET `Bodovi` = %d, `Novac` = %d, `Ubojstva` = %d, `Smrti` = %d, `Code` = %d, `Warns` = %d, `Online` = %d, `VIP` = %d, `Admin` = %d WHERE `Korisnik` = '%s'",GetPlayerScore(i), GetPlayerCash(i), PlayerInfo[i][pKills], PlayerInfo[i][pDeaths], PlayerInfo[i][pCode], PlayerInfo[i][pWarns], PlayerInfo[i][pOnline], PlayerInfo[i][pVIP], PlayerInfo[i][pAdmin], escpname);
            mysql_query(Query);
        }
    }
    SendRconCommand("gmx");
    return 1;
}
Reply
#8

TK - Yes, when I restar my console (samp-server.exe) or do a /gmx my stats doesn't save!
Tee - Thanks but doesn't work!

I have my custom /gmx command, I tried with calling OnPlayerDisconnect in /gmx but it's the same....
Also I think that this is problem
pawn Код:
else
            {
                new line[750];
                if(mysql_fetch_row_format(line, "|"))
                {
                    TogglePlayerSpectating(playerid, 0);
                    rBit1_Set(IsPlayerLogged, playerid, 1);
                    sscanf(line, "e<p<|>ddddddddd>", PlayerInfo[playerid]);
                    mysql_free_result();
                }
            }
Reply
#9

Is the IsPlayerLogged bit being set to one?
Reply
#10

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
Is the IsPlayerLogged bit being set to one?
Ofcourse, look at the code!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)