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


Messages In This Thread
Problem with my character system [MySQL] - by Kindred - 23.06.2013, 02:56
Re: Problem with my character system [MySQL] - by Kindred - 24.06.2013, 03:27
Re: Problem with my character system [MySQL] - by Scenario - 24.06.2013, 03:35
Re: Problem with my character system [MySQL] - by Kindred - 24.06.2013, 04:30
Re: Problem with my character system [MySQL] - by Scenario - 24.06.2013, 04:36
Re: Problem with my character system [MySQL] - by Kindred - 24.06.2013, 04:45
Re: Problem with my character system [MySQL] - by Scenario - 24.06.2013, 04:57

Forum Jump:


Users browsing this thread: 1 Guest(s)