Problem with my character system [MySQL]
#1

First off, please don't post unless you can actually help.

Alright, I made an account registration system. When the player joins, they login / register their account with a password. When that's finished, they are prompted to create a character. Now, if the characters variable is set to "None" it will show "New Character", otherwise it will show the characters name.

Now, for some reason, it allows me to perfectly insert the character into the characters table, and the "Character(1, 2, or 3)" in the account table to the name. Yet, for some reason, when the dialog shows back up (The dialog re-shows, showing the list of characters AFTER you type in the characters name (and it's an RP name and it's between a certain range of characters)) it still shows New Player. I don't know why, and in my opinion it should work.

I looked over it a few times the past few days, and I can't find the problem. It's probably a small error like usual, but for some reason I can't find it. Here are the relevant codes needed. If anything else is needed, please tell me.

The codes are listed in the order they are used (For example, OnPlayerConnect, login dialog, not login dialog then OnPlayerConnect stocks)

pawn Код:
// Global Variable
new PlayerCharacters[MAX_PLAYERS][3][128];

//Creating the character dialog and selecting the character dialog
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    new
        szMessage[128];
       
    switch(dialogid)
    {
        //Several other dialogs, then this one
        case DIALOG_SELECT_CHARACTER:
        {
            CharacterEditing[playerid] = listitem;
            if(!IsCharacterCreated(playerid, listitem)) return ShowDialog(playerid, 3);
            else LoginCharacter(playerid, listitem);
        }
        case DIALOG_CREATE_CHARACTER:
        {
            if(!response) return ShowDialog(playerid, 2);
            if(strlen(inputtext) > 24 || strlen(inputtext) <= 4)
            {
                SendClientMessage(playerid, COLOR_RED, "SERVER: Character name must be 5 - 24 characters long!");
                ShowDialog(playerid, 3);
                return 1;
            }
            else if(CharacterExist(playerid, inputtext))
            {
                SendClientMessage(playerid, COLOR_RED, "SERVER: That character name already exists!  Please type a different name!");
                ShowDialog(playerid, 3);
                return 1;
            }
            else if(!IsRPName(inputtext))
            {
                SendClientMessage(playerid, COLOR_RED, "SERVER: That isn't an RP name!  (Format: Firstname_Lastname)");
                ShowDialog(playerid, 3);
                return 1;
            }
            RegisterCharacter(playerid, inputtext, CharacterEditing[playerid]);
        }
    }
    return 1;
}

//Listing the characters and making the dialog.  Under custom "ShowDialog" stock.
stock ShowDialog(playerid, dialogid)
{
    new string[200];
    switch(dialogid)
    {
        //Other dialogid's
        case 2:
        {
            ShowPlayerDialog(playerid, DIALOG_SELECT_CHARACTER, DIALOG_STYLE_LIST, "Character - Selection", ListCharacters(playerid), "Select", "Cancel");
        {
    }
    return 1;
}


//Stocks
stock RegisterCharacter(playerid, charactername[], characterslot)
{
    new szQuery[300];
    format(PlayerCharacters[playerid][characterslot], 24, "%s", charactername);
    format(szQuery, sizeof(szQuery), "INSERT INTO characters (Account, Name, Skin, Health, Armour, PosX, PosY, PosZ, Money, Interior, VirtualWorld) VALUES ('%s', '%s', 299, 100, 0, 0, 0, 0, 1000, 0, 0)", PlayerInfo[playerid][pUsername], charactername);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
    format(szQuery, sizeof(szQuery), "UPDATE accounts SET Character%i = '%s' WHERE Username = '%s'", characterslot + 1, charactername, PlayerInfo[playerid][pUsername]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
    SendClientMessage(playerid, COLOR_WHITE, "You have registered a character!");
    ShowDialog(playerid, 2);
    return 1;
}

stock ListCharacters(playerid)
{
    new characters[3][24], string[128];
    LoadCharacterNames(playerid);
    for(new i = 0; i < 3; i++)
    {
        if(!strcmp(PlayerCharacters[playerid][i], "None", true, 24))
        {
            format(characters[i], 24, "New Character");
        }
        else { format(characters[i], 24, "%s", PlayerCharacters[playerid][i]); }
    }
    format(string, sizeof(string), "%s\n%s\n%s", characters[0], characters[1], characters[2]);
    return string;
}

stock LoadCharacterNames(playerid)
{
    new string[128];
    format(string, sizeof(string), "SELECT * FROM accounts WHERE Username = '%s'", PlayerInfo[playerid][pUsername]);
    mysql_query(string, THREAD_NO_RESULT, playerid, iConnectionHandle);

    mysql_fetch_field_row(string, "Character1", iConnectionHandle);
    format(PlayerCharacters[playerid][0], 24, "%s", string);
    mysql_fetch_field_row(string, "Character2", iConnectionHandle);
    format(PlayerCharacters[playerid][1], 24, "%s", string);
    mysql_fetch_field_row(string, "Character3", iConnectionHandle);
    format(PlayerCharacters[playerid][2], 24, "%s", string);
    return 1;
}

stock IsCharacterCreated(playerid, characterid)
{
    if(!strcmp(PlayerCharacters[playerid][characterid], "None", true, 128)) return false;
    else return true;
}

stock LoginCharacter(playerid, characterslot)
{
    new szQuery[128], szValue[64];
    format(szQuery, sizeof(szQuery), "SELECT * FROM characters WHERE Name = '%s'", PlayerCharacters[playerid][characterslot]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
    mysql_store_result(iConnectionHandle);
    mysql_retrieve_row();


    mysql_fetch_field_row(szValue, "PosX", iConnectionHandle);
    CharacterInfo[playerid][cPos][0] = floatstr(szValue);
    mysql_fetch_field_row(szValue, "PosY", iConnectionHandle);
    CharacterInfo[playerid][cPos][1] = floatstr(szValue);
    mysql_fetch_field_row(szValue, "PosZ", iConnectionHandle);
    CharacterInfo[playerid][cPos][2] = floatstr(szValue);
    mysql_fetch_field_row(szValue, "PosR", iConnectionHandle);
    CharacterInfo[playerid][cPos][3] = floatstr(szValue);
    mysql_fetch_field_row(szValue, "Health", iConnectionHandle);
    CharacterInfo[playerid][cHealth] = floatstr(szValue);
    mysql_fetch_field_row(szValue, "Armour", iConnectionHandle);
    CharacterInfo[playerid][cArmour] = floatstr(szValue);
    mysql_fetch_field_row(szValue, "Interior", iConnectionHandle);
    CharacterInfo[playerid][cInterior] = strval(szValue);
    mysql_fetch_field_row(szValue, "VirtualWorld", iConnectionHandle);
    CharacterInfo[playerid][cVW] = strval(szValue);
    mysql_fetch_field_row(szValue, "Skin", iConnectionHandle);
    CharacterInfo[playerid][cSkin] = strval(szValue);

    PlayerInfo[playerid][pStatus] = 1;

    if(PlayerInfo[playerid][pJail] == 1)
    {
        //SetSpawnInfo(playerid, 0, CharacterInfo[playerid][cSkin], posx, posy, posz, 0, 0, 0, 0, 0, 0, 0);
        SendClientMessageEx(playerid, COLOR_WHITE, "You've logged on with a jailed account!");
    }
    else SetSpawnInfo(playerid, 0, CharacterInfo[playerid][cSkin], CharacterInfo[playerid][cPos][0], CharacterInfo[playerid][cPos][1], CharacterInfo[playerid][cPos][2], CharacterInfo[playerid][cPos][3], 0, 0, 0, 0, 0, 0);
    SpawnPlayer(playerid);
    return 1;
}
I appreciate any help I can get.
Reply
#2

Still need help, it will still not show the correct name and will not allow me to log in.

I've again looked through anything and it looks like NOTHING what-so-ever changes in the variable, so it should be showing the players name instead of "New Character".
Reply
#3

pawn Код:
mysql_query(string, THREAD_NO_RESULT, playerid, iConnectionHandle);
You're trying to select rows from the table, but then you say there's going to be no result so you don't pass it to the OnQueryLoad (or w/e it is) callback and you're still trying to load the data in the same function.

That's not how R6 works, is it?
Reply
#4

I assume you are talking about under LoadCharacterNames?

Because regardless of whether or not I change the thread, it does not work. I made a thread for it and put the "getting rows" inside the thread, so it should work if that's not how it was suppose to work anyways.

Still doesn't work.
Reply
#5

You might want to try using mysql_num_rows() to see how many rows are being returned. Then load the data using mysql_fetch_field_row() and using a printf() statement to see if the query is returning anything.
Reply
#6

My printf's aren't even showing now. This is my new LoadCharacterNames:

pawn Код:
stock LoadCharacterNames(playerid)
{
    new string[128];
    format(string, sizeof(string), "SELECT * FROM accounts WHERE Username = '%s'", pInfo[playerid][Username]);
    mysql_query(string, THREAD_LOAD_CNAMES, playerid, iConnectionHandle);
    return 1;
}
And the thread under OnQueryFinish:

pawn Код:
public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
    new
        szMessage[128],
        szQuery[256];

    #pragma unused szQuery

    switch(resultid)
    {
//Other threads, blablabla
        case THREAD_LOAD_CNAMES:
        {
            printf("%i", mysql_num_rows(connectionHandle));
            mysql_store_result(connectionHandle);
            mysql_retrieve_row();
           
            mysql_fetch_field_row(PlayerCharacters[extraid][0], "Character1", connectionHandle);
            mysql_fetch_field_row(PlayerCharacters[extraid][1], "Character2", connectionHandle);
            mysql_fetch_field_row(PlayerCharacters[extraid][2], "Character3", connectionHandle);
           
            printf(PlayerCharacters[extraid][0]);
            printf(PlayerCharacters[extraid][1]);
            printf(PlayerCharacters[extraid][2]);
           
            mysql_free_result(connectionHandle);
        }
    }
    return 1;
}
The printf's aren't even working, so I don't even know what's wrong.
Reply
#7

If you have only just started with this mode, I would recommend updating to completely threaded queries. If you ask me, they make MUCH more sense. I'm kind of at a loss right now because I haven't touched non-threaded queries in years.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)