SQL loading.
#1

pawn Код:
stock LoadHouses()
{
    new
        Str[128],
        string[512],
        hID,
        hName[128],
        hOwner[24],
        Float:ExtX,
        Float:ExtY,
        Float:ExtZ,
        Float:IntX,
        Float:IntY,
        Float:IntZ,
        Price,
        IntID;
       
    mysql_query("SELECT * FROM `Houses`");
    mysql_store_result();
    new i = 1;
   
    if(mysql_num_rows() > 0) {
        while(mysql_fetch_row(Str)) {
            sscanf(Str, "p<|>is[128]s[24]ffffffii", hID, hName, hOwner, ExtX, ExtY, ExtZ, IntX, IntY, IntZ, IntID, Price);
            HousePickup[hID] = CreatePickup(1273, 1, ExtX, ExtY, ExtZ, 0);
            format(Houses[i][HouseName], 128, hName);
            format(Houses[i][HouseOwner], 24, hOwner);
            Houses[i][HouseExteriorX] = float(ExtX);
            Houses[i][HouseExteriorY] = float(ExtY);
            Houses[i][HouseExteriorZ] = float(ExtZ);
            Houses[i][HouseInteriorX] = float(IntX);
            Houses[i][HouseInteriorY] = float(IntY);
            Houses[i][HouseInteriorZ] = float(IntZ);
            Houses[i][HouseInteriorID] = strval(IntID);
            Houses[i][HousePrice] = strval(Price);
            i++;
            format(string, sizeof(string), "{73FFFF}House {FFFFFF}%d{73FFFF}\nPrice: {FFFFFF}$%d{73FFFF}\nName: {FFFFFF}%s{73FFFF}\nOwner: {FFFFFF}%s", hID, Price, hName, hOwner);
            Create3DTextLabel(string, BLUE, ExtX, ExtY, ExtZ, 5.0, 0, 1);
            hTotal++;
        }
    }
    mysql_free_result();
    printf("%i houses loaded from the MySQL Database.", hTotal);
    return 1;
}
This code gives me

Код:
(4966) : warning 213: tag mismatch
(4967) : warning 213: tag mismatch
(4968) : warning 213: tag mismatch
(4969) : warning 213: tag mismatch
(4970) : warning 213: tag mismatch
(4971) : warning 213: tag mismatch
(4972) : error 035: argument type mismatch (argument 1)
(4973) : error 035: argument type mismatch (argument 1)
Line 4966 - 4973 is:

pawn Код:
Houses[i][HouseExteriorX] = float(ExtX);
Houses[i][HouseExteriorY] = float(ExtY);
Houses[i][HouseExteriorZ] = float(ExtZ);
Houses[i][HouseInteriorX] = float(IntX);
Houses[i][HouseInteriorY] = float(IntY);
Houses[i][HouseInteriorZ] = float(IntZ);
Houses[i][HouseInteriorID] = strval(IntID);
Houses[i][HousePrice] = strval(Price);
Thanks!
Reply
#2

The HouseInteriorX, ect have to be a float in the array.
Reply
#3

This is the enum:

pawn Код:
enum HouseData
{
    HouseName[128],
    HouseOwner[24],
    HouseID,
    Float:HouseExteriorX,
    Float:HouseExteriorY,
    Float:HouseExteriorZ,
    Float:HouseInteriorX,
    Float:HouseInteriorY,
    Float:HouseInteriorZ,
    HouseInteriorID,
    HousePrice
};
This is the new;

pawn Код:
new Houses[MAX_HOUSES][HouseData];
Reply
#4

Код:
Houses[i][HouseExteriorX] = ExtX;
            Houses[i][HouseExteriorY] = ExtY;
            Houses[i][HouseExteriorZ] = ExtZ;
            Houses[i][HouseInteriorX] = IntX;
            Houses[i][HouseInteriorY] = IntY;
            Houses[i][HouseInteriorZ] = IntZ;
            Houses[i][HouseInteriorID] = IntID;
            Houses[i][HousePrice] = Price;
Reply
#5

Try:
pawn Код:
stock LoadHouses()
{
    new
        Str[128],
        string[512],
        hID,
        hName[128],
        hOwner[24],
        Float:ExtX,
        Float:ExtY,
        Float:ExtZ,
        Float:IntX,
        Float:IntY,
        Float:IntZ,
        Price,
        IntID;

    mysql_query("SELECT * FROM `Houses`");
    mysql_store_result();
    new i = 1;

    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>is[128]s[24]ffffffii", hID, hName, hOwner, ExtX, ExtY, ExtZ, IntX, IntY, IntZ, IntID, Price);
            HousePickup[hID] = CreatePickup(1273, 1, ExtX, ExtY, ExtZ, 0);
            format(Houses[i][HouseName], 128, hName);
            format(Houses[i][HouseOwner], 24, hOwner);
            Houses[i][HouseExteriorX] = floatstr(ExtX);
            Houses[i][HouseExteriorY] = floatstr(ExtY);
            Houses[i][HouseExteriorZ] = floatstr(ExtZ);
            Houses[i][HouseInteriorX] = floatstr(IntX);
            Houses[i][HouseInteriorY] = floatstr(IntY);
            Houses[i][HouseInteriorZ] = floatstr(IntZ);
            Houses[i][HouseInteriorID] = IntID;
            Houses[i][HousePrice] = Price;
            i++;
            format(string, sizeof(string), "{73FFFF}House {FFFFFF}%d{73FFFF}\nPrice: {FFFFFF}$%d{73FFFF}\nName: {FFFFFF}%s{73FFFF}\nOwner: {FFFFFF}%s", hID, Price, hName, hOwner);
            Create3DTextLabel(string, BLUE, ExtX, ExtY, ExtZ, 5.0, 0, 1);
            hTotal++;
        }
    }
    mysql_free_result();
    printf("%i houses loaded from the MySQL Database.", hTotal);
    return 1;
}
Reply
#6

Better
Код:
    if(mysql_num_rows() > 0) {
        while(mysql_fetch_row(Str)) {
            sscanf(Str, "p<|>ie<s[128]s[24]iffffffii>", hID, Houses[i]);
            HousePickup[hID] = CreatePickup(1273, 1, Houses[i][HouseExteriorX], Houses[i][HouseExteriorY], Houses[i][HouseExteriorZ], 0);
            format(string, sizeof(string), "{73FFFF}House {FFFFFF}%d{73FFFF}\nPrice: {FFFFFF}$%d{73FFFF}\nName: {FFFFFF}%s{73FFFF}\nOwner: {FFFFFF}%s", hID, Houses[i][HousePrice],  Houses[i][HouseName], Houses[i][HouseOwner]);
            Create3DTextLabel(string, BLUE, Houses[i][HouseExteriorX], Houses[i][HouseExteriorY], Houses[i][HouseExteriorZ], 5.0, 0, 1);
            i++;
        }
    }
and
Код:
printf("%i houses loaded from the MySQL Database.", i-1);
Reply
#7

Thanks, mate!

(Sorry for the slow reply)

Repped you both for being nice.
Reply
#8

Why are you initializing all of those variables? sscanf the results into your enums, geez.
Reply
#9

I do it that way because that's the way that I know how to do it.
Reply
#10

Quote:
Originally Posted by iGetty
Посмотреть сообщение
I do it that way because that's the way that I know how to do it.
Instead of creating new variables, you can always just use the actual enum variables. It's a tad quicker, and doesn't use up as many lines/miliseconds of processing time...!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)