How would I convert this?
#1

To MySQL


pawn Код:
forward LoadCharacter(playerid, charactername[]); // Load character.
public LoadCharacter(playerid, charactername[])
{
    new DBResult:qresult, count = 0, value[128];
    if(IsPlayerConnected(playerid))
    {
        if(MasterAccount[playerid][mLoggedIn])
        {
            count = PlayerCharacterCount(playerid);
            if(count >= 1 && count <= MAX_CHARACTER_SLOTS)
            {
                if(CharacterExists(charactername))
                {
                    MasterAccount[playerid][mCurrentCID] = CharacterID(charactername);
                    if(MasterAccount[playerid][mCurrentCID] != -1)
                    {
                        format(query, sizeof(query), "SELECT * FROM `Character` WHERE ( `id` = '%d' )", MasterAccount[playerid][mCurrentCID]);
                        qresult = db_query(database, query);
                        Character[playerid][cID] = MasterAccount[playerid][mCurrentCID];
                        db_get_field_assoc(qresult, "admin_level", value, 11);  Character[playerid][cAdminLevel] = strval(value);
                        db_get_field_assoc(qresult, "x", value, 11);    Character[playerid][cX] = floatstr(value);
                        db_get_field_assoc(qresult, "y", value, 11);    Character[playerid][cY] = floatstr(value);
                        db_get_field_assoc(qresult, "z", value, 11);    Character[playerid][cZ] = floatstr(value);
                        db_get_field_assoc(qresult, "angle", value, 11);    Character[playerid][cAngle] = floatstr(value);
                        db_get_field_assoc(qresult, "world", value, 11);    Character[playerid][cWorld] = strval(value);
                        db_get_field_assoc(qresult, "interior", value, 11); Character[playerid][cInterior] = strval(value);
                        db_get_field_assoc(qresult, "cash", value, 11); Character[playerid][cCash] = strval(value);
                        db_get_field_assoc(qresult, "sex", value, 11);  Character[playerid][cSex] = strval(value);
                        db_get_field_assoc(qresult, "age", value, 11);  Character[playerid][cAge] = strval(value);
                        db_get_field_assoc(qresult, "bank", value, 11); Character[playerid][cBank] = strval(value);
                        db_get_field_assoc(qresult, "skin", value, 11); Character[playerid][cSkin] = strval(value);
                        db_get_field_assoc(qresult, "religion", value, 11); Character[playerid][cReligion] = strval(value);
                        db_get_field_assoc(qresult, "owner_id", value, 11); Character[playerid][cOwnerID] = strval(value);
                        format(Character[playerid][cName], MAX_PLAYER_NAME, charactername);
                        /*printf("%d, %f, %f, %f, %f, %d, %d, %d, %d, %d, %d, %d, %d, %d, %s - CID: %d.",
                        Character[playerid][cAdminLevel],
                        Character[playerid][cX],
                        Character[playerid][cY],
                        Character[playerid][cZ],
                        Character[playerid][cAngle],
                        Character[playerid][cWorld],
                        Character[playerid][cInterior],
                        Character[playerid][cCash],
                        Character[playerid][cSex],
                        Character[playerid][cAge],
                        Character[playerid][cBank],
                        Character[playerid][cSkin],
                        Character[playerid][cReligion],
                        Character[playerid][cOwnerID],
                        Character[playerid][cName],
                        Character[playerid][cID]);*/

                        db_free_result(qresult);
                        SetSpawnInfo( playerid, 0, Character[playerid][cSkin], Character[playerid][cX], Character[playerid][cY], Character[playerid][cZ], Character[playerid][cAngle], 0, 0, 0, 0, 0, 0 );
                        SpawnPlayer(playerid);
                        SetPlayerVirtualWorld(playerid, Character[playerid][cWorld]);
                        SetPlayerInterior(playerid, Character[playerid][cInterior]);
                        SetPlayerCash(playerid, Character[playerid][cCash]);
                        new string[128];
                        format(string, sizeof(string), "[I:] You have successfully spawned as %s - (/mainmenu to return to character selection).", RemovePlayerUnderscoreString(charactername));
                        SendClientMessage(playerid, COLOR_YELLOW, string);
                        SetPlayerColor(playerid, COLOR_WHITE);// White = character spawned.
                        //Updating playername to player as we don't use the original playername system.
                        new namestring[128];
                        format(namestring,sizeof(namestring),"((%s | %d))\n%s", PlayerName(playerid), playerid, RemovePlayerUnderscoreString(Character[playerid][cName]));
                        Character[playerid][cNameLabel] = Create3DTextLabel(namestring,COLOR_WHITE,30.0,40.0,50.0,15.0,0);
                        Attach3DTextLabelToPlayer(Character[playerid][cNameLabel], playerid, 0.0, 0.0, 0.3);
                        GivePlayerWeapon(playerid, 24, 999);
                        SetTimerEx("PlayerNameTagTimer", 1000, true, "i", playerid);
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_RED, "ERROR");
                        Kick(playerid);
                    }
                }
            }
        }
    }
    return count;
}

Mainly this bit:
pawn Код:
format(query, sizeof(query), "SELECT * FROM `Character` WHERE ( `id` = '%d' )", MasterAccount[playerid][mCurrentCID]);
                        qresult = db_query(database, query);
                        Character[playerid][cID] = MasterAccount[playerid][mCurrentCID];
                        db_get_field_assoc(qresult, "admin_level", value, 11);  Character[playerid][cAdminLevel] = strval(value);
                        db_get_field_assoc(qresult, "x", value, 11);    Character[playerid][cX] = floatstr(value);
                        db_get_field_assoc(qresult, "y", value, 11);    Character[playerid][cY] = floatstr(value);
                        db_get_field_assoc(qresult, "z", value, 11);    Character[playerid][cZ] = floatstr(value);
                        db_get_field_assoc(qresult, "angle", value, 11);    Character[playerid][cAngle] = floatstr(value);
                        db_get_field_assoc(qresult, "world", value, 11);    Character[playerid][cWorld] = strval(value);
                        db_get_field_assoc(qresult, "interior", value, 11); Character[playerid][cInterior] = strval(value);
                        db_get_field_assoc(qresult, "cash", value, 11); Character[playerid][cCash] = strval(value);
                        db_get_field_assoc(qresult, "sex", value, 11);  Character[playerid][cSex] = strval(value);
                        db_get_field_assoc(qresult, "age", value, 11);  Character[playerid][cAge] = strval(value);
                        db_get_field_assoc(qresult, "bank", value, 11); Character[playerid][cBank] = strval(value);
                        db_get_field_assoc(qresult, "skin", value, 11); Character[playerid][cSkin] = strval(value);
                        db_get_field_assoc(qresult, "religion", value, 11); Character[playerid][cReligion] = strval(value);
                        db_get_field_assoc(qresult, "owner_id", value, 11); Character[playerid][cOwnerID] = strval(value);
                        format(Character[playerid][cName], MAX_PLAYER_NAME, charactername);
Reply
#2

Try This : https://sampforum.blast.hk/showthread.php?tid=245893
Reply
#3

It's SQLite.
Reply
#4

What do I use instead of db_get_field_assoc?
Reply
#5

Help please
Reply
#6

BUMP
Reply


Forum Jump:


Users browsing this thread: